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