mbed_example
/
CRC_eample_sd
CRC example for SD driver
Diff: main.cpp
- Revision:
- 2:ee110889fa99
- Parent:
- 1:ca0b1e353dfe
- Child:
- 3:97e3e51ca5d5
--- a/main.cpp Tue Jan 02 15:47:19 2018 +0000 +++ b/main.cpp Fri Mar 23 15:47:30 2018 +0000 @@ -1,14 +1,11 @@ #include "mbed.h" -#include "BaseCRC.h" -#include "BitwiseCRC.h" -#include "FastCRC.h" -int crc_sd_7bit() { - BitwiseCRC ct(CRC_7BIT_SD); +int crc_sd_7bit() +{ + MbedCRC<POLY_7BIT_SD, 7> ct; char test[5]; uint32_t crc; - ct.init(); test[0] = 0x40; test[1] = 0x00; test[2] = 0x00; @@ -17,9 +14,9 @@ ct.compute((void *)test, 5, &crc); // CRC 7-bit as 8-bit data - crc = (crc << 1 ) + 1; + crc = (crc | 0x01) & 0xFF; printf("The CRC of 0x%x \"CMD0\" is \"0x95\" Result: 0x%x\n", - ct.get_polynomial(), crc); + ct.get_polynomial(), crc); test[0] = 0x48; test[1] = 0x00; @@ -29,9 +26,9 @@ ct.compute((void *)test, 5, &crc); // CRC 7-bit as 8-bit data - crc = (crc << 1 ) + 1; + crc = (crc | 0x01) & 0xFF; printf("The CRC of 0x%x \"CMD8\" is \"0x87\" Result: 0x%x\n", - ct.get_polynomial(), crc); + ct.get_polynomial(), crc); test[0] = 0x51; test[1] = 0x00; @@ -41,25 +38,23 @@ ct.compute((void *)test, 5, &crc); // CRC 7-bit as 8-bit data - crc = (crc << 1 ) + 1; + crc = (crc | 0x01) & 0xFF; printf("The CRC of 0x%x \"CMD17\" is \"0x55\" Result: 0x%x\n", - ct.get_polynomial(), crc); + ct.get_polynomial(), crc); - ct.deinit(); return 0; } -int crc_sd_16bit() { +int crc_sd_16bit() +{ char test[512]; uint32_t crc; - FastCRC sd(CRC_16BIT_SD); + MbedCRC<POLY_16BIT_CCITT, 16> sd(0, 0, false, false); memset(test, 0xFF, 512); // 512 bytes with 0xFF data --> CRC16 = 0x7FA1 - sd.init(); sd.compute((void *)test, 512, &crc); - printf("The 16BIT SD CRC of 512 bytes with 0xFF data is \"0x7FA1\" Result: 0x%x\n", crc); - sd.deinit(); + printf("16BIT SD CRC (512 bytes 0xFF) is \"0x7FA1\" Result: 0x%x\n", crc); return 0; }