annotate OtherSources/data_central_mini.c @ 947:96cf6c53c934 Evo_2_23

GNSS sleep mode: Backup voltage is now enabled during initialization. Power saving interval has been changed to 20 second active in a 60 minutes cycle.
author Ideenmodellierer
date Sun, 22 Dec 2024 21:14:41 +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 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
114 cm_t crc_model;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
115 uint32_t word_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
116 uint8_t byte_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
117 int i;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
118
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
119 // Values for the STM32F generator.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
120
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
121 crc_model.cm_width = 32; // 32-bit CRC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
122 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
123 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
124 crc_model.cm_refin = FALSE; // CRC calculated MSB first
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
125 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
126 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
127
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
128 cm_ini(&crc_model);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
129
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
130 while (words--)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
131 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
132 // The STM32F10x hardware does 32-bit words at a time!!!
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
133 if(words > (768000/4))
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
134 word_to_do = *buffer2++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
135 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
136 word_to_do = *buffer1++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
137
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
138 // Do all bytes in the 32-bit word.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
139
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
140 for (i = 0; i < sizeof(word_to_do); i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
141 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
142 // We calculate a *byte* at a time. If the CRC is MSB first we
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
143 // do the next MS byte and vica-versa.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
144
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
145 if (crc_model.cm_refin == FALSE)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
146 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
147 // MSB first. Do the next MS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
148
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
149 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
150 word_to_do <<= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
151 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
152 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
153 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
154 // LSB first. Do the next LS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
155
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
156 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
157 word_to_do >>= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
158 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
159
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
160 cm_nxt(&crc_model, byte_to_do);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
161 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
162 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
163
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
164 // Return the final result.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
165
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
166 return (cm_crc(&crc_model));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
167 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
168
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
169
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
170 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
171 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
172 cm_t crc_model;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
173 uint32_t word_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
174 uint8_t byte_to_do;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
175 int i;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
176
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
177 // Values for the STM32F generator.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
178
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
179 crc_model.cm_width = 32; // 32-bit CRC
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
180 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
181 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
182 crc_model.cm_refin = FALSE; // CRC calculated MSB first
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
183 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
184 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
185
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
186 cm_ini(&crc_model);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
187
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
188 while (words--)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
189 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
190 // The STM32F10x hardware does 32-bit words at a time!!!
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
191
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
192 word_to_do = *buffer++;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
193
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
194 // Do all bytes in the 32-bit word.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
195
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
196 for (i = 0; i < sizeof(word_to_do); i++)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
197 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
198 // We calculate a *byte* at a time. If the CRC is MSB first we
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
199 // do the next MS byte and vica-versa.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
200
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
201 if (crc_model.cm_refin == FALSE)
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
202 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
203 // MSB first. Do the next MS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
204
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
205 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
206 word_to_do <<= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
207 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
208 else
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
209 {
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
210 // LSB first. Do the next LS byte.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
211
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
212 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
213 word_to_do >>= 8;
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
214 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
215
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
216 cm_nxt(&crc_model, byte_to_do);
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
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
220 // Return the final result.
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
221
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
222 return (cm_crc(&crc_model));
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
223 }
e65d01b6a17e MOVE files for other applications
JeanDo
parents:
diff changeset
224