![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnCRCUtils.h@125:ce4045184366, 2019-06-05 (annotated)
- Committer:
- uci1
- Date:
- Wed Jun 05 17:29:31 2019 +0000
- Revision:
- 125:ce4045184366
- Parent:
- 40:1324da35afd4
Added SnRateListner proto-class, publishing this version of the code in order to enable exporting of most recent features.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uci1 | 21:ce51bb0ba4a5 | 1 | #ifndef SN_SnCRCUtils |
uci1 | 21:ce51bb0ba4a5 | 2 | #define SN_SnCRCUtils |
uci1 | 21:ce51bb0ba4a5 | 3 | |
uci1 | 38:9070c17536cd | 4 | namespace SnCRCUtils { |
uci1 | 38:9070c17536cd | 5 | |
uci1 | 21:ce51bb0ba4a5 | 6 | /*******************************************************************\ |
uci1 | 21:ce51bb0ba4a5 | 7 | * CRC code "borrowed" from: * |
uci1 | 21:ce51bb0ba4a5 | 8 | * http://mbed.org/users/jpelletier/programs/CRC/lje513 * |
uci1 | 21:ce51bb0ba4a5 | 9 | * Library : lib_crc * |
uci1 | 21:ce51bb0ba4a5 | 10 | * File : lib_crc.c * |
uci1 | 21:ce51bb0ba4a5 | 11 | * Author : Lammert Bies 1999-2008 * |
uci1 | 21:ce51bb0ba4a5 | 12 | * E-mail : info@lammertbies.nl * |
uci1 | 21:ce51bb0ba4a5 | 13 | * Language : ANSI C * |
uci1 | 21:ce51bb0ba4a5 | 14 | \*******************************************************************/ |
uci1 | 21:ce51bb0ba4a5 | 15 | static const uint32_t crc_tabxfer_normal[] = { |
uci1 | 21:ce51bb0ba4a5 | 16 | 0x00000000, 0x000000AF, 0x0000015E, 0x000001F1, 0x000002BC, 0x00000213, 0x000003E2, 0x0000034D, |
uci1 | 21:ce51bb0ba4a5 | 17 | 0x00000578, 0x000005D7, 0x00000426, 0x00000489, 0x000007C4, 0x0000076B, 0x0000069A, 0x00000635, |
uci1 | 21:ce51bb0ba4a5 | 18 | 0x00000AF0, 0x00000A5F, 0x00000BAE, 0x00000B01, 0x0000084C, 0x000008E3, 0x00000912, 0x000009BD, |
uci1 | 21:ce51bb0ba4a5 | 19 | 0x00000F88, 0x00000F27, 0x00000ED6, 0x00000E79, 0x00000D34, 0x00000D9B, 0x00000C6A, 0x00000CC5, |
uci1 | 21:ce51bb0ba4a5 | 20 | 0x000015E0, 0x0000154F, 0x000014BE, 0x00001411, 0x0000175C, 0x000017F3, 0x00001602, 0x000016AD, |
uci1 | 21:ce51bb0ba4a5 | 21 | 0x00001098, 0x00001037, 0x000011C6, 0x00001169, 0x00001224, 0x0000128B, 0x0000137A, 0x000013D5, |
uci1 | 21:ce51bb0ba4a5 | 22 | 0x00001F10, 0x00001FBF, 0x00001E4E, 0x00001EE1, 0x00001DAC, 0x00001D03, 0x00001CF2, 0x00001C5D, |
uci1 | 21:ce51bb0ba4a5 | 23 | 0x00001A68, 0x00001AC7, 0x00001B36, 0x00001B99, 0x000018D4, 0x0000187B, 0x0000198A, 0x00001925, |
uci1 | 21:ce51bb0ba4a5 | 24 | 0x00002BC0, 0x00002B6F, 0x00002A9E, 0x00002A31, 0x0000297C, 0x000029D3, 0x00002822, 0x0000288D, |
uci1 | 21:ce51bb0ba4a5 | 25 | 0x00002EB8, 0x00002E17, 0x00002FE6, 0x00002F49, 0x00002C04, 0x00002CAB, 0x00002D5A, 0x00002DF5, |
uci1 | 21:ce51bb0ba4a5 | 26 | 0x00002130, 0x0000219F, 0x0000206E, 0x000020C1, 0x0000238C, 0x00002323, 0x000022D2, 0x0000227D, |
uci1 | 21:ce51bb0ba4a5 | 27 | 0x00002448, 0x000024E7, 0x00002516, 0x000025B9, 0x000026F4, 0x0000265B, 0x000027AA, 0x00002705, |
uci1 | 21:ce51bb0ba4a5 | 28 | 0x00003E20, 0x00003E8F, 0x00003F7E, 0x00003FD1, 0x00003C9C, 0x00003C33, 0x00003DC2, 0x00003D6D, |
uci1 | 21:ce51bb0ba4a5 | 29 | 0x00003B58, 0x00003BF7, 0x00003A06, 0x00003AA9, 0x000039E4, 0x0000394B, 0x000038BA, 0x00003815, |
uci1 | 21:ce51bb0ba4a5 | 30 | 0x000034D0, 0x0000347F, 0x0000358E, 0x00003521, 0x0000366C, 0x000036C3, 0x00003732, 0x0000379D, |
uci1 | 21:ce51bb0ba4a5 | 31 | 0x000031A8, 0x00003107, 0x000030F6, 0x00003059, 0x00003314, 0x000033BB, 0x0000324A, 0x000032E5, |
uci1 | 21:ce51bb0ba4a5 | 32 | |
uci1 | 21:ce51bb0ba4a5 | 33 | 0x00005780, 0x0000572F, 0x000056DE, 0x00005671, 0x0000553C, 0x00005593, 0x00005462, 0x000054CD, |
uci1 | 21:ce51bb0ba4a5 | 34 | 0x000052F8, 0x00005257, 0x000053A6, 0x00005309, 0x00005044, 0x000050EB, 0x0000511A, 0x000051B5, |
uci1 | 21:ce51bb0ba4a5 | 35 | 0x00005D70, 0x00005DDF, 0x00005C2E, 0x00005C81, 0x00005FCC, 0x00005F63, 0x00005E92, 0x00005E3D, |
uci1 | 21:ce51bb0ba4a5 | 36 | 0x00005808, 0x000058A7, 0x00005956, 0x000059F9, 0x00005AB4, 0x00005A1B, 0x00005BEA, 0x00005B45, |
uci1 | 21:ce51bb0ba4a5 | 37 | 0x00004260, 0x000042CF, 0x0000433E, 0x00004391, 0x000040DC, 0x00004073, 0x00004182, 0x0000412D, |
uci1 | 21:ce51bb0ba4a5 | 38 | 0x00004718, 0x000047B7, 0x00004646, 0x000046E9, 0x000045A4, 0x0000450B, 0x000044FA, 0x00004455, |
uci1 | 21:ce51bb0ba4a5 | 39 | 0x00004890, 0x0000483F, 0x000049CE, 0x00004961, 0x00004A2C, 0x00004A83, 0x00004B72, 0x00004BDD, |
uci1 | 21:ce51bb0ba4a5 | 40 | 0x00004DE8, 0x00004D47, 0x00004CB6, 0x00004C19, 0x00004F54, 0x00004FFB, 0x00004E0A, 0x00004EA5, |
uci1 | 21:ce51bb0ba4a5 | 41 | 0x00007C40, 0x00007CEF, 0x00007D1E, 0x00007DB1, 0x00007EFC, 0x00007E53, 0x00007FA2, 0x00007F0D, |
uci1 | 21:ce51bb0ba4a5 | 42 | 0x00007938, 0x00007997, 0x00007866, 0x000078C9, 0x00007B84, 0x00007B2B, 0x00007ADA, 0x00007A75, |
uci1 | 21:ce51bb0ba4a5 | 43 | 0x000076B0, 0x0000761F, 0x000077EE, 0x00007741, 0x0000740C, 0x000074A3, 0x00007552, 0x000075FD, |
uci1 | 21:ce51bb0ba4a5 | 44 | 0x000073C8, 0x00007367, 0x00007296, 0x00007239, 0x00007174, 0x000071DB, 0x0000702A, 0x00007085, |
uci1 | 21:ce51bb0ba4a5 | 45 | 0x000069A0, 0x0000690F, 0x000068FE, 0x00006851, 0x00006B1C, 0x00006BB3, 0x00006A42, 0x00006AED, |
uci1 | 21:ce51bb0ba4a5 | 46 | 0x00006CD8, 0x00006C77, 0x00006D86, 0x00006D29, 0x00006E64, 0x00006ECB, 0x00006F3A, 0x00006F95, |
uci1 | 21:ce51bb0ba4a5 | 47 | 0x00006350, 0x000063FF, 0x0000620E, 0x000062A1, 0x000061EC, 0x00006143, 0x000060B2, 0x0000601D, |
uci1 | 21:ce51bb0ba4a5 | 48 | 0x00006628, 0x00006687, 0x00006776, 0x000067D9, 0x00006494, 0x0000643B, 0x000065CA, 0x00006565 |
uci1 | 21:ce51bb0ba4a5 | 49 | }; |
uci1 | 21:ce51bb0ba4a5 | 50 | |
uci1 | 21:ce51bb0ba4a5 | 51 | // |
uci1 | 21:ce51bb0ba4a5 | 52 | // CRC functions |
uci1 | 21:ce51bb0ba4a5 | 53 | // |
uci1 | 21:ce51bb0ba4a5 | 54 | inline |
uci1 | 21:ce51bb0ba4a5 | 55 | uint32_t update_crc32_normal(const uint32_t* table, uint32_t crc, const uint8_t c ) { |
uci1 | 21:ce51bb0ba4a5 | 56 | uint32_t long_c; |
uci1 | 21:ce51bb0ba4a5 | 57 | |
uci1 | 21:ce51bb0ba4a5 | 58 | long_c = 0x000000ffL & (uint32_t) c; |
uci1 | 21:ce51bb0ba4a5 | 59 | |
uci1 | 21:ce51bb0ba4a5 | 60 | return (crc << 8) ^ table[((crc >> 24) ^ long_c) & 0xff]; |
uci1 | 21:ce51bb0ba4a5 | 61 | } |
uci1 | 21:ce51bb0ba4a5 | 62 | |
uci1 | 21:ce51bb0ba4a5 | 63 | inline |
uci1 | 21:ce51bb0ba4a5 | 64 | uint32_t update_crc32_xfer( uint32_t crc, const uint8_t c ) { |
uci1 | 21:ce51bb0ba4a5 | 65 | return update_crc32_normal(crc_tabxfer_normal,crc,c); |
uci1 | 21:ce51bb0ba4a5 | 66 | } |
uci1 | 21:ce51bb0ba4a5 | 67 | |
uci1 | 38:9070c17536cd | 68 | // |
uci1 | 38:9070c17536cd | 69 | // calculate CRC for data set |
uci1 | 38:9070c17536cd | 70 | // |
uci1 | 38:9070c17536cd | 71 | template<typename T> |
uci1 | 38:9070c17536cd | 72 | static |
uci1 | 40:1324da35afd4 | 73 | uint32_t GetUpdatedCRC32for(uint32_t crc, const T* const data, const uint32_t len) { |
uci1 | 38:9070c17536cd | 74 | // calculate the 32bit CRC for an array of data |
uci1 | 38:9070c17536cd | 75 | // len = number of array elements; not number of bytes |
uci1 | 38:9070c17536cd | 76 | |
uci1 | 38:9070c17536cd | 77 | union { |
uci1 | 38:9070c17536cd | 78 | const T* x; |
uci1 | 38:9070c17536cd | 79 | const uint8_t* c; |
uci1 | 38:9070c17536cd | 80 | } d; |
uci1 | 38:9070c17536cd | 81 | d.x = data; |
uci1 | 38:9070c17536cd | 82 | const uint32_t bytes = len * sizeof(T); |
uci1 | 38:9070c17536cd | 83 | for (register uint32_t i=0; i<bytes; ++i, ++d.c) { |
uci1 | 38:9070c17536cd | 84 | crc = update_crc32_xfer(crc, *(d.c)); |
uci1 | 38:9070c17536cd | 85 | } |
uci1 | 38:9070c17536cd | 86 | return crc; |
uci1 | 38:9070c17536cd | 87 | } |
uci1 | 38:9070c17536cd | 88 | |
uci1 | 40:1324da35afd4 | 89 | template<typename T> |
uci1 | 40:1324da35afd4 | 90 | static |
uci1 | 40:1324da35afd4 | 91 | uint32_t GetCRC32for(const T* const data, const uint32_t len) { |
uci1 | 40:1324da35afd4 | 92 | // calculate the 32bit CRC for an array of data |
uci1 | 40:1324da35afd4 | 93 | // len = number of array elements; not number of bytes |
uci1 | 40:1324da35afd4 | 94 | uint32_t crc(0); |
uci1 | 40:1324da35afd4 | 95 | return GetUpdatedCRC32for(crc, data, len); |
uci1 | 21:ce51bb0ba4a5 | 96 | } |
uci1 | 21:ce51bb0ba4a5 | 97 | |
uci1 | 38:9070c17536cd | 98 | }; |
uci1 | 21:ce51bb0ba4a5 | 99 | |
uci1 | 0:664899e0b988 | 100 | #endif // SN_SnCRCUtils |