annotate OtherSources/data_central_mini.c @ 1048:493a5903ec20 GasConsumption

Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
author Ideenmodellierer
date Sat, 15 Nov 2025 19:29:44 +0100
parents 7801c5d8a562
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
1 /**
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
2 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
3 * @copyright heinrichs weikamp
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
4 * @file data_central_mini.c - bootloader only -
36
7801c5d8a562 Update author name for release
heinrichsweikamp
parents: 5
diff changeset
5 * @author heinrichs weikamp gmbh
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
6 * @date 10-November-2014
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
7 * @version V1.0.3
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
8 * @since 10-Nov-2014
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
9 * @brief
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
10 * @bug
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
11 * @warning
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
12 @verbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
13
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
14 @endverbatim
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
15 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
16 * @attention
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
17 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
18 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
19 *
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
20 ******************************************************************************
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
21 */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
22
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
23 /* Includes ------------------------------------------------------------------*/
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
24 #include <string.h>
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
25 #include "data_central.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
26 #include "stm32f4xx_hal.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
27 #include "crcmodel.h"
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
28
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
29 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
30 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
31 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
32
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
33 /* Fill the structure fields with the read parameters */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
34 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
35 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
36 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
37 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
38
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
39 /* Convert the date structure parameters to Binary format */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
40 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
41 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
42 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
43 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
44
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
45 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
46 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
47 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
48
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
49 /* Fill the structure fields with the read parameters */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
50 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
51 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
52 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
53 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
54
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
55 /* Convert the time structure parameters to Binary format */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
56 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
57 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
58 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
59 sTime->SubSeconds = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
60 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
61
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
62
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
63 /* This is derived from crc32b but does table lookup. First the table
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
64 itself is calculated, if it has not yet been set up.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
65 Not counting the table setup (which would probably be a separate
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
66 function), when compiled to Cyclops with GCC, this function executes in
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
67 7 + 13n instructions, where n is the number of bytes in the input
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
68 message. It should be doable in 4 + 9n instructions. In any case, two
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
69 of the 13 or 9 instrucions are load byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
70 This is Figure 14-7 in the text. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
71
36
7801c5d8a562 Update author name for release
heinrichsweikamp
parents: 5
diff changeset
72 /* http://www.hackersdelight.org/ i guess ;-) *hw */
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
73
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
74 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
75 int i, j;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
76 uint32_t byte, crc, mask;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
77 static unsigned int table[256] = {0};
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
78
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
79 /* Set up the table, if necessary. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
80 if (table[1] == 0) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
81 for (byte = 0; byte <= 255; byte++) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
82 crc = byte;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
83 for (j = 7; j >= 0; j--) { // Do eight times.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
84 mask = -(crc & 1);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
85 crc = (crc >> 1) ^ (0xEDB88320 & mask);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
86 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
87 table[byte] = crc;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
88 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
89 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
90
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
91 /* Through with table setup, now calculate the CRC. */
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
92 i = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
93 crc = 0xFFFFFFFF;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
94 while (length--) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
95 byte = message[i];
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
96 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
97 i = i + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
98 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
99 if(length2)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
100 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
101 i = 0;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
102 while (length2--) {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
103 byte = message2[i];
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
104 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
105 i = i + 1;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
106 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
107 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
108 return ~crc;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
109 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
110
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
111
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
112 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
113 {
1048
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
114 cm_t crc_model;
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
115 uint32_t word_to_do;
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
116 uint8_t byte_to_do;
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
117 int i;
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
118
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
119 uint32_t wordCnt = 0;
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121 // Values for the STM32F generator.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123 crc_model.cm_width = 32; // 32-bit CRC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126 crc_model.cm_refin = FALSE; // CRC calculated MSB first
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130 cm_ini(&crc_model);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131
1048
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
132 do
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134 // The STM32F10x hardware does 32-bit words at a time!!!
1048
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
135 if(wordCnt >= (768000/4))
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136 word_to_do = *buffer2++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 word_to_do = *buffer1++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140 // Do all bytes in the 32-bit word.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 for (i = 0; i < sizeof(word_to_do); i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
143 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
144 // We calculate a *byte* at a time. If the CRC is MSB first we
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
145 // do the next MS byte and vica-versa.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 if (crc_model.cm_refin == FALSE)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149 // MSB first. Do the next MS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152 word_to_do <<= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 // LSB first. Do the next LS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159 word_to_do >>= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162 cm_nxt(&crc_model, byte_to_do);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163 }
1048
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
164 wordCnt++;
493a5903ec20 Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
Ideenmodellierer
parents: 36
diff changeset
165 } while (wordCnt != words);
5
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 // Return the final result.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169 return (cm_crc(&crc_model));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175 cm_t crc_model;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176 uint32_t word_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177 uint8_t byte_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178 int i;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 // Values for the STM32F generator.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182 crc_model.cm_width = 32; // 32-bit CRC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185 crc_model.cm_refin = FALSE; // CRC calculated MSB first
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 cm_ini(&crc_model);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191 while (words--)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193 // The STM32F10x hardware does 32-bit words at a time!!!
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
194
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
195 word_to_do = *buffer++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
196
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
197 // Do all bytes in the 32-bit word.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
199 for (i = 0; i < sizeof(word_to_do); i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
200 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
201 // We calculate a *byte* at a time. If the CRC is MSB first we
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
202 // do the next MS byte and vica-versa.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
203
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
204 if (crc_model.cm_refin == FALSE)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
205 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
206 // MSB first. Do the next MS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
207
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209 word_to_do <<= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
213 // LSB first. Do the next LS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
214
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216 word_to_do >>= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
217 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
218
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
219 cm_nxt(&crc_model, byte_to_do);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
221 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
222
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
223 // Return the final result.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
225 return (cm_crc(&crc_model));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
226 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
227