-
Notifications
You must be signed in to change notification settings - Fork 17
/
crc_example.c
82 lines (64 loc) · 2.21 KB
/
crc_example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "dml/dml.h"
#include "examples_utils.h"
#define BUFFER_SIZE 1024 // 1 KB
/*
* This example demonstrates how to create and run a crc operation.
*/
int main(int argc, char **argv)
{
dml_path_t execution_path = DML_PATH_SW;
// Get path from input argument
int parse_ret = parse_execution_path(argc, argv, &execution_path);
if (parse_ret != 0) {
return 1;
}
printf("Starting CRC job example.\n");
printf("Caclulating CRC for region of size 1KB.\n");
dml_job_t *dml_job_ptr = NULL;
uint32_t size = 0u;
uint8_t source [BUFFER_SIZE];
for(int i = 0; i < BUFFER_SIZE; i++){
source[i] = i % 256;
}
dml_status_t status = dml_get_job_size(execution_path, &size);
if (DML_STATUS_OK != status) {
printf("An error (%u) occured during getting job size.\n", status);
return 1;
}
dml_job_ptr = (dml_job_t *)malloc(size);
status = dml_init_job(execution_path, dml_job_ptr);
if (DML_STATUS_OK != status) {
printf("An error (%u) occured during job initialization.\n", status);
free(dml_job_ptr);
return 1;
}
uint32_t crc = 1;
dml_job_ptr->operation = DML_OP_CRC;
dml_job_ptr->source_first_ptr = source;
dml_job_ptr->source_length = BUFFER_SIZE;
dml_job_ptr->crc_checksum_ptr = &crc;
status = dml_execute_job(dml_job_ptr, DML_WAIT_MODE_BUSY_POLL);
if (DML_STATUS_OK != status) {
printf("An error (%u) occured during job execution.\n", status);
dml_finalize_job(dml_job_ptr);
free(dml_job_ptr);
return 1;
}
printf("Calculated CRC is: 0x%08x\n", crc);
status = dml_finalize_job(dml_job_ptr);
if (DML_STATUS_OK != status) {
printf("An error (%u) occured during job finalization.\n", status);
free(dml_job_ptr);
return 1;
}
free(dml_job_ptr);
printf("Finished successfully.\n");
return 0;
}