comparison crc_wrapper.cpp @ 5:115cfa4a3239 default tip

Added icon upload function for OSTC 4/5 For the upload the same process as the one for the firmware update is used => CRC functionality has been copied from the ostc_pack SW
author Ideenmodellierer
date Tue, 30 Dec 2025 21:41:02 +0100
parents
children
comparison
equal deleted inserted replaced
4:e30f00f760d3 5:115cfa4a3239
1 #include "crc_wrapper.h"
2
3 extern "C" {
4 #include "crcmodel.h"
5 }
6
7
8 CrcWrapper::CrcWrapper(QObject *parent)
9 : QObject(parent)
10 {}
11
12
13 void CrcWrapper::init(p_cm_t p_cm)
14 {
15 cm_ini(p_cm);
16 }
17
18 void CrcWrapper::cm_next(p_cm_t p_cm, int ch)
19 {
20 cm_nxt(p_cm, ch);
21 }
22
23 uint32_t CrcWrapper::CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words)
24 {
25 cm_t crc_model;
26 uint32_t word_to_do;
27 uint8_t byte_to_do;
28 int i;
29
30 // Values for the STM32F generator.
31
32 crc_model.cm_width = 32; // 32-bit CRC
33 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
34 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
35 crc_model.cm_refin = FALSE; // CRC calculated MSB first
36 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
37 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
38
39 cm_ini(&crc_model);
40
41 while (words--)
42 {
43 // The STM32F10x hardware does 32-bit words at a time!!!
44
45 word_to_do = *buffer++;
46
47 // Do all bytes in the 32-bit word.
48
49 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
52 // do the next MS byte and vica-versa.
53
54 if (crc_model.cm_refin == FALSE)
55 {
56 // MSB first. Do the next MS byte.
57
58 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
59 word_to_do <<= 8;
60 }
61 else
62 {
63 // LSB first. Do the next LS byte.
64
65 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
66 word_to_do >>= 8;
67 }
68
69 cm_nxt(&crc_model, byte_to_do);
70 }
71 }
72
73 // Return the final result.
74
75 return (cm_crc(&crc_model));
76 }
77