![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
CRC example to compute 32-bit CRC .
main.cpp@1:6f792125397a, 2017-12-29 (annotated)
- Committer:
- deepikabhavnani
- Date:
- Fri Dec 29 23:13:37 2017 +0000
- Revision:
- 1:6f792125397a
- Parent:
- 0:4ea3a9a52bb6
- Child:
- 2:a9d9b5c4a32b
SlowCRC is renamed to BitwiseCRC; CRC classes are not template class anymore
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
deepikabhavnani | 0:4ea3a9a52bb6 | 1 | #include "mbed.h" |
deepikabhavnani | 1:6f792125397a | 2 | #include "BitwiseCRC.h" |
deepikabhavnani | 0:4ea3a9a52bb6 | 3 | #include "FastCRC.h" |
deepikabhavnani | 0:4ea3a9a52bb6 | 4 | |
deepikabhavnani | 0:4ea3a9a52bb6 | 5 | #define FAST_COMPUTE 1 |
deepikabhavnani | 0:4ea3a9a52bb6 | 6 | |
deepikabhavnani | 0:4ea3a9a52bb6 | 7 | #if defined(FAST_COMPUTE) |
deepikabhavnani | 1:6f792125397a | 8 | #define CRC_ALGO FastCRC |
deepikabhavnani | 0:4ea3a9a52bb6 | 9 | #else |
deepikabhavnani | 1:6f792125397a | 10 | #define CRC_ALGO BitwiseCRC |
deepikabhavnani | 0:4ea3a9a52bb6 | 11 | #endif |
deepikabhavnani | 0:4ea3a9a52bb6 | 12 | |
deepikabhavnani | 0:4ea3a9a52bb6 | 13 | char test[] = "123456789"; |
deepikabhavnani | 0:4ea3a9a52bb6 | 14 | uint32_t crc; |
deepikabhavnani | 0:4ea3a9a52bb6 | 15 | |
deepikabhavnani | 1:6f792125397a | 16 | int crc_calculate(crc_polynomial_type_t crc_type) { |
deepikabhavnani | 1:6f792125397a | 17 | CRC_ALGO ct(crc_type); |
deepikabhavnani | 0:4ea3a9a52bb6 | 18 | |
deepikabhavnani | 0:4ea3a9a52bb6 | 19 | ct.init(); |
deepikabhavnani | 1:6f792125397a | 20 | ct.compute((void *)test, strlen((const char*)test), &crc); |
deepikabhavnani | 0:4ea3a9a52bb6 | 21 | |
deepikabhavnani | 1:6f792125397a | 22 | printf("The CRC of 0x%x data \"123456789\" is : 0x%lx\n", |
deepikabhavnani | 0:4ea3a9a52bb6 | 23 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:4ea3a9a52bb6 | 24 | ct.deinit(); |
deepikabhavnani | 0:4ea3a9a52bb6 | 25 | return 0; |
deepikabhavnani | 0:4ea3a9a52bb6 | 26 | } |
deepikabhavnani | 0:4ea3a9a52bb6 | 27 | |
deepikabhavnani | 0:4ea3a9a52bb6 | 28 | int main() { |
deepikabhavnani | 1:6f792125397a | 29 | |
deepikabhavnani | 1:6f792125397a | 30 | crc_calculate(CRC_32BIT); |
deepikabhavnani | 1:6f792125397a | 31 | crc_calculate(CRC_16BIT_IBM); |
deepikabhavnani | 1:6f792125397a | 32 | crc_calculate(CRC_16BIT_CCITT); |
deepikabhavnani | 1:6f792125397a | 33 | |
deepikabhavnani | 1:6f792125397a | 34 | printf("End\n"); |
deepikabhavnani | 0:4ea3a9a52bb6 | 35 | return 0; |
deepikabhavnani | 0:4ea3a9a52bb6 | 36 | } |