1 #include "../../firmware.h"
2 #include "../../test.h"
5 const uint8_t crc_test_1[] = {
6 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
12 const uint8_t crc_test_2[] = {
13 0x7F, 0x9C, 0x2B, 0xA4, 0xE8, 0x8F, 0x82, 0x7D,
14 0x61, 0x60, 0x45, 0x50, 0x76, 0x05, 0x85, 0x3E,
15 0x13, 0x1A, 0xB8, 0xD2, 0xB5, 0x94, 0x94, 0x6B,
16 0x9C, 0x81, 0x33, 0x3F, 0x9B, 0xB6, 0xE0, 0xCE,
17 0xF4, 0x3E, 0xA7, 0xA3, 0x36, 0x9D, 0x4B, 0xAA
19 const uint8_t crc_test_3[] = {
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'};
24 const uint8_t crc8_result_1 = 0x00;
26 const uint8_t crc8_result_2 = 0x18;
28 const uint8_t crc8_result_3 = 0xF4;
32 const uint16_t crc16_result_1 = 0x570D;
34 const uint16_t crc16_result_2 = 0x5264;
36 const uint16_t crc16_result_3 = 0x29B1;
40 const uint32_t crc32_result_1 = 0x1F877C1E;
42 const uint32_t crc32_result_2 = 0xF62AE45F;
44 const uint32_t crc32_result_3 = 0xCBF43926;
49 uint16_t crc16_result;
50 uint32_t crc32_result;
54 crc8_result =
Util_crc8(crc_test_1,
sizeof(crc_test_1));
55 if(crc8_result != crc8_result_1)
59 Debug_print(
"CRC-8 Test 1: Expected 0x%02x, Got 0x%02x\r\n"
67 crc8_result =
Util_crc8(crc_test_2,
sizeof(crc_test_2));
68 if(crc8_result != crc8_result_2)
72 Debug_print(
"CRC-8 Test 2: Expected 0x%02x, Got 0x%02x\r\n"
80 crc8_result =
Util_crc8(crc_test_3,
sizeof(crc_test_3));
81 if(crc8_result != crc8_result_3)
85 Debug_print(
"CRC-8 Test 3: Expected 0x%02x, Got 0x%02x\r\n"
95 crc16_result =
Util_crc16(crc_test_1,
sizeof(crc_test_1));
96 if(crc16_result != crc16_result_1)
100 Debug_print(
"CRC-16-CCITT-FALSE Test 1: Expected 0x%04x, Got 0x%04x\r\n"
108 crc16_result =
Util_crc16(crc_test_2,
sizeof(crc_test_2));
109 if(crc16_result != crc16_result_2)
113 Debug_print(
"CRC-16-CCITT-FALSE Test 2: Expected 0x%04x, Got 0x%04x\r\n"
121 crc16_result =
Util_crc16(crc_test_3,
sizeof(crc_test_3));
122 if(crc16_result != crc16_result_3)
126 Debug_print(
"CRC-16-CCITT-FALSE Test 3: Expected 0x%04x, Got 0x%04x\r\n"
136 crc32_result =
Util_crc32(crc_test_1,
sizeof(crc_test_1));
137 if(crc32_result != crc32_result_1)
141 Debug_print(
"CRC-32 Test 1: Expected 0x%08x, Got 0x%08x\r\n"
149 crc32_result =
Util_crc32(crc_test_2,
sizeof(crc_test_2));
150 if(crc32_result != crc32_result_2)
154 Debug_print(
"CRC-32 Test 2: Expected 0x%08x, Got 0x%08x\r\n"
162 crc32_result =
Util_crc32(crc_test_3,
sizeof(crc_test_3));
163 if(crc32_result != crc32_result_3)
167 Debug_print(
"CRC-32 Test 3: Expected 0x%08x, Got 0x%08x\r\n"
void Debug_print(char *fmt,...)
uint16_t Util_crc16(const uint8_t *buf, uint32_t size)
uint32_t Util_crc32(const uint8_t *buf, uint32_t size)
uint8_t Util_crc8(const uint8_t *buf, uint32_t size)