mbed_example
/
CRC_eample_sd
CRC example for SD driver
main.cpp@3:97e3e51ca5d5, 2018-10-24 (annotated)
- Committer:
- Maciej Bocianski
- Date:
- Wed Oct 24 11:58:37 2018 +0200
- Revision:
- 3:97e3e51ca5d5
- Parent:
- 2:ee110889fa99
fix compilation warnings
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 | |
deepikabhavnani | 2:ee110889fa99 | 3 | int crc_sd_7bit() |
deepikabhavnani | 2:ee110889fa99 | 4 | { |
deepikabhavnani | 2:ee110889fa99 | 5 | MbedCRC<POLY_7BIT_SD, 7> ct; |
deepikabhavnani | 1:ca0b1e353dfe | 6 | char test[5]; |
deepikabhavnani | 1:ca0b1e353dfe | 7 | uint32_t crc; |
deepikabhavnani | 1:ca0b1e353dfe | 8 | |
deepikabhavnani | 0:e60fda833675 | 9 | test[0] = 0x40; |
deepikabhavnani | 0:e60fda833675 | 10 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 11 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 12 | test[3] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 13 | test[4] = 0x00; |
deepikabhavnani | 1:ca0b1e353dfe | 14 | |
deepikabhavnani | 1:ca0b1e353dfe | 15 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 16 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 2:ee110889fa99 | 17 | crc = (crc | 0x01) & 0xFF; |
Maciej Bocianski |
3:97e3e51ca5d5 | 18 | printf("The CRC of 0x%lx \"CMD0\" is \"0x95\" Result: 0x%lx\n", |
deepikabhavnani | 2:ee110889fa99 | 19 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 20 | |
deepikabhavnani | 0:e60fda833675 | 21 | test[0] = 0x48; |
deepikabhavnani | 0:e60fda833675 | 22 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 23 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 24 | test[3] = 0x01; |
deepikabhavnani | 0:e60fda833675 | 25 | test[4] = 0xAA; |
deepikabhavnani | 1:ca0b1e353dfe | 26 | |
deepikabhavnani | 1:ca0b1e353dfe | 27 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 28 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 2:ee110889fa99 | 29 | crc = (crc | 0x01) & 0xFF; |
Maciej Bocianski |
3:97e3e51ca5d5 | 30 | printf("The CRC of 0x%lx \"CMD8\" is \"0x87\" Result: 0x%lx\n", |
deepikabhavnani | 2:ee110889fa99 | 31 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 32 | |
deepikabhavnani | 0:e60fda833675 | 33 | test[0] = 0x51; |
deepikabhavnani | 0:e60fda833675 | 34 | test[1] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 35 | test[2] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 36 | test[3] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 37 | test[4] = 0x00; |
deepikabhavnani | 0:e60fda833675 | 38 | |
deepikabhavnani | 1:ca0b1e353dfe | 39 | ct.compute((void *)test, 5, &crc); |
deepikabhavnani | 0:e60fda833675 | 40 | // CRC 7-bit as 8-bit data |
deepikabhavnani | 2:ee110889fa99 | 41 | crc = (crc | 0x01) & 0xFF; |
Maciej Bocianski |
3:97e3e51ca5d5 | 42 | printf("The CRC of 0x%lx \"CMD17\" is \"0x55\" Result: 0x%lx\n", |
deepikabhavnani | 2:ee110889fa99 | 43 | ct.get_polynomial(), crc); |
deepikabhavnani | 0:e60fda833675 | 44 | |
deepikabhavnani | 0:e60fda833675 | 45 | return 0; |
deepikabhavnani | 0:e60fda833675 | 46 | } |
deepikabhavnani | 0:e60fda833675 | 47 | |
deepikabhavnani | 2:ee110889fa99 | 48 | int crc_sd_16bit() |
deepikabhavnani | 2:ee110889fa99 | 49 | { |
deepikabhavnani | 0:e60fda833675 | 50 | char test[512]; |
deepikabhavnani | 0:e60fda833675 | 51 | uint32_t crc; |
deepikabhavnani | 2:ee110889fa99 | 52 | MbedCRC<POLY_16BIT_CCITT, 16> sd(0, 0, false, false); |
deepikabhavnani | 1:ca0b1e353dfe | 53 | |
deepikabhavnani | 0:e60fda833675 | 54 | memset(test, 0xFF, 512); |
deepikabhavnani | 0:e60fda833675 | 55 | // 512 bytes with 0xFF data --> CRC16 = 0x7FA1 |
deepikabhavnani | 0:e60fda833675 | 56 | sd.compute((void *)test, 512, &crc); |
Maciej Bocianski |
3:97e3e51ca5d5 | 57 | printf("16BIT SD CRC (512 bytes 0xFF) is \"0x7FA1\" Result: 0x%lx\n", crc); |
deepikabhavnani | 0:e60fda833675 | 58 | return 0; |
deepikabhavnani | 0:e60fda833675 | 59 | } |
deepikabhavnani | 0:e60fda833675 | 60 | |
deepikabhavnani | 1:ca0b1e353dfe | 61 | int main() |
deepikabhavnani | 0:e60fda833675 | 62 | { |
deepikabhavnani | 1:ca0b1e353dfe | 63 | crc_sd_16bit(); |
deepikabhavnani | 0:e60fda833675 | 64 | crc_sd_7bit(); |
deepikabhavnani | 0:e60fda833675 | 65 | return 0; |
deepikabhavnani | 0:e60fda833675 | 66 | } |