mbed_example
/
CRC_eample_sd
CRC example for SD driver
main.cpp@0:e60fda833675, 2017-12-18 (annotated)
- Committer:
- deepikabhavnani
- Date:
- Mon Dec 18 22:58:44 2017 +0000
- Revision:
- 0:e60fda833675
- Child:
- 1:ca0b1e353dfe
CRC example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
deepikabhavnani | 0:e60fda833675 | 1 | #include "mbed.h" |
deepikabhavnani | 0:e60fda833675 | 2 | #include "mbed_crc.h" |
deepikabhavnani | 0:e60fda833675 | 3 | #include "SlowCRC.h" |
deepikabhavnani | 0:e60fda833675 | 4 | #include "FastCRC.h" |
deepikabhavnani | 0:e60fda833675 | 5 | |
deepikabhavnani | 0:e60fda833675 | 6 | int crc_sd_7bit() { |
deepikabhavnani | 0:e60fda833675 | 7 | SlowCRC<uint8_t> ct(CRC_7BIT_SD); |
deepikabhavnani | 0:e60fda833675 | 8 | |
deepikabhavnani | 0:e60fda833675 | 9 | ct.init(); |
deepikabhavnani | 0:e60fda833675 | 10 | test[0] = 0x40; |
deepikabhavnani | 0:e60fda833675 | 11 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 12 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 13 | test[3] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 14 | test[4] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 15 | |
deepikabhavnani | 0:e60fda833675 | 16 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 17 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 0:e60fda833675 | 18 | crc = (crc << 1 ) + 1; |
deepikabhavnani | 0:e60fda833675 | 19 | printf("The CRC of 0x%x \"CMD0\" is \"0x95\" Result: 0x%x\n", |
deepikabhavnani | 0:e60fda833675 | 20 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 21 | |
deepikabhavnani | 0:e60fda833675 | 22 | test[0] = 0x48; |
deepikabhavnani | 0:e60fda833675 | 23 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 24 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 25 | test[3] = 0x01; |
deepikabhavnani | 0:e60fda833675 | 26 | test[4] = 0xAA; |
deepikabhavnani | 0:e60fda833675 | 27 | |
deepikabhavnani | 0:e60fda833675 | 28 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 29 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 0:e60fda833675 | 30 | crc = (crc << 1 ) + 1; |
deepikabhavnani | 0:e60fda833675 | 31 | printf("The CRC of 0x%x \"CMD8\" is \"0x87\" Result: 0x%x\n", |
deepikabhavnani | 0:e60fda833675 | 32 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 33 | |
deepikabhavnani | 0:e60fda833675 | 34 | test[0] = 0x51; |
deepikabhavnani | 0:e60fda833675 | 35 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 36 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 37 | test[3] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 38 | test[4] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 39 | |
deepikabhavnani | 0:e60fda833675 | 40 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 41 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 0:e60fda833675 | 42 | crc = (crc << 1 ) + 1; |
deepikabhavnani | 0:e60fda833675 | 43 | printf("The CRC of 0x%x \"CMD17\" is \"0x55\" Result: 0x%x\n", |
deepikabhavnani | 0:e60fda833675 | 44 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 45 | |
deepikabhavnani | 0:e60fda833675 | 46 | ct.deinit(); |
deepikabhavnani | 0:e60fda833675 | 47 | return 0; |
deepikabhavnani | 0:e60fda833675 | 48 | } |
deepikabhavnani | 0:e60fda833675 | 49 | |
deepikabhavnani | 0:e60fda833675 | 50 | int crc_sd_16bit() { |
deepikabhavnani | 0:e60fda833675 | 51 | char test[512]; |
deepikabhavnani | 0:e60fda833675 | 52 | uint32_t crc; |
deepikabhavnani | 0:e60fda833675 | 53 | FastCRC<uint16_t> sd(CRC_16BIT_SD); |
deepikabhavnani | 0:e60fda833675 | 54 | |
deepikabhavnani | 0:e60fda833675 | 55 | memset(test, 0xFF, 512); |
deepikabhavnani | 0:e60fda833675 | 56 | // 512 bytes with 0xFF data --> CRC16 = 0x7FA1 |
deepikabhavnani | 0:e60fda833675 | 57 | sd.init(); |
deepikabhavnani | 0:e60fda833675 | 58 | sd.compute((void *)test, 512, &crc); |
deepikabhavnani | 0:e60fda833675 | 59 | printf("The 16BIT SD CRC of 512 bytes with 0xFF data is \"0x7FA1\" Result: 0x%x\n", crc); |
deepikabhavnani | 0:e60fda833675 | 60 | sd.deinit(); |
deepikabhavnani | 0:e60fda833675 | 61 | return 0; |
deepikabhavnani | 0:e60fda833675 | 62 | } |
deepikabhavnani | 0:e60fda833675 | 63 | |
deepikabhavnani | 0:e60fda833675 | 64 | int main() |
deepikabhavnani | 0:e60fda833675 | 65 | { |
deepikabhavnani | 0:e60fda833675 | 66 | crc_sd_16bit(); |
deepikabhavnani | 0:e60fda833675 | 67 | crc_sd_7bit(); |
deepikabhavnani | 0:e60fda833675 | 68 | return 0; |
deepikabhavnani | 0:e60fda833675 | 69 | } |