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