Mercurial > public > ostc_companion
view crc_wrapper.cpp @ 8:21ce6187d32e
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:51:17 +0000 |
| parents | 115cfa4a3239 |
| children | 6fba58c4964b |
line wrap: on
line source
#include "crc_wrapper.h" extern "C" { #include "crcmodel.h" } CrcWrapper::CrcWrapper(QObject *parent) : QObject(parent) {} void CrcWrapper::init(p_cm_t p_cm) { cm_ini(p_cm); } void CrcWrapper::cm_next(p_cm_t p_cm, int ch) { cm_nxt(p_cm, ch); } uint32_t CrcWrapper::CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words) { cm_t crc_model; uint32_t word_to_do; uint8_t byte_to_do; int i; // Values for the STM32F generator. crc_model.cm_width = 32; // 32-bit CRC crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's crc_model.cm_refin = FALSE; // CRC calculated MSB first crc_model.cm_refot = FALSE; // Final result is not bit-reversed crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this cm_ini(&crc_model); while (words--) { // The STM32F10x hardware does 32-bit words at a time!!! word_to_do = *buffer++; // Do all bytes in the 32-bit word. for (i = 0; i < sizeof(word_to_do); i++) { // We calculate a *byte* at a time. If the CRC is MSB first we // do the next MS byte and vica-versa. if (crc_model.cm_refin == FALSE) { // MSB first. Do the next MS byte. byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24); word_to_do <<= 8; } else { // LSB first. Do the next LS byte. byte_to_do = (uint8_t) (word_to_do & 0x000000FF); word_to_do >>= 8; } cm_nxt(&crc_model, byte_to_do); } } // Return the final result. return (cm_crc(&crc_model)); }
