Mercurial > public > ostc_companion
comparison crc_wrapper.cpp @ 11:6fba58c4964b
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:57:24 +0000 |
| parents | 115cfa4a3239 |
| children |
comparison
equal
deleted
inserted
replaced
| 10:9a3c1a6f9833 | 11:6fba58c4964b |
|---|---|
| 2 | 2 |
| 3 extern "C" { | 3 extern "C" { |
| 4 #include "crcmodel.h" | 4 #include "crcmodel.h" |
| 5 } | 5 } |
| 6 | 6 |
| 7 | |
| 8 CrcWrapper::CrcWrapper(QObject *parent) | 7 CrcWrapper::CrcWrapper(QObject *parent) |
| 9 : QObject(parent) | 8 : QObject(parent) |
| 10 {} | 9 {} |
| 11 | 10 |
| 12 | |
| 13 void CrcWrapper::init(p_cm_t p_cm) | 11 void CrcWrapper::init(p_cm_t p_cm) |
| 14 { | 12 { |
| 15 cm_ini(p_cm); | 13 cm_ini(p_cm); |
| 16 } | 14 } |
| 17 | 15 |
| 18 void CrcWrapper::cm_next(p_cm_t p_cm, int ch) | 16 void CrcWrapper::cm_next(p_cm_t p_cm, int ch) |
| 19 { | 17 { |
| 20 cm_nxt(p_cm, ch); | 18 cm_nxt(p_cm, ch); |
| 21 } | 19 } |
| 22 | 20 |
| 23 uint32_t CrcWrapper::CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) | 21 uint32_t CrcWrapper::CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) |
| 24 { | 22 { |
| 25 cm_t crc_model; | 23 cm_t crc_model; |
| 26 uint32_t word_to_do; | 24 uint32_t word_to_do; |
| 27 uint8_t byte_to_do; | 25 uint8_t byte_to_do; |
| 28 int i; | 26 int i; |
| 29 | 27 |
| 30 // Values for the STM32F generator. | 28 // Values for the STM32F generator. |
| 31 | 29 |
| 32 crc_model.cm_width = 32; // 32-bit CRC | 30 crc_model.cm_width = 32; // 32-bit CRC |
| 33 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial | 31 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial |
| 34 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's | 32 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's |
| 35 crc_model.cm_refin = FALSE; // CRC calculated MSB first | 33 crc_model.cm_refin = FALSE; // CRC calculated MSB first |
| 36 crc_model.cm_refot = FALSE; // Final result is not bit-reversed | 34 crc_model.cm_refot = FALSE; // Final result is not bit-reversed |
| 37 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this | 35 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this |
| 38 | 36 |
| 39 cm_ini(&crc_model); | 37 cm_ini(&crc_model); |
| 40 | 38 |
| 41 while (words--) | 39 while (words--) { |
| 42 { | |
| 43 // The STM32F10x hardware does 32-bit words at a time!!! | 40 // The STM32F10x hardware does 32-bit words at a time!!! |
| 44 | 41 |
| 45 word_to_do = *buffer++; | 42 word_to_do = *buffer++; |
| 46 | 43 |
| 47 // Do all bytes in the 32-bit word. | 44 // Do all bytes in the 32-bit word. |
| 48 | 45 |
| 49 for (i = 0; i < sizeof(word_to_do); i++) | 46 for (i = 0; i < sizeof(word_to_do); i++) { |
| 50 { | |
| 51 // We calculate a *byte* at a time. If the CRC is MSB first we | 47 // We calculate a *byte* at a time. If the CRC is MSB first we |
| 52 // do the next MS byte and vica-versa. | 48 // do the next MS byte and vica-versa. |
| 53 | 49 |
| 54 if (crc_model.cm_refin == FALSE) | 50 if (crc_model.cm_refin == FALSE) { |
| 55 { | |
| 56 // MSB first. Do the next MS byte. | 51 // MSB first. Do the next MS byte. |
| 57 | 52 |
| 58 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); | 53 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); |
| 59 word_to_do <<= 8; | 54 word_to_do <<= 8; |
| 60 } | 55 } else { |
| 61 else | |
| 62 { | |
| 63 // LSB first. Do the next LS byte. | 56 // LSB first. Do the next LS byte. |
| 64 | 57 |
| 65 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); | 58 byte_to_do = (uint8_t) (word_to_do & 0x000000FF); |
| 66 word_to_do >>= 8; | 59 word_to_do >>= 8; |
| 67 } | 60 } |
| 72 | 65 |
| 73 // Return the final result. | 66 // Return the final result. |
| 74 | 67 |
| 75 return (cm_crc(&crc_model)); | 68 return (cm_crc(&crc_model)); |
| 76 } | 69 } |
| 77 |
