Mercurial > public > ostc4
annotate Discovery/Src/tComm.c @ 303:90e65971f15d cleanup-4
bugfix, cleanup: simplify stopwatch logic and fix fallout
The previous 2 commits (making the depth switch between surface
and diving consistent) increased the time difference (in the
simulator) to about 4 seconds. This commit fixes this again, and
we are back at 1 sec. difference between the 2 timers (notice:
in the simulator). Still not the wanted 0 sec. difference, but
the old stopwatch logic logic was rather convoluted. Resetting to
1 second (instead of 0), and second-1 logic. Basically, this feels
like a bug fixed with a second bug on top to mask it. The code
is now much more logic and consistent (despite the fact that the
real reason for the 1 sec. difference is not yet found).
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Mon, 20 May 2019 12:57:31 +0200 |
parents | ad6ddc4aabcd |
children | 4da2bffb07ca |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tComm.c | |
5 /// \brief Main file for communication with PC | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 08-Aug-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /** | |
30 ============================================================================== | |
31 ##### How to use ##### | |
32 ============================================================================== | |
33 ============================================================================== | |
34 ##### History ##### | |
35 ============================================================================== | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
36 160211 added 4 bytes Serial in update Files after checksum prior to binary |
38 | 37 160211 0x6B changed to version only |
38 160623 fixed 0x72 (in V1.0.9) | |
39 160623 fixed rebuild menu (before update) for V1.0.10 | |
40 | |
41 ============================================================================== | |
42 ##### CTS / RTS ##### | |
43 ============================================================================== | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
44 RTS is Output, CTS is Input |
38 | 45 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
46 BlueMod Pin D7 UART-RTS# is Output |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
47 connected to STM32F429 PA11 CTS (Input) |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
48 also STM32 PA12 RTS is connected to BlueMod UART-CTS# F3 |
38 | 49 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
50 see BlueMod_SR_HWreference_r06.pdf, page 156 |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
51 and MAIN_CPU STM32F4 Reference manual DM00031020.pdf, page 990 |
38 | 52 |
53 | |
54 ============================================================================== | |
55 ##### Codes ##### | |
56 ============================================================================== | |
57 [0x73] upload CPU2 firmware in SDRAM and update CPU2 | |
58 | |
59 [0x74] upload MainCPU firmware in EEPROM and start bootloader | |
60 | |
61 */ | |
62 | |
63 /* Includes ------------------------------------------------------------------*/ | |
64 | |
65 #include "tComm.h" | |
66 | |
67 #include "externCPU2bootloader.h" | |
68 #include "externLogbookFlash.h" | |
69 #include "gfx_colors.h" | |
70 #include "gfx_engine.h" | |
71 #include "gfx_fonts.h" | |
72 #include "ostc.h" | |
73 | |
74 #ifndef BOOTLOADER_STANDALONE | |
75 # include "base.h" | |
76 # include "tHome.h" | |
77 # include "logbook.h" | |
78 # include "tMenu.h" | |
79 #else | |
80 # include "base_bootloader.h" | |
81 # include "firmwareEraseProgram.h" | |
82 #endif | |
83 | |
84 #ifdef SPECIALPROGRAMM | |
85 # include "firmwareEraseProgram.h" | |
86 #endif | |
87 | |
88 #include <string.h> | |
89 | |
90 | |
91 /* Private variables ---------------------------------------------------------*/ | |
92 GFX_DrawCfgScreen tCscreen; | |
93 GFX_DrawCfgWindow tCwindow; | |
94 | |
95 uint8_t receiveStartByteUart = 0; | |
96 uint8_t bluetoothActiveLastTime = 0; | |
97 | |
98 uint8_t StartListeningToUART = 0; | |
229
2c0b502b0a72
cleanup: fix recent extra compiler warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
218
diff
changeset
|
99 char display_text[256] = { 0 }; |
38 | 100 |
101 uint8_t setForcedBluetoothName = 0; | |
102 | |
103 uint8_t updateSettingsAndMenuOnExit = 0; | |
104 | |
105 /* Private types -------------------------------------------------------------*/ | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
106 #define BYTE_DOWNLOAD_MODE (0xBB) |
38 | 107 #define BYTE_SERVICE_MODE (0xAA) |
108 | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
109 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
110 |
38 | 111 const uint8_t id_Region1_firmware = 0xFF; |
112 const uint8_t id_RTE = 0xFE; | |
113 const uint8_t id_FONT = 0x10; | |
114 const uint8_t id_FONT_OLD = 0x00; | |
115 | |
116 /* Private function prototypes -----------------------------------------------*/ | |
117 | |
118 static void tComm_Error_Handler(void); | |
119 static uint8_t select_mode(uint8_t aRxByte); | |
120 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED); | |
121 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED); | |
122 uint8_t receive_update_data_mainCPU_firmware(void); | |
123 uint8_t receive_update_data_mainCPU_variable_firmware(void); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
124 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2); |
38 | 125 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size); |
126 static uint8_t openComm(uint8_t aRxByte); | |
127 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence); | |
128 uint8_t prompt4D4C(uint8_t mode); | |
129 | |
130 #ifdef BOOTLOADER_STANDALONE | |
131 static uint8_t receive_update_data_cpu2(void); | |
132 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer); | |
133 #endif | |
134 | |
135 /* Exported functions --------------------------------------------------------*/ | |
136 | |
137 void tComm_init(void) | |
138 { | |
139 tCscreen.FBStartAdress = 0; | |
140 tCscreen.ImageHeight = 480; | |
141 tCscreen.ImageWidth = 800; | |
142 tCscreen.LayerIndex = 1; | |
143 | |
144 tCwindow.Image = &tCscreen; | |
145 tCwindow.WindowNumberOfTextLines = 6; | |
146 tCwindow.WindowLineSpacing = 65; | |
147 tCwindow.WindowTab = 400; | |
148 tCwindow.WindowX0 = 20; | |
149 tCwindow.WindowX1 = 779; | |
150 tCwindow.WindowY0 = 0; | |
151 tCwindow.WindowY1 = 799; | |
152 | |
153 StartListeningToUART = 1; | |
154 | |
155 /* WHY? | |
156 #ifdef BLE_NENABLE_PIN | |
157 HAL_GPIO_WritePin(BLE_NENABLE_GPIO_PORT,BLE_NENABLE_PIN,GPIO_PIN_RESET); | |
158 #endif | |
159 */ | |
160 } | |
161 | |
162 uint8_t tComm_control(void) | |
163 { | |
164 uint8_t answer = 0; | |
165 #ifndef BOOTLOADER_STANDALONE | |
166 | |
167 /* should do something like reset UART ... */ | |
168 if( settingsGetPointer()->bluetoothActive == 0) | |
169 { | |
170 if(bluetoothActiveLastTime) | |
171 { | |
172 HAL_UART_DeInit(&UartHandle); | |
173 HAL_Delay(1); | |
174 HAL_UART_Init(&UartHandle); | |
175 HAL_Delay(1); | |
176 UartReady = RESET; | |
177 StartListeningToUART = 1; | |
178 bluetoothActiveLastTime = 0; | |
179 receiveStartByteUart = 0; | |
180 } | |
181 return 0; | |
182 } | |
183 else | |
184 { | |
185 bluetoothActiveLastTime = 1; | |
186 } | |
187 | |
188 #endif | |
189 | |
190 /*##-2- Put UART peripheral in reception process ###########################*/ | |
191 | |
192 if((UartReady == RESET) && StartListeningToUART) | |
193 { | |
194 StartListeningToUART = 0; | |
195 if(HAL_UART_Receive_IT(&UartHandle, &receiveStartByteUart, 1) != HAL_OK) | |
196 tComm_Error_Handler(); | |
197 } | |
198 /* Reset transmission flag */ | |
199 if(UartReady == SET) | |
200 { | |
201 UartReady = RESET; | |
202 if((receiveStartByteUart == BYTE_DOWNLOAD_MODE) || (receiveStartByteUart == BYTE_SERVICE_MODE)) | |
203 answer = openComm(receiveStartByteUart); | |
204 StartListeningToUART = 1; | |
205 return answer; | |
206 } | |
207 return 0; | |
208 } | |
209 | |
210 | |
211 void tComm_refresh(void) | |
212 { | |
213 if(tCscreen.FBStartAdress == 0) | |
214 { | |
215 GFX_hwBackgroundOn(); | |
216 tCscreen.FBStartAdress = getFrame(18); | |
217 write_content_simple(&tCscreen, 0, 800, 480-24, &FontT24,"Exit",CLUT_ButtonSurfaceScreen); | |
218 if(receiveStartByteUart == BYTE_SERVICE_MODE) | |
219 GFX_write_string(&FontT48, &tCwindow, "Service mode enabled",2); | |
220 else | |
221 GFX_write_string(&FontT48, &tCwindow, "Download mode enabled",2); | |
166
255eedad4155
cleanup: get rid of some compile warnings
Jan Mulder <jlmulder@xs4all.nl>
parents:
138
diff
changeset
|
222 GFX_SetFramesTopBottom(tCscreen.FBStartAdress, 0,480); |
38 | 223 display_text[0] = 0; |
224 display_text[255] = 0; | |
225 } | |
226 else if(display_text[255]) | |
227 { | |
228 display_text[display_text[255]] = 0; | |
229 releaseFrame(18,tCscreen.FBStartAdress); | |
230 tCscreen.FBStartAdress = getFrame(18); | |
231 write_content_simple(&tCscreen, 0, 800, 480-24, &FontT24,"Exit",CLUT_ButtonSurfaceScreen); | |
232 GFX_write_string(&FontT48, &tCwindow, display_text,2); | |
233 GFX_SetFrameTop(tCscreen.FBStartAdress); | |
234 display_text[0] = 0; | |
235 display_text[255] = 0; | |
236 } | |
237 } | |
238 | |
239 | |
240 void tComm_verlauf(uint8_t percentage_complete) | |
241 { | |
242 uint32_t pDestination; | |
243 | |
244 pDestination = (uint32_t)tCscreen.FBStartAdress; | |
245 pDestination += 150 * tCscreen.ImageHeight * 2; | |
246 pDestination += 100 * 2; | |
247 | |
248 if(percentage_complete > 100) | |
249 percentage_complete = 100; | |
250 | |
251 int i = 1; | |
252 while(i<=percentage_complete) | |
253 { | |
254 i += 1; | |
255 for(int y=0;y<4;y++) | |
256 { | |
257 for(int x=0;x<40;x++) | |
258 { | |
259 *(__IO uint16_t*)pDestination = 0xFF00 + 00; | |
260 pDestination += 2; | |
261 } | |
262 pDestination += (tCscreen.ImageHeight - 40 )* 2; | |
263 } | |
264 pDestination += tCscreen.ImageHeight * 2; // one spare line | |
265 } | |
266 } | |
267 | |
268 | |
269 void tComm_exit(void) | |
270 { | |
271 SStateList status; | |
272 get_globalStateList(&status); | |
273 | |
274 releaseFrame(18,tCscreen.FBStartAdress); | |
275 tCscreen.FBStartAdress = 0; | |
276 GFX_hwBackgroundOff(); | |
277 | |
278 if(setForcedBluetoothName) | |
279 { | |
280 setForcedBluetoothName = 0; | |
281 MX_Bluetooth_PowerOff(); | |
282 HAL_Delay(1000); | |
283 MX_Bluetooth_PowerOn(); | |
284 tComm_Set_Bluetooth_Name(1); | |
285 } | |
286 #ifndef BOOTLOADER_STANDALONE | |
287 if(updateSettingsAndMenuOnExit) | |
288 { | |
289 check_and_correct_settings(); | |
290 createDiveSettings(); | |
291 tM_rebuild_menu_after_tComm(); | |
292 } | |
293 #endif | |
294 updateSettingsAndMenuOnExit = 0; | |
295 | |
296 if(status.base == BaseComm) | |
297 { | |
298 #ifndef BOOTLOADER_STANDALONE | |
299 set_globalState_tHome(); | |
300 #else | |
301 set_globalState_Base(); | |
302 #endif | |
303 } | |
304 } | |
305 | |
306 | |
307 uint8_t tComm_Set_Bluetooth_Name(uint8_t force) | |
308 { | |
309 uint8_t answer = 0; | |
310 | |
311 if(hardwareDataGetPointer()->secondarySerial != 0xFFFF) | |
312 { | |
313 if(force || (hardwareDataGetPointer()->secondary_bluetooth_name_set == 0xFF)) | |
314 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->secondarySerial, 0); | |
315 #ifdef BOOTLOADER_STANDALONE | |
316 if(answer == HAL_OK) | |
317 hardware_programmSecondaryBluetoothNameSet(); | |
318 #endif | |
319 } | |
320 else | |
321 if(hardwareDataGetPointer()->primarySerial != 0xFFFF) | |
322 { | |
323 if(force || (hardwareDataGetPointer()->production_bluetooth_name_set == 0xFF)) | |
324 answer = HW_Set_Bluetooth_Name(hardwareDataGetPointer()->primarySerial, 0); | |
325 #ifdef BOOTLOADER_STANDALONE | |
326 if(answer == HAL_OK) | |
327 hardware_programmPrimaryBluetoothNameSet(); | |
328 #endif | |
329 } | |
330 return answer; | |
331 } | |
332 | |
333 | |
334 uint8_t HW_Set_Bluetooth_Name(uint16_t serial, uint8_t withEscapeSequence) | |
335 { | |
336 uint8_t answer = HAL_OK; | |
337 uint8_t aRxBuffer[50]; | |
338 | |
339 // char aTxFactoryDefaults[50] = "AT&F1\r"; | |
340 | |
341 char aTxBufferEscapeSequence[50] = "+++"; | |
342 // limit is 19 chars, with 7 chars shown in BLE advertising mode | |
343 //________________________123456789012345678901 | |
344 char aTxBufferName[50] = "AT+BNAME=OSTC4-12345\r"; | |
345 char answerOkay[6] = "\r\nOKr\n"; | |
346 | |
347 gfx_number_to_string(5,1,&aTxBufferName[15],serial); | |
348 | |
349 // store active configuration in non-volatile memory | |
350 char aTxBufferWrite[50] = "AT&W\r"; | |
351 | |
352 // char aTxBufferReset[50] = "AT+RESET\r"; | |
353 | |
354 | |
355 HAL_Delay(1010); | |
356 if(withEscapeSequence) | |
357 { | |
358 aRxBuffer[0] = 0; | |
359 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 2000)!= HAL_OK) | |
360 answer = HAL_ERROR; | |
361 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 3, 2000); | |
362 HAL_Delay(1010); | |
363 | |
364 for(int i=0;i<3;i++) | |
365 if(aRxBuffer[i] != '+') | |
366 answer = HAL_ERROR; | |
367 } | |
368 | |
369 aRxBuffer[0] = 0; | |
370 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferName, 21, 2000)!= HAL_OK) | |
371 answer = HAL_ERROR; | |
372 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 21+6, 2000); | |
373 | |
374 for(int i=0;i<21;i++) | |
375 if(aRxBuffer[i] != aTxBufferName[i]) | |
376 answer = HAL_ERROR; | |
377 | |
378 for(int i=0;i<6;i++) | |
379 if(aRxBuffer[21+i] != answerOkay[i]) | |
380 answer = HAL_ERROR; | |
381 | |
382 HAL_Delay(200); | |
383 | |
384 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferWrite, 5, 2000)!= HAL_OK) | |
385 answer = HAL_ERROR; | |
386 HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5+6, 2000); | |
387 | |
388 for(int i=0;i<5;i++) | |
389 if(aRxBuffer[i] != aTxBufferWrite[i]) | |
390 answer = HAL_ERROR; | |
391 | |
392 for(int i=0;i<6;i++) | |
393 if(aRxBuffer[5+i] != answerOkay[i]) | |
394 answer = HAL_ERROR; | |
395 | |
396 answer = HAL_OK; | |
397 return answer; | |
398 } | |
399 | |
400 | |
401 uint8_t openComm(uint8_t aRxByte) | |
402 { | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
403 SStateList status; |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
404 uint8_t timeoutCounter = 0; |
38 | 405 uint8_t answer = 0; |
406 uint8_t service_mode_last_three_bytes[3]; | |
407 uint8_t service_mode_response[5] = | |
408 { | |
409 0x4B, | |
410 0xAB, | |
411 0xCD, | |
412 0xEF, | |
413 0x4C | |
414 }; | |
415 uint8_t download_mode_response[2] = | |
416 { | |
417 0xBB, | |
418 0x4D | |
419 }; | |
420 | |
421 if((aRxByte != BYTE_DOWNLOAD_MODE) && (aRxByte != BYTE_SERVICE_MODE)) | |
422 return 0; | |
423 | |
424 set_globalState(StUART_STANDARD); | |
425 | |
426 /* service mode is four bytes | |
427 0xAA 0xAB 0xCD 0xEF | |
428 answer is | |
429 */ | |
430 | |
431 if(aRxByte == BYTE_SERVICE_MODE) | |
432 { | |
433 if((HAL_UART_Receive(&UartHandle, (uint8_t*)service_mode_last_three_bytes, 3, 2000)!= HAL_OK)) | |
434 answer = 0x00; | |
435 else | |
436 { | |
437 if((service_mode_last_three_bytes[0] != 0xAB) || (service_mode_last_three_bytes[1] != 0xCD) || (service_mode_last_three_bytes[2] != 0xEF)) | |
438 answer = 0x00; | |
439 else | |
440 { | |
441 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)service_mode_response, 5, 2000)!= HAL_OK) | |
442 answer = 0x00; | |
443 else | |
444 answer = prompt4D4C(receiveStartByteUart); | |
445 } | |
446 } | |
447 } | |
448 else //if(aRxByte == BYTE_SERVICE_MODE) | |
449 { | |
450 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)download_mode_response, 2, 2000)!= HAL_OK) | |
451 answer = 0x00; | |
452 else | |
453 answer = prompt4D4C(receiveStartByteUart); | |
454 } | |
455 /* | |
456 uint8_t debug[256] = {0}; | |
457 uint8_t dbgptr = 0; | |
458 debug[dbgptr++] = aRxByte; | |
459 */ | |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
460 while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS * 2)) /* Split 120 seconds timeout into 240 iterations a 500ms */ |
38 | 461 { |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
462 if(HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 500)!= HAL_OK) /* Timeout half a second */ |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
463 { |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
464 timeoutCounter++; |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
465 get_globalStateList(&status); |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
466 if (status.base != BaseComm) |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
467 { |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
468 timeoutCounter = UART_TIMEOUT_SECONDS * 2; /* Abort action triggered outside main loop => exit */ |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
469 } |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
470 } |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
471 else |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
472 { |
38 | 473 // debug[dbgptr++] = aRxByte; |
218
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
474 answer = select_mode(aRxByte); |
ff59d1d07f9c
Splitted 120 seconds UART timeout into chunks of 500ms
ideenmodellierer
parents:
166
diff
changeset
|
475 } |
38 | 476 } |
477 set_returnFromComm(); | |
478 return 1; | |
479 } | |
480 | |
481 | |
482 uint8_t prompt4D4C(uint8_t mode) | |
483 { | |
484 if(mode == BYTE_SERVICE_MODE) | |
485 return 0x4C; | |
486 else | |
487 return 0x4D; | |
488 } | |
489 | |
490 | |
491 uint8_t select_mode(uint8_t type) | |
492 { | |
493 #ifndef BOOTLOADER_STANDALONE | |
494 SLogbookHeader logbookHeader; | |
495 SLogbookHeaderOSTC3 * plogbookHeaderOSTC3; | |
496 SLogbookHeaderOSTC3compact * plogbookHeaderOSTC3compact; | |
497 uint32_t sampleTotalLength; | |
498 SSettings* pSettings = settingsGetPointer(); | |
499 RTC_DateTypeDef sdatestructure; | |
500 RTC_TimeTypeDef stimestructure; | |
501 #else | |
502 uint8_t dummyForBootloader[256] = {0}; | |
503 #endif | |
504 | |
505 uint8_t count; | |
506 uint8_t aTxBuffer[128]; | |
507 uint8_t aRxBuffer[68]; | |
508 uint8_t answer; | |
509 aTxBuffer[0] = type; | |
510 aTxBuffer[1] = prompt4D4C(receiveStartByteUart); | |
511 uint8_t tempHigh, tempLow; | |
512 count = 0; | |
513 | |
514 // service mode only commands | |
515 if(receiveStartByteUart == BYTE_SERVICE_MODE) | |
516 { | |
517 // first part | |
518 switch(type) | |
519 { | |
520 // start communication (again) | |
521 case 0xAA: | |
522 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
523 return 0; | |
524 else | |
525 return prompt4D4C(receiveStartByteUart); | |
526 | |
527 /* | |
528 // update firmware main preparation | |
529 case 0x74: | |
530 ext_flash_erase_firmware_if_not_empty(); | |
531 break; | |
532 | |
533 // update firmware main with variable full access memory location preparation | |
534 case 0x76: | |
535 ext_flash_erase_firmware2_if_not_empty(); | |
536 break; | |
537 */ | |
538 default: | |
539 break; | |
540 } | |
541 | |
542 #ifndef BOOTLOADER_STANDALONE | |
543 uint32_t logCopyDataPtr = 0; | |
544 convert_Type logCopyDataLength; | |
545 uint32_t logCopyDataPtrTemp = 0; | |
546 uint32_t logCopyDataLengthTemp = 0; | |
547 uint8_t logDummyByte = 0; | |
548 uint8_t logStepBackwards = 0; | |
549 convert16_Type totalDiveCount; | |
550 logCopyDataLength.u32bit = 0; | |
551 totalDiveCount.u16bit = 0; | |
552 #endif | |
553 | |
554 // Exit communication on Text like RING, CONNECT, ... or 0xFF command | |
555 if((type < 0x60) || (type == 0xFF)) | |
556 return 0; | |
557 | |
558 // return of command for (almost) all commands | |
559 switch(type) | |
560 { | |
561 // not supported yet case 0x20: // send hi:lo:temp1 bytes starting from ext_flash_address:3 | |
562 // not supported yet case 0x22: // Resets all logbook pointers and the logbook (!) | |
563 // not supported yet case 0x23: // Resets battery gauge registers | |
564 // not supported yet case 0x30: // write bytes starting from ext_flash_address:3 (Stop when timeout) | |
565 // not supported yet case 0x40: // erases 4kB block from ext_flash_address:3 (Warning: No confirmation or built-in security here...) | |
566 // not supported yet case 0x42: // erases range in 4kB steps (Get 3 bytes address and 1byte amount of 4kB blocks) | |
567 // not supported yet case 0x50: // sends firmware from external flash from 0x3E0000 to 0x3FD000 (118784bytes) via comm | |
568 case 0xFE: // hw unit_tests | |
569 case 0x71: // hw read manufacturing data | |
570 case 0x73: // hw update FLEX | |
571 case 0x79: // hw read device data | |
572 #ifdef BOOTLOADER_STANDALONE | |
573 case 0x74: // hw update Firmware | |
574 case 0x75: // hw update RTE | |
575 case 0x76: // hw update Fonts | |
576 case 0x80: // hw write manufacturing data | |
577 case 0x81: // hw write second serial | |
578 case 0x82: // hw set bluetooth name | |
579 #else | |
580 case 0x83: // hw copy logbook entry - read | |
581 case 0x84: // hw copy logbook entry - write | |
582 case 0x85: // hw read entire logbook memory | |
583 case 0x86: // hw overwrite entire logbook memory | |
584 case 0x87: // hw ext_flash_repair_SPECIAL_dive_numbers_starting_count_with memory(x) | |
585 | |
586 #endif | |
587 case 0xC1: // Start low-level bootloader | |
588 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | |
589 return 0; | |
590 break; | |
591 default: | |
592 break; | |
593 } | |
594 | |
595 // now send content or update firmware | |
596 switch(type) | |
597 { | |
598 case 0xFE: | |
599 // work to do :-) 12. Oct. 2015 | |
600 // 256 bytes output | |
601 memset(aTxBuffer,0,128); | |
602 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
603 return 0; | |
604 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
605 return 0; | |
606 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
607 break; | |
608 | |
609 case 0x71: | |
610 memcpy(aTxBuffer,hardwareDataGetPointer(),64); | |
611 count += 64; | |
612 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
613 break; | |
614 | |
615 case 0x73: | |
616 #ifndef BOOTLOADER_STANDALONE | |
617 answer = receive_update_flex(1); | |
618 #else | |
619 answer = receive_update_flex(0); | |
620 #endif | |
621 if(answer == 0) | |
622 return 0; | |
623 else if(answer == 2) // 2 = RTE without bootToBootloader | |
624 { | |
625 aTxBuffer[0] = 0xFF; | |
626 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000); | |
627 return 0; | |
628 } | |
629 else | |
630 { | |
631 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
632 if(answer == 1) /* 0xFF is checksum error, 2 = RTE without bootToBootloader */ | |
633 { | |
634 extern uint8_t bootToBootloader; | |
635 bootToBootloader = 1; | |
636 } | |
637 } | |
638 break; | |
639 | |
640 case 0x79: | |
641 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
642 return 0; | |
643 ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(aTxBuffer); | |
644 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
645 return 0; | |
646 aTxBuffer[0] = prompt4D4C(receiveStartByteUart); | |
647 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
648 return 0; | |
649 else | |
650 return prompt4D4C(receiveStartByteUart); | |
651 | |
652 case 0x82: | |
653 #ifdef BOOTLOADER_STANDALONE | |
654 setForcedBluetoothName = 1; | |
655 return 0; | |
656 #else | |
657 settingsGetPointer()->debugModeOnStart = 1; | |
658 extern uint8_t bootToBootloader; | |
659 bootToBootloader = 1; | |
660 return prompt4D4C(receiveStartByteUart); | |
661 #endif | |
662 | |
663 #ifdef BOOTLOADER_STANDALONE | |
664 case 0x74: | |
665 answer = receive_update_data_mainCPU_firmware(); | |
666 if(answer != 0) | |
667 { | |
668 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
669 if(answer == 1) // 0xFF is checksum error | |
670 { | |
671 extern uint8_t bootToBootloader; | |
672 bootToBootloader = 1; | |
673 } | |
674 } | |
675 else | |
676 return 0; | |
677 break; | |
678 | |
679 case 0x75: | |
680 receive_update_data_cpu2(); | |
681 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
682 break; | |
683 | |
684 case 0x76: | |
685 answer = receive_update_data_mainCPU_variable_firmware(); | |
686 if(answer != 0) | |
687 { | |
688 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
689 if(answer == 1) // 0xFF is checksum error | |
690 { | |
691 extern uint8_t bootToBootloader; | |
692 bootToBootloader = 1; | |
693 } | |
694 } | |
695 else | |
696 return 0; | |
697 break; | |
698 | |
699 case 0x80: | |
700 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
701 return 0; | |
702 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
703 { | |
704 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
705 } | |
706 else | |
707 return 0; | |
708 break; | |
709 | |
710 case 0x81: | |
711 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 12, 1000)!= HAL_OK) | |
712 return 0; | |
713 if(hardware_programmSecondarySerial(aRxBuffer) == HAL_OK) | |
714 { | |
715 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
716 } | |
717 else | |
718 return 0; | |
719 break; | |
720 | |
721 #else | |
722 | |
723 #ifdef SPECIALPROGRAMM | |
724 case 0x80: | |
725 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
726 return 0; | |
727 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
728 { | |
729 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
730 } | |
731 else | |
732 return 0; | |
733 break; | |
734 #endif | |
735 case 0x83: | |
736 if(HAL_UART_Receive(&UartHandle, &logStepBackwards, 1, 1000)!= HAL_OK) | |
737 return 0; | |
738 logCopyDataPtr = getFrame(98); | |
739 logCopyDataPtrTemp = logCopyDataPtr; | |
740 logCopyDataLength.u32bit = ext_flash_read_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, 1000000,logStepBackwards); | |
741 answer = HAL_OK; | |
742 if(answer == HAL_OK) | |
743 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
744 if(answer == HAL_OK) | |
745 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
746 if(answer == HAL_OK) | |
747 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
748 if(answer == HAL_OK) | |
749 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
750 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
751 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
752 { | |
753 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
754 logCopyDataLengthTemp -= 0xFFFF; | |
755 logCopyDataPtrTemp += 0xFFFF; | |
756 } | |
757 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
758 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
759 releaseFrame(98,logCopyDataPtr); | |
760 if(answer == HAL_OK) | |
761 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
762 else | |
763 return 0; | |
764 break; | |
765 | |
766 case 0x84: | |
767 logCopyDataPtr = getFrame(98); | |
768 logCopyDataPtrTemp = logCopyDataPtr; | |
769 answer = HAL_OK; | |
770 if(answer == HAL_OK) | |
771 answer = HAL_UART_Receive(&UartHandle, &logDummyByte, 1,2000); | |
772 if(answer == HAL_OK) | |
773 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
774 if(answer == HAL_OK) | |
775 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
776 if(answer == HAL_OK) | |
777 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
778 if(answer == HAL_OK) | |
779 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
780 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
781 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
782 { | |
783 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
784 logCopyDataLengthTemp -= 0xFFFF; | |
785 logCopyDataPtrTemp += 0xFFFF; | |
786 } | |
787 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
788 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
789 if(answer == HAL_OK) | |
790 ext_flash_write_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, logCopyDataLength.u32bit); | |
791 releaseFrame(98,logCopyDataPtr); | |
792 if(answer == HAL_OK) | |
793 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
794 else | |
795 return 0; | |
796 break; | |
797 | |
798 case 0x85: | |
799 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
800 logCopyDataPtr = getFrame(98); | |
801 ext_flash_read_header_memory((uint8_t *)logCopyDataPtr); | |
802 for(int i=0;i<8;i++) | |
803 HAL_UART_Transmit(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); | |
804 releaseFrame(98,logCopyDataPtr); | |
805 break; | |
806 | |
807 case 0x86: | |
808 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
809 logCopyDataPtr = getFrame(98); | |
810 for(int i=0;i<8;i++) | |
811 HAL_UART_Receive(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); | |
812 ext_flash_write_header_memory((uint8_t *)logCopyDataPtr); | |
813 releaseFrame(98,logCopyDataPtr); | |
814 break; | |
815 | |
816 case 0x87: | |
817 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 4, 1000)!= HAL_OK) | |
818 return 0; | |
819 if(((aRxBuffer[0] ^ aRxBuffer[2]) != 0xFF) || ((aRxBuffer[1] ^ aRxBuffer[3]) != 0xFF)) | |
820 return 0; | |
821 totalDiveCount.u8bit.byteLow = aRxBuffer[1]; | |
822 totalDiveCount.u8bit.byteHigh = aRxBuffer[0]; | |
823 ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(totalDiveCount.u16bit); | |
824 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
825 break; | |
826 #endif | |
827 } | |
828 | |
829 // was service command? Yes, finish and exit | |
830 if(count) | |
831 { | |
832 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
833 return 0; | |
834 else | |
835 return prompt4D4C(receiveStartByteUart); | |
836 } | |
837 } | |
838 | |
839 | |
840 // download mode commands | |
841 switch(type) | |
842 { | |
843 // return of command for almost all commands | |
844 case 0x60: // get model + features | |
845 case 0x61: // get all headers full (256 bytes) | |
846 case 0x62: // set clock | |
847 case 0x63: // set custom text | |
848 case 0x66: // get dive profile | |
849 case 0x69: // get serial, old version numbering, custom text | |
850 case 0x6A: // get model | |
851 case 0x6B: // get specific firmware version | |
852 case 0x6D: // get all compact headers (16 byte) | |
853 case 0x6E: // display text | |
854 case 0x70: // read min, default, max setting | |
855 case 0x72: // read setting | |
856 case 0x77: // write setting | |
857 case 0x78: // reset all settings | |
858 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | |
859 return 0; | |
860 break; | |
861 | |
862 // start communication (again) | |
863 case 0xBB: | |
864 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
865 return 0; | |
866 else | |
867 return prompt4D4C(receiveStartByteUart); | |
868 | |
869 // stop communication | |
870 case 0xFF: | |
871 HAL_UART_Transmit(&UartHandle, (uint8_t*)&aTxBuffer, 1, 1000); | |
872 return 0; | |
873 | |
874 default: | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
875 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); |
38 | 876 break; |
877 } | |
878 | |
879 switch(type) | |
880 { | |
881 case 0x62: | |
882 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 6, 2000)!= HAL_OK) | |
883 return 0; | |
884 break; | |
885 case 0x63: | |
886 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 60, 5000)!= HAL_OK) | |
887 return 0; | |
888 break; | |
889 case 0x66: | |
890 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
891 return 0; | |
892 break; | |
893 case 0x6B: | |
894 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
895 return 0; | |
896 break; | |
897 case 0x6E: | |
898 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 16, 5000)!= HAL_OK) | |
899 return 0; | |
900 break; | |
901 case 0x77: | |
902 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5, 5000)!= HAL_OK) | |
903 return 0; | |
904 break; | |
905 case 0x72: | |
906 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
907 return 0; | |
908 break; | |
909 case 0x70: | |
910 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
911 return 0; | |
912 break; | |
913 } | |
914 | |
915 switch(type) | |
916 { | |
917 /* common to standard and bootloader */ | |
918 | |
919 // get model + features | |
920 case 0x60: | |
921 aTxBuffer[count++] = 0x00; // hardware descriptor HIGH byte | |
922 aTxBuffer[count++] = 0x3B; // hardware descriptor LOW byte // 0x3B is OSTC4 // 0x1A is OTSC3 | |
923 aTxBuffer[count++] = 0x00; // feature descriptor HIGH byte | |
138 | 924 aTxBuffer[count++] = 0x00; // feature descriptor LOW byte |
38 | 925 aTxBuffer[count++] = 0x43; // model id |
926 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
927 break; | |
928 | |
929 // get model | |
930 case 0x6A: | |
931 aTxBuffer[count++] = 0x3B; // 0x3B is OSTC4 // 0x1A is OTSC3 | |
932 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
933 break; | |
934 | |
935 // get all firmware version and status (OSTC4 only) | |
936 case 0x6B: | |
937 switch(*aRxBuffer) | |
938 { | |
939 case 0xFF: | |
940 // firmware | |
941 aTxBuffer[count++] = firmwareDataGetPointer()->versionFirst; | |
942 aTxBuffer[count++] = firmwareDataGetPointer()->versionSecond; | |
943 aTxBuffer[count++] = firmwareDataGetPointer()->versionThird; | |
944 aTxBuffer[count++] = firmwareDataGetPointer()->versionBeta; | |
945 break; | |
946 case 0xFE: | |
947 // RTE | |
948 getActualRTEandFONTversion(&tempHigh, &tempLow, 0, 0); // RTE | |
949 aTxBuffer[count++] = tempHigh; | |
950 aTxBuffer[count++] = tempLow; | |
951 aTxBuffer[count++] = 0; | |
952 aTxBuffer[count++] = 0; | |
953 break; | |
954 case 0x10: | |
955 getActualRTEandFONTversion( 0, 0, &tempHigh, &tempLow); // font | |
956 aTxBuffer[count++] = tempHigh; | |
957 aTxBuffer[count++] = tempLow; | |
958 aTxBuffer[count++] = 0; | |
959 aTxBuffer[count++] = 0; | |
960 break; | |
961 default: | |
962 // not supported | |
963 aTxBuffer[count++] = 0xFF; | |
964 aTxBuffer[count++] = 0xFF; | |
965 aTxBuffer[count++] = 0xFF; | |
966 aTxBuffer[count++] = 0xFF; | |
967 break; | |
968 /* Jef Driesen Test | |
969 default: | |
970 // not supported | |
971 aTxBuffer[count++] = 0x1; | |
972 aTxBuffer[count++] = 0x1; | |
973 aTxBuffer[count++] = 0x1; | |
974 aTxBuffer[count++] = 0x1; | |
975 break; | |
976 */ | |
977 } | |
978 /* | |
979 // serial | |
980 aTxBuffer[count++] = pSettings->serialLow; | |
981 aTxBuffer[count++] = pSettings->serialHigh; | |
982 // batch code (date) | |
983 hardwareBatchCode(&tempHigh, &tempLow); | |
984 aTxBuffer[count++] = tempLow; | |
985 aTxBuffer[count++] = tempHigh; | |
986 // status and status detail (future feature) | |
987 aTxBuffer[count++] = 0; | |
988 aTxBuffer[count++] = 0; | |
989 aTxBuffer[count++] = 0; | |
990 aTxBuffer[count++] = 0; | |
991 */ | |
992 // prompt | |
993 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
994 break; | |
995 | |
996 // display text | |
997 case 0x6E: | |
998 for(int i=0;i<16;i++) | |
999 display_text[i] = aRxBuffer[i]; | |
1000 display_text[15] = 0; | |
1001 display_text[255] = 16; | |
1002 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1003 break; | |
1004 | |
1005 // version / identify | |
1006 case 0x69: | |
1007 #ifndef BOOTLOADER_STANDALONE | |
1008 aTxBuffer[count++] = pSettings->serialLow; | |
1009 aTxBuffer[count++] = pSettings->serialHigh; | |
1010 aTxBuffer[count++] = firmwareVersion_16bit_low(); | |
1011 aTxBuffer[count++] = firmwareVersion_16bit_high(); | |
1012 memcpy(&aTxBuffer[count], pSettings->customtext, 60); | |
1013 #else | |
1014 aTxBuffer[count++] = 0;//pSettings->serialLow; | |
1015 aTxBuffer[count++] = 0;//pSettings->serialHigh; | |
1016 aTxBuffer[count++] = 0;//firmwareVersion_16bit_low(); | |
1017 aTxBuffer[count++] = 0;//firmwareVersion_16bit_high(); | |
1018 memset(&aTxBuffer[count], 0, 60); | |
1019 #endif | |
1020 count += 60; | |
1021 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1022 break; | |
1023 | |
1024 #ifndef BOOTLOADER_STANDALONE | |
1025 //Reset all setting | |
1026 case 0x78: | |
1027 set_settings_to_Standard(); | |
1028 updateSettingsAndMenuOnExit = 1; | |
1029 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1030 break; | |
1031 #endif | |
1032 | |
1033 #ifndef BOOTLOADER_STANDALONE | |
1034 // full headers (256 byte) | |
1035 case 0x61: | |
1036 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1037 { | |
1038 logbook_getHeader(StepBackwards, &logbookHeader); | |
1039 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1040 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1041 return 0; | |
1042 } | |
1043 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1044 break; | |
1045 | |
1046 // compact headers (16 byte) | |
1047 case 0x6D: | |
1048 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1049 { | |
1050 logbook_getHeader(StepBackwards, &logbookHeader); | |
1051 plogbookHeaderOSTC3compact = logbook_build_ostc3header_compact(&logbookHeader); | |
1052 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3compact, 16,5000)!= HAL_OK) | |
1053 return 0; | |
1054 } | |
1055 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1056 break; | |
1057 | |
1058 // set clock & date | |
1059 case 0x62: | |
1060 // ToDo | |
1061 stimestructure.Hours = aRxBuffer[0]; | |
1062 stimestructure.Minutes = aRxBuffer[1]; | |
1063 stimestructure.Seconds = aRxBuffer[2]; | |
1064 sdatestructure.Month = aRxBuffer[3]; | |
1065 sdatestructure.Date = aRxBuffer[4]; | |
1066 sdatestructure.Year = aRxBuffer[5]; // This parameter must be a number between Min_Data = 0 and Max_Data = 99 | |
1067 setWeekday(&sdatestructure); | |
1068 | |
1069 if( ( stimestructure.Hours < 24 ) | |
1070 &&( stimestructure.Minutes < 60 ) | |
1071 &&( stimestructure.Seconds < 60 ) | |
1072 &&( sdatestructure.Month < 13 ) | |
1073 &&( sdatestructure.Date < 32 ) | |
1074 &&( sdatestructure.Year < 100 )) | |
1075 { | |
1076 setTime(stimestructure); | |
1077 setDate(sdatestructure); | |
1078 set_globalState(StUART_RTECONNECT); | |
1079 HAL_Delay(1); | |
1080 set_globalState(StUART_STANDARD); | |
1081 } | |
1082 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1083 break; | |
1084 | |
1085 case 0x63: | |
1086 for(int i=0;i<60;i++) | |
1087 pSettings->customtext[i] = aRxBuffer[i]; | |
1088 pSettings->customtext[59] = 0; | |
1089 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1090 break; | |
1091 | |
1092 // get dive profile | |
1093 case 0x66: | |
1094 logbook_getHeader(255 - aRxBuffer[0], &logbookHeader); | |
1095 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1096 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1097 return 0; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1098 ext_flash_open_read_sample(255 - aRxBuffer[0], &sampleTotalLength); |
38 | 1099 while(sampleTotalLength >= 128) |
1100 { | |
1101 ext_flash_read_next_sample_part(aTxBuffer,128); | |
1102 sampleTotalLength -= 128; | |
1103 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
1104 return 0; | |
1105 } | |
1106 if(sampleTotalLength) | |
1107 { | |
1108 ext_flash_read_next_sample_part(aTxBuffer,sampleTotalLength); | |
1109 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, sampleTotalLength,5000)!= HAL_OK) | |
1110 return 0; | |
1111 } | |
1112 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1113 break; | |
1114 | |
1115 // read min,default,max setting | |
1116 case 0x70: | |
1117 count += readDataLimits__8and16BitValues_4and7BytesOutput(aRxBuffer[0],&aTxBuffer[count]); | |
1118 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1119 break; | |
1120 | |
1121 // read setting | |
1122 case 0x72: | |
1123 readData(aRxBuffer[0],&aTxBuffer[count]); | |
1124 count += 4; | |
1125 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1126 break; | |
1127 | |
1128 // write setting | |
1129 case 0x77: | |
1130 writeData(aRxBuffer); | |
1131 updateSettingsAndMenuOnExit = 1; | |
1132 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1133 break; | |
1134 #else | |
1135 /* bootloader dummies */ | |
1136 // full headers (256 byte) | |
1137 case 0x61: | |
1138 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1139 { | |
1140 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1141 return 0; | |
1142 } | |
1143 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1144 break; | |
1145 // compact headers (16 byte) | |
1146 case 0x6D: | |
1147 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1148 { | |
1149 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 16,5000)!= HAL_OK) | |
1150 return 0; | |
1151 } | |
1152 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1153 break; | |
1154 // set clock & date | |
1155 case 0x62: | |
1156 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1157 break; | |
1158 // set custom text | |
1159 case 0x63: | |
1160 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1161 break; | |
1162 // get dive profile | |
1163 case 0x66: | |
1164 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1165 return 0; | |
1166 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1167 break; | |
1168 // read min,default,max setting | |
1169 // read settings | |
1170 | |
1171 | |
1172 case 0x72: | |
1173 memcpy(&aTxBuffer[count], dummyForBootloader, 4); | |
1174 count += 4; | |
1175 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1176 break; | |
1177 // write settings | |
1178 case 0x77: | |
1179 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1180 break; | |
1181 #endif | |
1182 } | |
1183 | |
1184 if(count) | |
1185 { | |
1186 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
1187 return 0; | |
1188 else | |
1189 return prompt4D4C(receiveStartByteUart); | |
1190 } | |
1191 return 0; | |
1192 } | |
1193 | |
1194 | |
1195 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size) | |
1196 { | |
1197 uint16_t length_16_blocks; | |
1198 uint16_t length_16_remainder; | |
1199 uint32_t temp; | |
1200 HAL_StatusTypeDef result = HAL_OK; | |
1201 uint32_t pDataLocal; | |
1202 | |
1203 length_16_blocks = (uint16_t) (Size / 0xFFFF); | |
1204 temp = length_16_blocks; | |
1205 temp *= 0xFFFF; | |
1206 length_16_remainder = (uint16_t) ( Size - temp); | |
1207 | |
1208 pDataLocal = (uint32_t)pData; | |
1209 | |
1210 while((result == HAL_OK) && length_16_blocks) | |
1211 { | |
1212 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, 0xFFFF , 60000); | |
1213 pDataLocal += 0xFFFF; | |
1214 length_16_blocks--; | |
1215 } | |
1216 if((result == HAL_OK) && length_16_remainder) | |
1217 { | |
1218 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, length_16_remainder , 60000); | |
1219 } | |
1220 return result; | |
1221 } | |
1222 | |
1223 | |
1224 /* for safety reason (memory blocking this code is main and sub */ | |
1225 | |
1226 #ifdef BOOTLOADER_STANDALONE | |
1227 | |
1228 uint8_t receive_update_data_cpu2(void) | |
1229 { | |
1230 uint8_t answer; | |
1231 | |
1232 uint8_t* pBuffer = (uint8_t*)getFrame(20); | |
1233 answer = receive_update_data_cpu2_sub(pBuffer); | |
1234 releaseFrame(20,(uint32_t)pBuffer); | |
1235 return answer; | |
1236 } | |
1237 | |
1238 | |
1239 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer) | |
1240 { | |
1241 uint8_t sBuffer[10]; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1242 uint32_t length, offsetTotal, checksum, checksumCalc; |
38 | 1243 uint8_t id; |
1244 const uint8_t id_RTE = 0xFE; | |
1245 | |
1246 //Get length | |
1247 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1248 { | |
1249 return 0; | |
1250 } | |
1251 length = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1252 | |
1253 //Get id | |
1254 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1255 { | |
1256 return 0; | |
1257 } | |
1258 id = pBuffer[0]; | |
1259 offsetTotal = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1260 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1261 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1262 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1263 { | |
1264 return 0; | |
1265 } | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1266 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1267 checksumCalc = length + offsetTotal; |
38 | 1268 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1269 // no need to get code if checksum == length is wrong |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1270 if(checksumCalc != checksum) |
38 | 1271 { |
1272 return 0; | |
1273 } | |
1274 | |
1275 //get Code | |
1276 if(receive_uart_large_size(&UartHandle, pBuffer, length)!= HAL_OK) | |
1277 { | |
1278 return 0; | |
1279 } | |
1280 | |
1281 //get Checksum | |
1282 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 | |
1283 { | |
1284 return 0; | |
1285 } | |
1286 uint32_t checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1287 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); | |
1288 uint32_t checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); | |
1289 | |
1290 if(checksum != checksumCalc) | |
1291 { | |
1292 return 0; | |
1293 } | |
1294 | |
1295 if(id != id_RTE) | |
1296 { | |
1297 strcpy(display_text,"wrong data."); | |
1298 display_text[255] = 32; | |
1299 return 0; | |
1300 } | |
1301 | |
1302 strcpy(display_text," RTE update."); | |
1303 display_text[255] = 32; | |
1304 | |
1305 return extCPU2bootloader(pBuffer,length,display_text); | |
1306 } | |
1307 #endif // BOOTLOADER_STANDALONE | |
1308 | |
1309 | |
1310 | |
1311 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED) | |
1312 { | |
1313 uint8_t answer; | |
1314 | |
1315 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1316 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1317 | |
1318 answer = receive_update_data_flex(pBuffer1, pBuffer2, isRTEupdateALLOWED); | |
1319 | |
1320 releaseFrame(20,(uint32_t)pBuffer1); | |
1321 releaseFrame(20,(uint32_t)pBuffer2); | |
1322 | |
1323 return answer; | |
1324 } | |
1325 | |
1326 uint8_t receive_update_data_mainCPU_firmware(void) | |
1327 { | |
1328 uint8_t answer; | |
1329 | |
1330 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1331 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1332 answer = receive_update_data_mainCPU_firmware_subroutine(1, pBuffer1, 0); |
38 | 1333 |
1334 releaseFrame(20,(uint32_t)pBuffer1); | |
1335 | |
1336 return answer; | |
1337 } | |
1338 | |
1339 /* multi buffer (long data) not tested yet */ | |
1340 uint8_t receive_update_data_mainCPU_variable_firmware(void) | |
1341 { | |
1342 uint8_t answer; | |
1343 | |
1344 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1345 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1346 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1347 answer = receive_update_data_mainCPU_firmware_subroutine(2, pBuffer1, pBuffer2); |
38 | 1348 |
1349 releaseFrame(20,(uint32_t)pBuffer1); | |
1350 releaseFrame(20,(uint32_t)pBuffer2); | |
1351 | |
1352 return answer; | |
1353 } | |
1354 | |
1355 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED) | |
1356 { | |
1357 uint8_t sBuffer[10]; | |
1358 uint8_t serialBuffer[10]; | |
1359 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1360 uint32_t lengthTotal, offsetTotal; |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1361 uint32_t checksum, checksumCalc = 0; |
38 | 1362 uint8_t id; |
1363 const uint8_t id_Region1_firmware = 0xFF; | |
1364 const uint8_t id_RTE = 0xFE; | |
1365 uint8_t textpointer = 0; | |
1366 | |
1367 //Get length | |
1368 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1369 { | |
1370 return 0; | |
1371 } | |
1372 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1373 | |
1374 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1375 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1376 { | |
1377 return 0; | |
1378 } | |
1379 id = sBuffer[0]; | |
1380 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1381 checksumCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1382 checksumCalc += lengthTotal; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1383 //old, does no longer work because of the fonts: checksumCalc = lengthTotal + offsetTotal; |
38 | 1384 |
1385 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1386 { | |
1387 return 0; | |
1388 } | |
1389 | |
1390 // neu 110212 | |
1391 if(id == id_FONT) | |
1392 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1393 else | |
1394 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1395 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1396 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1397 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1398 { | |
1399 return 0; | |
1400 } | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1401 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
38 | 1402 |
1403 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1404 if(checksumCalc != checksum) |
38 | 1405 { |
1406 uint8_t ptr = 0; | |
1407 strcpy(&display_text[ptr]," checksum error"); | |
1408 ptr += 15; | |
1409 strcpy(&display_text[ptr],"\n\r"); | |
1410 ptr += 2; | |
1411 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1412 display_text[ptr] = 0; | |
1413 display_text[255] = ptr + 1; | |
1414 return 0xFF; | |
1415 } | |
1416 | |
1417 //Get serial (new since 160211) | |
1418 if(HAL_UART_Receive(&UartHandle, serialBuffer, 4,5000)!= HAL_OK) | |
1419 { | |
1420 return 0; | |
1421 } | |
1422 | |
1423 if(lengthTotal > 768000) | |
1424 { | |
1425 length1 = 768000; | |
1426 length2 = lengthTotal - length1; | |
1427 } | |
1428 else | |
1429 { | |
1430 length1 = lengthTotal; | |
1431 length2 = 0; | |
1432 } | |
1433 | |
1434 if((pBuffer2 == 0) && (length2 != 0)) | |
1435 return 0; | |
1436 | |
1437 //get Code | |
1438 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1439 return 0; | |
1440 | |
1441 if(length2) | |
1442 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1443 return 0; | |
1444 | |
1445 //get Checksum | |
1446 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1447 return 0; | |
1448 | |
1449 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1450 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1451 if(length2) | |
1452 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1453 else | |
1454 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1455 | |
1456 /* check id now */ | |
1457 /* | |
1458 if(region == 2) | |
1459 { | |
1460 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1461 { | |
1462 strcpy(display_text,"wrong data."); | |
1463 display_text[255] = 32; | |
1464 return 0; | |
1465 } | |
1466 } | |
1467 else | |
1468 { | |
1469 if(id != id_Region1_firmware) | |
1470 { | |
1471 strcpy(display_text,"wrong data."); | |
1472 display_text[255] = 32; | |
1473 return 0; | |
1474 } | |
1475 } | |
1476 */ | |
1477 /* test checksum */ | |
1478 if(checksum != checksumCalc) | |
1479 { | |
1480 uint8_t ptr = 0; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1481 strcpy(&display_text[ptr]," checksum error"); |
38 | 1482 ptr += 15; |
1483 strcpy(&display_text[ptr],"\n\r"); | |
1484 display_text[ptr] = 0; | |
1485 display_text[255] = ptr + 1; | |
1486 return 0xFF; | |
1487 } | |
1488 | |
1489 if(id == id_Region1_firmware) | |
1490 { | |
1491 uint8_t ptr = 0; | |
1492 display_text[ptr++] = 'V'; | |
1493 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1494 display_text[ptr++] = '.'; | |
1495 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1496 display_text[ptr++] = '.'; | |
1497 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1498 display_text[ptr++] = ' '; | |
1499 if(pBuffer1[0x10003]) | |
1500 { | |
1501 strcpy(&display_text[ptr],"beta "); | |
1502 ptr +=5; | |
1503 } | |
1504 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1505 ptr += 25; |
38 | 1506 display_text[255] = ptr + 1; |
1507 } | |
1508 else if(id == id_RTE) | |
1509 { | |
1510 if(RTEupdateALLOWED) | |
1511 { | |
1512 strcpy(display_text," RTE update.\n\r"); | |
1513 textpointer = 0; | |
1514 while((display_text[textpointer] != 0) && (textpointer < 50)) | |
1515 textpointer++; | |
1516 #ifndef BOOTLOADER_STANDALONE | |
1517 if(textpointer < 50) | |
1518 { | |
1519 // display_text[textpointer++] = | |
1520 display_text[textpointer++] = '\025'; | |
1521 display_text[textpointer++] = TXT_2BYTE; | |
1522 display_text[textpointer++] = TXT2BYTE_DecoDataLost; | |
1523 display_text[textpointer] = 0; | |
1524 } | |
1525 #endif | |
1526 display_text[255] = textpointer+1; | |
1527 return extCPU2bootloader(pBuffer1,length1,display_text); | |
1528 } | |
1529 else | |
1530 return 0xFF; | |
1531 } | |
1532 else | |
1533 //if(region == 2) | |
1534 { | |
1535 uint8_t ptr = 0; | |
1536 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1537 strcpy(&display_text[ptr]," bytes with "); | |
1538 ptr += 12; | |
1539 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1540 strcpy(&display_text[ptr]," offset"); | |
1541 ptr += 7; | |
1542 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1543 ptr += 25; |
38 | 1544 display_text[255] = ptr + 1; |
1545 } | |
1546 | |
1547 | |
1548 // only non RTE !! | |
1549 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1550 ByteCompareStatus = 0; | |
1551 | |
1552 if(id == id_Region1_firmware) | |
1553 { | |
1554 /* standard firmware limited to 768000 */ | |
1555 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1556 ext_flash_erase_firmware(); | |
1557 ext_flash_write_firmware(pBuffer1, length1); | |
1558 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1559 | |
1560 if(lengthCompare != length1) | |
1561 ByteCompareStatus = 10000; | |
1562 for(int i = 0; i < length1; i++) | |
1563 { | |
1564 if(pBuffer1[0] != pBufferCompare[0]) | |
1565 ByteCompareStatus++; | |
1566 } | |
1567 } | |
1568 else | |
1569 //if(region == 2) | |
1570 { | |
1571 /* upper region firmware can be larger (1MB) */ | |
1572 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1573 ext_flash_erase_firmware2(); | |
1574 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1575 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1576 | |
1577 if(lengthCompare != length1 + length2) | |
1578 ByteCompareStatus = 10000; | |
1579 if(offsetTotal != offsetCompare) | |
1580 ByteCompareStatus += 20000; | |
1581 for(int i = 0; i < length1; i++) | |
1582 { | |
1583 if(pBuffer1[0] != pBufferCompare[0]) | |
1584 ByteCompareStatus++; | |
1585 } | |
1586 | |
1587 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1588 for(int i = 0; i < length2; i++) | |
1589 { | |
1590 if(pBuffer2[0] != pBufferCompare[0]) | |
1591 ByteCompareStatus++; | |
1592 } | |
1593 } | |
1594 | |
1595 releaseFrame(20,(uint32_t)pBufferCompare); | |
1596 | |
1597 if(ByteCompareStatus != 0) | |
1598 { | |
1599 strcpy(&display_text[0],"\n\rcopy error."); | |
1600 display_text[255] = 21; | |
1601 return 0; | |
1602 } | |
1603 else | |
1604 { | |
1605 strcpy(&display_text[0],"\n\rready to install."); | |
1606 display_text[255] = 21; | |
1607 return 1; | |
1608 } | |
1609 } | |
1610 | |
1611 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1612 uint8_t receive_update_data_mainCPU_firmware_subroutine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2) |
38 | 1613 { |
1614 uint8_t sBuffer[10]; | |
1615 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1616 uint32_t lengthTotal, offsetTotal, checksum, checksumCalc = 0; |
38 | 1617 uint8_t id; |
1618 | |
1619 //Get length | |
1620 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1621 return 0; | |
1622 | |
1623 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1624 | |
1625 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1626 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1627 return 0; | |
1628 | |
1629 id = sBuffer[0]; | |
1630 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1631 checksumCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; |
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1632 checksumCalc += lengthTotal; |
38 | 1633 |
1634 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1635 return 0; | |
1636 | |
1637 if(id == id_FONT) | |
1638 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1639 // alt, prior to id for font | |
1640 else | |
1641 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1642 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1643 // get checksum, bytes are in different order on Dev C++ code!!! |
38 | 1644 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 |
1645 return 0; | |
1646 | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1647 checksum = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; |
38 | 1648 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1649 //old: checksumCalc = lengthTotal + offsetTotal; |
38 | 1650 |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1651 if(checksumCalc != checksum) |
38 | 1652 { |
1653 uint8_t ptr = 0; | |
1654 strcpy(&display_text[ptr]," checksum error"); | |
1655 ptr += 15; | |
1656 strcpy(&display_text[ptr],"\n\r"); | |
1657 ptr += 2; | |
1658 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1659 display_text[ptr] = 0; | |
1660 display_text[255] = ptr + 1; | |
1661 return 0xFF; | |
1662 } | |
1663 | |
1664 if(lengthTotal > 768000) | |
1665 { | |
1666 length1 = 768000; | |
1667 length2 = lengthTotal - length1; | |
1668 } | |
1669 else | |
1670 { | |
1671 length1 = lengthTotal; | |
1672 length2 = 0; | |
1673 } | |
1674 | |
1675 if((pBuffer2 == 0) && (length2 != 0)) | |
1676 return 0; | |
1677 | |
1678 //get Code | |
1679 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1680 return 0; | |
1681 | |
1682 if(length2) | |
1683 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1684 return 0; | |
1685 | |
1686 //get Checksum | |
1687 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1688 return 0; | |
1689 | |
1690 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1691 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1692 if(length2) | |
1693 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1694 else | |
1695 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1696 | |
1697 /* check id now */ | |
1698 if(region == 2) | |
1699 { | |
1700 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1701 { | |
1702 strcpy(display_text,"wrong data."); | |
1703 display_text[255] = 32; | |
1704 return 0; | |
1705 } | |
1706 } | |
1707 else | |
1708 { | |
1709 if(id != id_Region1_firmware) | |
1710 { | |
1711 strcpy(display_text,"wrong data."); | |
1712 display_text[255] = 32; | |
1713 return 0; | |
1714 } | |
1715 } | |
1716 | |
1717 /* test checksum */ | |
1718 if(checksum != checksumCalc) | |
1719 { | |
1720 uint8_t ptr = 0; | |
1721 strcpy(&display_text[ptr]," pruefsummen error"); | |
1722 ptr += 15; | |
1723 strcpy(&display_text[ptr],"\n\r"); | |
1724 display_text[ptr] = 0; | |
1725 display_text[255] = ptr + 1; | |
1726 return 0xFF; | |
1727 } | |
1728 | |
1729 if(region == 2) | |
1730 { | |
1731 uint8_t ptr = 0; | |
1732 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1733 strcpy(&display_text[ptr]," bytes with "); | |
1734 ptr += 12; | |
1735 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1736 strcpy(&display_text[ptr]," offset"); | |
1737 ptr += 7; | |
1738 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1739 ptr += 25; |
38 | 1740 display_text[255] = ptr + 1; |
1741 | |
1742 } | |
1743 else | |
1744 { | |
1745 uint8_t ptr = 0; | |
1746 display_text[ptr++] = 'V'; | |
1747 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1748 display_text[ptr++] = '.'; | |
1749 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1750 display_text[ptr++] = '.'; | |
1751 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1752 display_text[ptr++] = ' '; | |
1753 if(pBuffer1[0x10003]) | |
1754 { | |
1755 strcpy(&display_text[ptr],"beta "); | |
1756 ptr +=5; | |
1757 } | |
1758 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
236
ad6ddc4aabcd
Minor: translating some comments and variable names into english, some cleanup in tComm.c
heinrichsweikamp
parents:
229
diff
changeset
|
1759 ptr += 25; |
38 | 1760 display_text[255] = ptr + 1; |
1761 } | |
1762 | |
1763 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1764 ByteCompareStatus = 0; | |
1765 | |
1766 if(region == 2) | |
1767 { | |
1768 /* upper region firmware can be larger (1MB) */ | |
1769 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1770 ext_flash_erase_firmware2(); | |
1771 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1772 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1773 | |
1774 if(lengthCompare != length1 + length2) | |
1775 ByteCompareStatus = 10000; | |
1776 if(offsetTotal != offsetCompare) | |
1777 ByteCompareStatus += 20000; | |
1778 for(int i = 0; i < length1; i++) | |
1779 { | |
1780 if(pBuffer1[0] != pBufferCompare[0]) | |
1781 ByteCompareStatus++; | |
1782 } | |
1783 | |
1784 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1785 for(int i = 0; i < length2; i++) | |
1786 { | |
1787 if(pBuffer2[0] != pBufferCompare[0]) | |
1788 ByteCompareStatus++; | |
1789 } | |
1790 } | |
1791 else | |
1792 { | |
1793 /* standard firmware limited to 768000 */ | |
1794 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1795 ext_flash_erase_firmware(); | |
1796 ext_flash_write_firmware(pBuffer1, length1); | |
1797 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1798 | |
1799 if(lengthCompare != length1) | |
1800 ByteCompareStatus = 10000; | |
1801 for(int i = 0; i < length1; i++) | |
1802 { | |
1803 if(pBuffer1[0] != pBufferCompare[0]) | |
1804 ByteCompareStatus++; | |
1805 } | |
1806 } | |
1807 | |
1808 releaseFrame(20,(uint32_t)pBufferCompare); | |
1809 | |
1810 if(ByteCompareStatus != 0) | |
1811 { | |
1812 strcpy(&display_text[0],"\n\rcopy error."); | |
1813 display_text[255] = 21; | |
1814 return 0; | |
1815 } | |
1816 else | |
1817 { | |
1818 strcpy(&display_text[0],"\n\rready to install."); | |
1819 display_text[255] = 21; | |
1820 return 1; | |
1821 } | |
1822 } | |
1823 | |
1824 static void tComm_Error_Handler(void) | |
1825 { | |
1826 while(1) | |
1827 {} | |
1828 } |