Mercurial > public > ostc4
annotate Discovery/Src/tComm.c @ 98:01169b86f9c6 kittz
+2ms delay
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Mon, 26 Nov 2018 13:58:51 +0300 |
parents | 8f8ea3a32e82 |
children | b7689d9e888a |
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; | |
100 char display_text[256] = { 0 }; | |
101 | |
102 uint8_t setForcedBluetoothName = 0; | |
103 | |
104 uint8_t updateSettingsAndMenuOnExit = 0; | |
105 | |
106 /* Private types -------------------------------------------------------------*/ | |
107 #define BYTE_DOWNLOAD_MODE (0xBB) | |
108 #define BYTE_SERVICE_MODE (0xAA) | |
109 | |
110 const uint8_t id_Region1_firmware = 0xFF; | |
111 const uint8_t id_RTE = 0xFE; | |
112 const uint8_t id_FONT = 0x10; | |
113 const uint8_t id_FONT_OLD = 0x00; | |
114 | |
115 /* Private function prototypes -----------------------------------------------*/ | |
116 | |
117 static void tComm_Error_Handler(void); | |
118 static uint8_t select_mode(uint8_t aRxByte); | |
119 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED); | |
120 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED); | |
121 uint8_t receive_update_data_mainCPU_firmware(void); | |
122 uint8_t receive_update_data_mainCPU_variable_firmware(void); | |
123 uint8_t receive_update_data_mainCPU_firmware_subrotuine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2); | |
124 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size); | |
125 static uint8_t openComm(uint8_t aRxByte); | |
126 uint8_t tComm_Set_Bluetooth_Name_sub(uint16_t serial); | |
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); | |
222 GFX_SetFramesTopBottom(tCscreen.FBStartAdress, NULL,480); | |
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 //char aTxBufferName[50] = "AT+BNAME=BONEX-HW%4a\r"; | |
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 { | |
404 uint8_t answer = 0; | |
405 uint8_t service_mode_last_three_bytes[3]; | |
406 uint8_t service_mode_response[5] = | |
407 { | |
408 0x4B, | |
409 0xAB, | |
410 0xCD, | |
411 0xEF, | |
412 0x4C | |
413 }; | |
414 uint8_t download_mode_response[2] = | |
415 { | |
416 0xBB, | |
417 0x4D | |
418 }; | |
419 | |
420 if((aRxByte != BYTE_DOWNLOAD_MODE) && (aRxByte != BYTE_SERVICE_MODE)) | |
421 return 0; | |
422 | |
423 set_globalState(StUART_STANDARD); | |
424 | |
425 /* service mode is four bytes | |
426 0xAA 0xAB 0xCD 0xEF | |
427 answer is | |
428 */ | |
429 | |
430 if(aRxByte == BYTE_SERVICE_MODE) | |
431 { | |
432 if((HAL_UART_Receive(&UartHandle, (uint8_t*)service_mode_last_three_bytes, 3, 2000)!= HAL_OK)) | |
433 answer = 0x00; | |
434 else | |
435 { | |
436 if((service_mode_last_three_bytes[0] != 0xAB) || (service_mode_last_three_bytes[1] != 0xCD) || (service_mode_last_three_bytes[2] != 0xEF)) | |
437 answer = 0x00; | |
438 else | |
439 { | |
440 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)service_mode_response, 5, 2000)!= HAL_OK) | |
441 answer = 0x00; | |
442 else | |
443 answer = prompt4D4C(receiveStartByteUart); | |
444 } | |
445 } | |
446 } | |
447 else //if(aRxByte == BYTE_SERVICE_MODE) | |
448 { | |
449 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)download_mode_response, 2, 2000)!= HAL_OK) | |
450 answer = 0x00; | |
451 else | |
452 answer = prompt4D4C(receiveStartByteUart); | |
453 } | |
454 /* | |
455 uint8_t debug[256] = {0}; | |
456 uint8_t dbgptr = 0; | |
457 debug[dbgptr++] = aRxByte; | |
458 */ | |
459 while((answer == prompt4D4C(receiveStartByteUart)) && (HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 120000)== HAL_OK)) | |
460 { | |
461 // debug[dbgptr++] = aRxByte; | |
462 answer = select_mode(aRxByte); | |
463 } | |
464 set_returnFromComm(); | |
465 return 1; | |
466 } | |
467 | |
468 | |
469 uint8_t prompt4D4C(uint8_t mode) | |
470 { | |
471 if(mode == BYTE_SERVICE_MODE) | |
472 return 0x4C; | |
473 else | |
474 return 0x4D; | |
475 } | |
476 | |
477 | |
478 uint8_t select_mode(uint8_t type) | |
479 { | |
480 #ifndef BOOTLOADER_STANDALONE | |
481 SLogbookHeader logbookHeader; | |
482 SLogbookHeaderOSTC3 * plogbookHeaderOSTC3; | |
483 SLogbookHeaderOSTC3compact * plogbookHeaderOSTC3compact; | |
484 uint32_t sampleTotalLength; | |
485 SSettings* pSettings = settingsGetPointer(); | |
486 RTC_DateTypeDef sdatestructure; | |
487 RTC_TimeTypeDef stimestructure; | |
488 #else | |
489 uint8_t dummyForBootloader[256] = {0}; | |
490 #endif | |
491 | |
492 uint8_t count; | |
493 uint8_t aTxBuffer[128]; | |
494 uint8_t aRxBuffer[68]; | |
495 uint8_t answer; | |
496 aTxBuffer[0] = type; | |
497 aTxBuffer[1] = prompt4D4C(receiveStartByteUart); | |
498 uint8_t tempHigh, tempLow; | |
499 count = 0; | |
500 | |
501 // service mode only commands | |
502 if(receiveStartByteUart == BYTE_SERVICE_MODE) | |
503 { | |
504 // first part | |
505 switch(type) | |
506 { | |
507 // start communication (again) | |
508 case 0xAA: | |
509 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
510 return 0; | |
511 else | |
512 return prompt4D4C(receiveStartByteUart); | |
513 | |
514 /* | |
515 // update firmware main preparation | |
516 case 0x74: | |
517 ext_flash_erase_firmware_if_not_empty(); | |
518 break; | |
519 | |
520 // update firmware main with variable full access memory location preparation | |
521 case 0x76: | |
522 ext_flash_erase_firmware2_if_not_empty(); | |
523 break; | |
524 */ | |
525 default: | |
526 break; | |
527 } | |
528 | |
529 #ifndef BOOTLOADER_STANDALONE | |
530 uint32_t logCopyDataPtr = 0; | |
531 convert_Type logCopyDataLength; | |
532 uint32_t logCopyDataPtrTemp = 0; | |
533 uint32_t logCopyDataLengthTemp = 0; | |
534 uint8_t logDummyByte = 0; | |
535 uint8_t logStepBackwards = 0; | |
536 convert16_Type totalDiveCount; | |
537 logCopyDataLength.u32bit = 0; | |
538 totalDiveCount.u16bit = 0; | |
539 #endif | |
540 | |
541 // Exit communication on Text like RING, CONNECT, ... or 0xFF command | |
542 if((type < 0x60) || (type == 0xFF)) | |
543 return 0; | |
544 | |
545 // return of command for (almost) all commands | |
546 switch(type) | |
547 { | |
548 // not supported yet case 0x20: // send hi:lo:temp1 bytes starting from ext_flash_address:3 | |
549 // not supported yet case 0x22: // Resets all logbook pointers and the logbook (!) | |
550 // not supported yet case 0x23: // Resets battery gauge registers | |
551 // not supported yet case 0x30: // write bytes starting from ext_flash_address:3 (Stop when timeout) | |
552 // not supported yet case 0x40: // erases 4kB block from ext_flash_address:3 (Warning: No confirmation or built-in security here...) | |
553 // not supported yet case 0x42: // erases range in 4kB steps (Get 3 bytes address and 1byte amount of 4kB blocks) | |
554 // not supported yet case 0x50: // sends firmware from external flash from 0x3E0000 to 0x3FD000 (118784bytes) via comm | |
555 case 0xFE: // hw unit_tests | |
556 case 0x71: // hw read manufacturing data | |
557 case 0x73: // hw update FLEX | |
558 case 0x79: // hw read device data | |
559 #ifdef BOOTLOADER_STANDALONE | |
560 case 0x74: // hw update Firmware | |
561 case 0x75: // hw update RTE | |
562 case 0x76: // hw update Fonts | |
563 case 0x80: // hw write manufacturing data | |
564 case 0x81: // hw write second serial | |
565 case 0x82: // hw set bluetooth name | |
566 #else | |
567 case 0x83: // hw copy logbook entry - read | |
568 case 0x84: // hw copy logbook entry - write | |
569 case 0x85: // hw read entire logbook memory | |
570 case 0x86: // hw overwrite entire logbook memory | |
571 case 0x87: // hw ext_flash_repair_SPECIAL_dive_numbers_starting_count_with memory(x) | |
572 | |
573 #endif | |
574 case 0xC1: // Start low-level bootloader | |
575 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | |
576 return 0; | |
577 break; | |
578 default: | |
579 break; | |
580 } | |
581 | |
582 // now send content or update firmware | |
583 switch(type) | |
584 { | |
585 case 0xFE: | |
586 // work to do :-) 12. Oct. 2015 | |
587 // 256 bytes output | |
588 memset(aTxBuffer,0,128); | |
589 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
590 return 0; | |
591 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
592 return 0; | |
593 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
594 break; | |
595 | |
596 case 0x71: | |
597 memcpy(aTxBuffer,hardwareDataGetPointer(),64); | |
598 count += 64; | |
599 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
600 break; | |
601 | |
602 case 0x73: | |
603 #ifndef BOOTLOADER_STANDALONE | |
604 answer = receive_update_flex(1); | |
605 #else | |
606 answer = receive_update_flex(0); | |
607 #endif | |
608 if(answer == 0) | |
609 return 0; | |
610 else if(answer == 2) // 2 = RTE without bootToBootloader | |
611 { | |
612 aTxBuffer[0] = 0xFF; | |
613 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000); | |
614 return 0; | |
615 } | |
616 else | |
617 { | |
618 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
619 if(answer == 1) /* 0xFF is checksum error, 2 = RTE without bootToBootloader */ | |
620 { | |
621 extern uint8_t bootToBootloader; | |
622 bootToBootloader = 1; | |
623 } | |
624 } | |
625 break; | |
626 | |
627 case 0x79: | |
628 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
629 return 0; | |
630 ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(aTxBuffer); | |
631 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
632 return 0; | |
633 aTxBuffer[0] = prompt4D4C(receiveStartByteUart); | |
634 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1,10000)!= HAL_OK) | |
635 return 0; | |
636 else | |
637 return prompt4D4C(receiveStartByteUart); | |
638 | |
639 case 0x82: | |
640 #ifdef BOOTLOADER_STANDALONE | |
641 setForcedBluetoothName = 1; | |
642 return 0; | |
643 #else | |
644 settingsGetPointer()->debugModeOnStart = 1; | |
645 extern uint8_t bootToBootloader; | |
646 bootToBootloader = 1; | |
647 return prompt4D4C(receiveStartByteUart); | |
648 #endif | |
649 | |
650 #ifdef BOOTLOADER_STANDALONE | |
651 case 0x74: | |
652 answer = receive_update_data_mainCPU_firmware(); | |
653 if(answer != 0) | |
654 { | |
655 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
656 if(answer == 1) // 0xFF is checksum error | |
657 { | |
658 extern uint8_t bootToBootloader; | |
659 bootToBootloader = 1; | |
660 } | |
661 } | |
662 else | |
663 return 0; | |
664 break; | |
665 | |
666 case 0x75: | |
667 receive_update_data_cpu2(); | |
668 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
669 break; | |
670 | |
671 case 0x76: | |
672 answer = receive_update_data_mainCPU_variable_firmware(); | |
673 if(answer != 0) | |
674 { | |
675 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
676 if(answer == 1) // 0xFF is checksum error | |
677 { | |
678 extern uint8_t bootToBootloader; | |
679 bootToBootloader = 1; | |
680 } | |
681 } | |
682 else | |
683 return 0; | |
684 break; | |
685 | |
686 case 0x80: | |
687 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
688 return 0; | |
689 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
690 { | |
691 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
692 } | |
693 else | |
694 return 0; | |
695 break; | |
696 | |
697 case 0x81: | |
698 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 12, 1000)!= HAL_OK) | |
699 return 0; | |
700 if(hardware_programmSecondarySerial(aRxBuffer) == HAL_OK) | |
701 { | |
702 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
703 } | |
704 else | |
705 return 0; | |
706 break; | |
707 | |
708 #else | |
709 | |
710 #ifdef SPECIALPROGRAMM | |
711 case 0x80: | |
712 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 52, 5000)!= HAL_OK) | |
713 return 0; | |
714 if(hardware_programmProductionData(aRxBuffer) == HAL_OK) | |
715 { | |
716 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
717 } | |
718 else | |
719 return 0; | |
720 break; | |
721 #endif | |
722 case 0x83: | |
723 if(HAL_UART_Receive(&UartHandle, &logStepBackwards, 1, 1000)!= HAL_OK) | |
724 return 0; | |
725 logCopyDataPtr = getFrame(98); | |
726 logCopyDataPtrTemp = logCopyDataPtr; | |
727 logCopyDataLength.u32bit = ext_flash_read_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, 1000000,logStepBackwards); | |
728 answer = HAL_OK; | |
729 if(answer == HAL_OK) | |
730 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
731 if(answer == HAL_OK) | |
732 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
733 if(answer == HAL_OK) | |
734 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
735 if(answer == HAL_OK) | |
736 answer = HAL_UART_Transmit(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
737 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
738 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
739 { | |
740 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
741 logCopyDataLengthTemp -= 0xFFFF; | |
742 logCopyDataPtrTemp += 0xFFFF; | |
743 } | |
744 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
745 answer = HAL_UART_Transmit(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
746 releaseFrame(98,logCopyDataPtr); | |
747 if(answer == HAL_OK) | |
748 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
749 else | |
750 return 0; | |
751 break; | |
752 | |
753 case 0x84: | |
754 logCopyDataPtr = getFrame(98); | |
755 logCopyDataPtrTemp = logCopyDataPtr; | |
756 answer = HAL_OK; | |
757 if(answer == HAL_OK) | |
758 answer = HAL_UART_Receive(&UartHandle, &logDummyByte, 1,2000); | |
759 if(answer == HAL_OK) | |
760 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteLow), 1,2000); | |
761 if(answer == HAL_OK) | |
762 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidLow), 1,2000); | |
763 if(answer == HAL_OK) | |
764 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteMidHigh), 1,2000); | |
765 if(answer == HAL_OK) | |
766 answer = HAL_UART_Receive(&UartHandle, &(logCopyDataLength.u8bit.byteHigh), 1,2000); | |
767 logCopyDataLengthTemp = logCopyDataLength.u32bit; | |
768 while((logCopyDataLengthTemp >= 0xFFFF) && (answer == HAL_OK)) | |
769 { | |
770 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, 0xFFFF,30000); | |
771 logCopyDataLengthTemp -= 0xFFFF; | |
772 logCopyDataPtrTemp += 0xFFFF; | |
773 } | |
774 if((logCopyDataLengthTemp > 0) && (answer == HAL_OK)) | |
775 answer = HAL_UART_Receive(&UartHandle, (uint8_t *)logCopyDataPtrTemp, (uint16_t)logCopyDataLengthTemp,30000); | |
776 if(answer == HAL_OK) | |
777 ext_flash_write_dive_raw_with_double_header_1K((uint8_t *)logCopyDataPtr, logCopyDataLength.u32bit); | |
778 releaseFrame(98,logCopyDataPtr); | |
779 if(answer == HAL_OK) | |
780 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
781 else | |
782 return 0; | |
783 break; | |
784 | |
785 case 0x85: | |
786 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
787 logCopyDataPtr = getFrame(98); | |
788 ext_flash_read_header_memory((uint8_t *)logCopyDataPtr); | |
789 for(int i=0;i<8;i++) | |
790 HAL_UART_Transmit(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); | |
791 releaseFrame(98,logCopyDataPtr); | |
792 break; | |
793 | |
794 case 0x86: | |
795 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
796 logCopyDataPtr = getFrame(98); | |
797 for(int i=0;i<8;i++) | |
798 HAL_UART_Receive(&UartHandle, (uint8_t *)(logCopyDataPtr + (0x8000 * i)), (uint16_t)0x8000,60000); | |
799 ext_flash_write_header_memory((uint8_t *)logCopyDataPtr); | |
800 releaseFrame(98,logCopyDataPtr); | |
801 break; | |
802 | |
803 case 0x87: | |
804 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 4, 1000)!= HAL_OK) | |
805 return 0; | |
806 if(((aRxBuffer[0] ^ aRxBuffer[2]) != 0xFF) || ((aRxBuffer[1] ^ aRxBuffer[3]) != 0xFF)) | |
807 return 0; | |
808 totalDiveCount.u8bit.byteLow = aRxBuffer[1]; | |
809 totalDiveCount.u8bit.byteHigh = aRxBuffer[0]; | |
810 ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(totalDiveCount.u16bit); | |
811 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
812 break; | |
813 #endif | |
814 } | |
815 | |
816 // was service command? Yes, finish and exit | |
817 if(count) | |
818 { | |
819 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
820 return 0; | |
821 else | |
822 return prompt4D4C(receiveStartByteUart); | |
823 } | |
824 } | |
825 | |
826 | |
827 // download mode commands | |
828 switch(type) | |
829 { | |
830 // return of command for almost all commands | |
831 case 0x60: // get model + features | |
832 case 0x61: // get all headers full (256 bytes) | |
833 case 0x62: // set clock | |
834 case 0x63: // set custom text | |
835 case 0x66: // get dive profile | |
836 case 0x69: // get serial, old version numbering, custom text | |
837 case 0x6A: // get model | |
838 case 0x6B: // get specific firmware version | |
839 case 0x6D: // get all compact headers (16 byte) | |
840 case 0x6E: // display text | |
841 case 0x70: // read min, default, max setting | |
842 case 0x72: // read setting | |
843 case 0x77: // write setting | |
844 case 0x78: // reset all settings | |
845 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | |
846 return 0; | |
847 break; | |
848 | |
849 // start communication (again) | |
850 case 0xBB: | |
851 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 2, 1000)!= HAL_OK) | |
852 return 0; | |
853 else | |
854 return prompt4D4C(receiveStartByteUart); | |
855 | |
856 // stop communication | |
857 case 0xFF: | |
858 HAL_UART_Transmit(&UartHandle, (uint8_t*)&aTxBuffer, 1, 1000); | |
859 return 0; | |
860 | |
861 default: | |
862 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); // hw 160712 | |
863 break; | |
864 } | |
865 | |
866 switch(type) | |
867 { | |
868 case 0x62: | |
869 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 6, 2000)!= HAL_OK) | |
870 return 0; | |
871 break; | |
872 case 0x63: | |
873 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 60, 5000)!= HAL_OK) | |
874 return 0; | |
875 break; | |
876 case 0x66: | |
877 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
878 return 0; | |
879 break; | |
880 case 0x6B: | |
881 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 1000)!= HAL_OK) | |
882 return 0; | |
883 break; | |
884 case 0x6E: | |
885 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 16, 5000)!= HAL_OK) | |
886 return 0; | |
887 break; | |
888 case 0x77: | |
889 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 5, 5000)!= HAL_OK) | |
890 return 0; | |
891 break; | |
892 case 0x72: | |
893 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
894 return 0; | |
895 break; | |
896 case 0x70: | |
897 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, 1, 5000)!= HAL_OK) | |
898 return 0; | |
899 break; | |
900 } | |
901 | |
902 switch(type) | |
903 { | |
904 /* common to standard and bootloader */ | |
905 | |
906 // get model + features | |
907 case 0x60: | |
908 aTxBuffer[count++] = 0x00; // hardware descriptor HIGH byte | |
909 aTxBuffer[count++] = 0x3B; // hardware descriptor LOW byte // 0x3B is OSTC4 // 0x1A is OTSC3 | |
910 aTxBuffer[count++] = 0x00; // feature descriptor HIGH byte | |
911 if(getLicence() == LICENCEBONEX) | |
912 aTxBuffer[count++] = 0x01; // feature descriptor LOW byte | |
913 else | |
914 aTxBuffer[count++] = 0x00; // feature descriptor LOW byte | |
915 aTxBuffer[count++] = 0x43; // model id | |
916 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
917 break; | |
918 | |
919 // get model | |
920 case 0x6A: | |
921 aTxBuffer[count++] = 0x3B; // 0x3B is OSTC4 // 0x1A is OTSC3 | |
922 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
923 break; | |
924 | |
925 // get all firmware version and status (OSTC4 only) | |
926 case 0x6B: | |
927 switch(*aRxBuffer) | |
928 { | |
929 case 0xFF: | |
930 // firmware | |
931 aTxBuffer[count++] = firmwareDataGetPointer()->versionFirst; | |
932 aTxBuffer[count++] = firmwareDataGetPointer()->versionSecond; | |
933 aTxBuffer[count++] = firmwareDataGetPointer()->versionThird; | |
934 aTxBuffer[count++] = firmwareDataGetPointer()->versionBeta; | |
935 break; | |
936 case 0xFE: | |
937 // RTE | |
938 getActualRTEandFONTversion(&tempHigh, &tempLow, 0, 0); // RTE | |
939 aTxBuffer[count++] = tempHigh; | |
940 aTxBuffer[count++] = tempLow; | |
941 aTxBuffer[count++] = 0; | |
942 aTxBuffer[count++] = 0; | |
943 break; | |
944 case 0x10: | |
945 getActualRTEandFONTversion( 0, 0, &tempHigh, &tempLow); // font | |
946 aTxBuffer[count++] = tempHigh; | |
947 aTxBuffer[count++] = tempLow; | |
948 aTxBuffer[count++] = 0; | |
949 aTxBuffer[count++] = 0; | |
950 break; | |
951 default: | |
952 // not supported | |
953 aTxBuffer[count++] = 0xFF; | |
954 aTxBuffer[count++] = 0xFF; | |
955 aTxBuffer[count++] = 0xFF; | |
956 aTxBuffer[count++] = 0xFF; | |
957 break; | |
958 /* Jef Driesen Test | |
959 default: | |
960 // not supported | |
961 aTxBuffer[count++] = 0x1; | |
962 aTxBuffer[count++] = 0x1; | |
963 aTxBuffer[count++] = 0x1; | |
964 aTxBuffer[count++] = 0x1; | |
965 break; | |
966 */ | |
967 } | |
968 /* | |
969 // serial | |
970 aTxBuffer[count++] = pSettings->serialLow; | |
971 aTxBuffer[count++] = pSettings->serialHigh; | |
972 // batch code (date) | |
973 hardwareBatchCode(&tempHigh, &tempLow); | |
974 aTxBuffer[count++] = tempLow; | |
975 aTxBuffer[count++] = tempHigh; | |
976 // status and status detail (future feature) | |
977 aTxBuffer[count++] = 0; | |
978 aTxBuffer[count++] = 0; | |
979 aTxBuffer[count++] = 0; | |
980 aTxBuffer[count++] = 0; | |
981 */ | |
982 // prompt | |
983 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
984 break; | |
985 | |
986 // display text | |
987 case 0x6E: | |
988 for(int i=0;i<16;i++) | |
989 display_text[i] = aRxBuffer[i]; | |
990 display_text[15] = 0; | |
991 display_text[255] = 16; | |
992 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
993 break; | |
994 | |
995 // version / identify | |
996 case 0x69: | |
997 #ifndef BOOTLOADER_STANDALONE | |
998 aTxBuffer[count++] = pSettings->serialLow; | |
999 aTxBuffer[count++] = pSettings->serialHigh; | |
1000 aTxBuffer[count++] = firmwareVersion_16bit_low(); | |
1001 aTxBuffer[count++] = firmwareVersion_16bit_high(); | |
1002 memcpy(&aTxBuffer[count], pSettings->customtext, 60); | |
1003 #else | |
1004 aTxBuffer[count++] = 0;//pSettings->serialLow; | |
1005 aTxBuffer[count++] = 0;//pSettings->serialHigh; | |
1006 aTxBuffer[count++] = 0;//firmwareVersion_16bit_low(); | |
1007 aTxBuffer[count++] = 0;//firmwareVersion_16bit_high(); | |
1008 memset(&aTxBuffer[count], 0, 60); | |
1009 #endif | |
1010 count += 60; | |
1011 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1012 break; | |
1013 | |
1014 #ifndef BOOTLOADER_STANDALONE | |
1015 //Reset all setting | |
1016 case 0x78: | |
1017 set_settings_to_Standard(); | |
1018 updateSettingsAndMenuOnExit = 1; | |
1019 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1020 break; | |
1021 #endif | |
1022 | |
1023 #ifndef BOOTLOADER_STANDALONE | |
1024 // full headers (256 byte) | |
1025 case 0x61: | |
1026 // for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) // comment Jef Driesen email 15.09.2015 and 3.3.2016 | |
1027 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1028 { | |
1029 logbook_getHeader(StepBackwards, &logbookHeader); | |
1030 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1031 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1032 return 0; | |
1033 } | |
1034 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1035 break; | |
1036 | |
1037 // compact headers (16 byte) | |
1038 case 0x6D: | |
1039 // for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) // comment Jef Driesen email 15.09.2015 and 3.3.2016 | |
1040 for(int StepBackwards = 255; StepBackwards > -1; StepBackwards--) | |
1041 { | |
1042 logbook_getHeader(StepBackwards, &logbookHeader); | |
1043 plogbookHeaderOSTC3compact = logbook_build_ostc3header_compact(&logbookHeader); | |
1044 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3compact, 16,5000)!= HAL_OK) | |
1045 return 0; | |
1046 } | |
1047 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1048 break; | |
1049 | |
1050 // set clock & date | |
1051 case 0x62: | |
1052 // ToDo | |
1053 stimestructure.Hours = aRxBuffer[0]; | |
1054 stimestructure.Minutes = aRxBuffer[1]; | |
1055 stimestructure.Seconds = aRxBuffer[2]; | |
1056 sdatestructure.Month = aRxBuffer[3]; | |
1057 sdatestructure.Date = aRxBuffer[4]; | |
1058 sdatestructure.Year = aRxBuffer[5]; // This parameter must be a number between Min_Data = 0 and Max_Data = 99 | |
1059 setWeekday(&sdatestructure); | |
1060 | |
1061 if( ( stimestructure.Hours < 24 ) | |
1062 &&( stimestructure.Minutes < 60 ) | |
1063 &&( stimestructure.Seconds < 60 ) | |
1064 &&( sdatestructure.Month < 13 ) | |
1065 &&( sdatestructure.Date < 32 ) | |
1066 &&( sdatestructure.Year < 100 )) | |
1067 { | |
1068 setTime(stimestructure); | |
1069 setDate(sdatestructure); | |
1070 set_globalState(StUART_RTECONNECT); | |
1071 HAL_Delay(1); | |
1072 set_globalState(StUART_STANDARD); | |
1073 } | |
1074 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1075 break; | |
1076 | |
1077 case 0x63: | |
1078 for(int i=0;i<60;i++) | |
1079 pSettings->customtext[i] = aRxBuffer[i]; | |
1080 pSettings->customtext[59] = 0; | |
1081 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1082 break; | |
1083 | |
1084 // get dive profile | |
1085 case 0x66: | |
1086 // logbook_getHeader(aRxBuffer[0], &logbookHeader); // comment Jef Driesen email 15.09.2015 | |
1087 logbook_getHeader(255 - aRxBuffer[0], &logbookHeader); | |
1088 plogbookHeaderOSTC3 = logbook_build_ostc3header(&logbookHeader); | |
1089 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK) | |
1090 return 0; | |
1091 ext_flash_open_read_sample(255 - aRxBuffer[0], &sampleTotalLength); // comment Jef Driesen email 15.09.2015 about length: changed in externLogbookFlash.c | |
1092 while(sampleTotalLength >= 128) | |
1093 { | |
1094 ext_flash_read_next_sample_part(aTxBuffer,128); | |
1095 sampleTotalLength -= 128; | |
1096 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 128,5000)!= HAL_OK) | |
1097 return 0; | |
1098 } | |
1099 if(sampleTotalLength) | |
1100 { | |
1101 ext_flash_read_next_sample_part(aTxBuffer,sampleTotalLength); | |
1102 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, sampleTotalLength,5000)!= HAL_OK) | |
1103 return 0; | |
1104 } | |
1105 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1106 break; | |
1107 | |
1108 // read min,default,max setting | |
1109 case 0x70: | |
1110 count += readDataLimits__8and16BitValues_4and7BytesOutput(aRxBuffer[0],&aTxBuffer[count]); | |
1111 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1112 break; | |
1113 | |
1114 // read setting | |
1115 case 0x72: | |
1116 readData(aRxBuffer[0],&aTxBuffer[count]); | |
1117 count += 4; | |
1118 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1119 break; | |
1120 | |
1121 // write setting | |
1122 case 0x77: | |
1123 writeData(aRxBuffer); | |
1124 updateSettingsAndMenuOnExit = 1; | |
1125 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1126 break; | |
1127 #else | |
1128 /* bootloader dummies */ | |
1129 // full headers (256 byte) | |
1130 case 0x61: | |
1131 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1132 { | |
1133 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1134 return 0; | |
1135 } | |
1136 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1137 break; | |
1138 // compact headers (16 byte) | |
1139 case 0x6D: | |
1140 for(int StepBackwards = 0;StepBackwards<256;StepBackwards++) | |
1141 { | |
1142 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 16,5000)!= HAL_OK) | |
1143 return 0; | |
1144 } | |
1145 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1146 break; | |
1147 // set clock & date | |
1148 case 0x62: | |
1149 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1150 break; | |
1151 // set custom text | |
1152 case 0x63: | |
1153 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1154 break; | |
1155 // get dive profile | |
1156 case 0x66: | |
1157 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)dummyForBootloader, 256,5000)!= HAL_OK) | |
1158 return 0; | |
1159 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1160 break; | |
1161 // read min,default,max setting | |
1162 // read settings | |
1163 | |
1164 | |
1165 case 0x72: | |
1166 memcpy(&aTxBuffer[count], dummyForBootloader, 4); | |
1167 count += 4; | |
1168 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1169 break; | |
1170 // write settings | |
1171 case 0x77: | |
1172 aTxBuffer[count++] = prompt4D4C(receiveStartByteUart); | |
1173 break; | |
1174 #endif | |
1175 } | |
1176 | |
1177 if(count) | |
1178 { | |
1179 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, count,10000)!= HAL_OK) | |
1180 return 0; | |
1181 else | |
1182 return prompt4D4C(receiveStartByteUart); | |
1183 } | |
1184 return 0; | |
1185 } | |
1186 | |
1187 | |
1188 HAL_StatusTypeDef receive_uart_large_size(UART_HandleTypeDef *huart, uint8_t *pData, uint32_t Size) | |
1189 { | |
1190 uint16_t length_16_blocks; | |
1191 uint16_t length_16_remainder; | |
1192 uint32_t temp; | |
1193 HAL_StatusTypeDef result = HAL_OK; | |
1194 uint32_t pDataLocal; | |
1195 | |
1196 length_16_blocks = (uint16_t) (Size / 0xFFFF); | |
1197 temp = length_16_blocks; | |
1198 temp *= 0xFFFF; | |
1199 length_16_remainder = (uint16_t) ( Size - temp); | |
1200 | |
1201 pDataLocal = (uint32_t)pData; | |
1202 | |
1203 while((result == HAL_OK) && length_16_blocks) | |
1204 { | |
1205 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, 0xFFFF , 60000); | |
1206 pDataLocal += 0xFFFF; | |
1207 length_16_blocks--; | |
1208 } | |
1209 if((result == HAL_OK) && length_16_remainder) | |
1210 { | |
1211 result = HAL_UART_Receive(&UartHandle, (uint8_t *)pDataLocal, length_16_remainder , 60000); | |
1212 } | |
1213 return result; | |
1214 } | |
1215 | |
1216 | |
1217 /* for safety reason (memory blocking this code is main and sub */ | |
1218 | |
1219 #ifdef BOOTLOADER_STANDALONE | |
1220 | |
1221 uint8_t receive_update_data_cpu2(void) | |
1222 { | |
1223 uint8_t answer; | |
1224 | |
1225 uint8_t* pBuffer = (uint8_t*)getFrame(20); | |
1226 answer = receive_update_data_cpu2_sub(pBuffer); | |
1227 releaseFrame(20,(uint32_t)pBuffer); | |
1228 return answer; | |
1229 } | |
1230 | |
1231 | |
1232 uint8_t receive_update_data_cpu2_sub(uint8_t* pBuffer) | |
1233 { | |
1234 uint8_t sBuffer[10]; | |
1235 uint32_t length, offsetTotal, pruefsumme, pruefsummeCalc; | |
1236 uint8_t id; | |
1237 const uint8_t id_RTE = 0xFE; | |
1238 | |
1239 //Get length | |
1240 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1241 { | |
1242 return 0; | |
1243 } | |
1244 length = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1245 | |
1246 //Get id | |
1247 if(HAL_UART_Receive(&UartHandle, pBuffer, 4,5000)!= HAL_OK) // 58000 | |
1248 { | |
1249 return 0; | |
1250 } | |
1251 id = pBuffer[0]; | |
1252 offsetTotal = 256 * 256 * 256 * (uint32_t)pBuffer[0] + 256 * 256 * (uint32_t)pBuffer[1] + 256 * (uint32_t)pBuffer[2] + pBuffer[3]; | |
1253 | |
1254 // get pruefsumme, bytes are in different order on Dev C++ code!!! | |
1255 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1256 { | |
1257 return 0; | |
1258 } | |
1259 pruefsumme = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; | |
1260 pruefsummeCalc = length + offsetTotal; | |
1261 | |
1262 // no need to get code if pruefsumme == length is wrong | |
1263 if(pruefsummeCalc != pruefsumme) | |
1264 { | |
1265 return 0; | |
1266 } | |
1267 | |
1268 //get Code | |
1269 if(receive_uart_large_size(&UartHandle, pBuffer, length)!= HAL_OK) | |
1270 { | |
1271 return 0; | |
1272 } | |
1273 | |
1274 //get Checksum | |
1275 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 580000 | |
1276 { | |
1277 return 0; | |
1278 } | |
1279 uint32_t checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1280 // uint32_t checksumCalc = crc32c_checksum(pBuffer, length,0,0); | |
1281 uint32_t checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer, length/4); | |
1282 | |
1283 if(checksum != checksumCalc) | |
1284 { | |
1285 return 0; | |
1286 } | |
1287 | |
1288 if(id != id_RTE) | |
1289 { | |
1290 strcpy(display_text,"wrong data."); | |
1291 display_text[255] = 32; | |
1292 return 0; | |
1293 } | |
1294 | |
1295 strcpy(display_text," RTE update."); | |
1296 display_text[255] = 32; | |
1297 | |
1298 return extCPU2bootloader(pBuffer,length,display_text); | |
1299 } | |
1300 #endif // BOOTLOADER_STANDALONE | |
1301 | |
1302 | |
1303 | |
1304 uint8_t receive_update_flex(uint8_t isRTEupdateALLOWED) | |
1305 { | |
1306 uint8_t answer; | |
1307 | |
1308 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1309 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1310 | |
1311 answer = receive_update_data_flex(pBuffer1, pBuffer2, isRTEupdateALLOWED); | |
1312 | |
1313 releaseFrame(20,(uint32_t)pBuffer1); | |
1314 releaseFrame(20,(uint32_t)pBuffer2); | |
1315 | |
1316 return answer; | |
1317 } | |
1318 | |
1319 uint8_t receive_update_data_mainCPU_firmware(void) | |
1320 { | |
1321 uint8_t answer; | |
1322 | |
1323 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1324 | |
1325 answer = receive_update_data_mainCPU_firmware_subrotuine(1, pBuffer1, 0); | |
1326 | |
1327 releaseFrame(20,(uint32_t)pBuffer1); | |
1328 | |
1329 return answer; | |
1330 } | |
1331 | |
1332 /* multi buffer (long data) not tested yet */ | |
1333 uint8_t receive_update_data_mainCPU_variable_firmware(void) | |
1334 { | |
1335 uint8_t answer; | |
1336 | |
1337 uint8_t* pBuffer1 = (uint8_t*)getFrame(20); | |
1338 uint8_t* pBuffer2 = (uint8_t*)getFrame(20); | |
1339 | |
1340 answer = receive_update_data_mainCPU_firmware_subrotuine(2, pBuffer1, pBuffer2); | |
1341 | |
1342 releaseFrame(20,(uint32_t)pBuffer1); | |
1343 releaseFrame(20,(uint32_t)pBuffer2); | |
1344 | |
1345 return answer; | |
1346 } | |
1347 | |
1348 uint8_t receive_update_data_flex(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t RTEupdateALLOWED) | |
1349 { | |
1350 uint8_t sBuffer[10]; | |
1351 uint8_t serialBuffer[10]; | |
1352 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
1353 uint32_t lengthTotal, offsetTotal, pruefsumme, pruefsummeCalc; | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1354 uint32_t checksum, checksumCalc = 0; |
38 | 1355 uint8_t id; |
1356 const uint8_t id_Region1_firmware = 0xFF; | |
1357 const uint8_t id_RTE = 0xFE; | |
1358 uint8_t textpointer = 0; | |
1359 | |
1360 //Get length | |
1361 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1362 { | |
1363 return 0; | |
1364 } | |
1365 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1366 | |
1367 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1368 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1369 { | |
1370 return 0; | |
1371 } | |
1372 id = sBuffer[0]; | |
1373 | |
1374 pruefsummeCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1375 pruefsummeCalc += lengthTotal; | |
1376 //alt, geht nicht mehr wegen Font: pruefsummeCalc = lengthTotal + offsetTotal; | |
1377 | |
1378 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1379 { | |
1380 return 0; | |
1381 } | |
1382 | |
1383 // neu 110212 | |
1384 if(id == id_FONT) | |
1385 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1386 else | |
1387 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1388 | |
1389 // get pruefsumme, bytes are in different order on Dev C++ code!!! | |
1390 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1391 { | |
1392 return 0; | |
1393 } | |
1394 pruefsumme = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; | |
1395 | |
1396 | |
1397 if(pruefsummeCalc != pruefsumme) | |
1398 { | |
1399 uint8_t ptr = 0; | |
1400 strcpy(&display_text[ptr]," checksum error"); | |
1401 ptr += 15; | |
1402 strcpy(&display_text[ptr],"\n\r"); | |
1403 ptr += 2; | |
1404 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1405 display_text[ptr] = 0; | |
1406 display_text[255] = ptr + 1; | |
1407 return 0xFF; | |
1408 } | |
1409 | |
1410 //Get serial (new since 160211) | |
1411 if(HAL_UART_Receive(&UartHandle, serialBuffer, 4,5000)!= HAL_OK) | |
1412 { | |
1413 return 0; | |
1414 } | |
1415 | |
1416 if(lengthTotal > 768000) | |
1417 { | |
1418 length1 = 768000; | |
1419 length2 = lengthTotal - length1; | |
1420 } | |
1421 else | |
1422 { | |
1423 length1 = lengthTotal; | |
1424 length2 = 0; | |
1425 } | |
1426 | |
1427 if((pBuffer2 == 0) && (length2 != 0)) | |
1428 return 0; | |
1429 | |
1430 //get Code | |
1431 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1432 return 0; | |
1433 | |
1434 if(length2) | |
1435 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1436 return 0; | |
1437 | |
1438 //get Checksum | |
1439 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1440 return 0; | |
1441 | |
1442 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1443 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1444 if(length2) | |
1445 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1446 else | |
1447 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1448 | |
1449 /* check id now */ | |
1450 /* | |
1451 if(region == 2) | |
1452 { | |
1453 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1454 { | |
1455 strcpy(display_text,"wrong data."); | |
1456 display_text[255] = 32; | |
1457 return 0; | |
1458 } | |
1459 } | |
1460 else | |
1461 { | |
1462 if(id != id_Region1_firmware) | |
1463 { | |
1464 strcpy(display_text,"wrong data."); | |
1465 display_text[255] = 32; | |
1466 return 0; | |
1467 } | |
1468 } | |
1469 */ | |
1470 /* test checksum */ | |
1471 if(checksum != checksumCalc) | |
1472 { | |
1473 uint8_t ptr = 0; | |
1474 strcpy(&display_text[ptr]," pruefsummen error"); | |
1475 ptr += 15; | |
1476 strcpy(&display_text[ptr],"\n\r"); | |
1477 display_text[ptr] = 0; | |
1478 display_text[255] = ptr + 1; | |
1479 return 0xFF; | |
1480 } | |
1481 | |
1482 if(id == id_Region1_firmware) | |
1483 { | |
1484 uint8_t ptr = 0; | |
1485 display_text[ptr++] = 'V'; | |
1486 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1487 display_text[ptr++] = '.'; | |
1488 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1489 display_text[ptr++] = '.'; | |
1490 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1491 display_text[ptr++] = ' '; | |
1492 if(pBuffer1[0x10003]) | |
1493 { | |
1494 strcpy(&display_text[ptr],"beta "); | |
1495 ptr +=5; | |
1496 } | |
1497 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
1498 ptr += 25; // circa ungef�hr | |
1499 display_text[255] = ptr + 1; | |
1500 } | |
1501 else if(id == id_RTE) | |
1502 { | |
1503 if(RTEupdateALLOWED) | |
1504 { | |
1505 strcpy(display_text," RTE update.\n\r"); | |
1506 textpointer = 0; | |
1507 while((display_text[textpointer] != 0) && (textpointer < 50)) | |
1508 textpointer++; | |
1509 #ifndef BOOTLOADER_STANDALONE | |
1510 if(textpointer < 50) | |
1511 { | |
1512 // display_text[textpointer++] = | |
1513 display_text[textpointer++] = '\025'; | |
1514 display_text[textpointer++] = TXT_2BYTE; | |
1515 display_text[textpointer++] = TXT2BYTE_DecoDataLost; | |
1516 display_text[textpointer] = 0; | |
1517 } | |
1518 #endif | |
1519 display_text[255] = textpointer+1; | |
1520 return extCPU2bootloader(pBuffer1,length1,display_text); | |
1521 } | |
1522 else | |
1523 return 0xFF; | |
1524 } | |
1525 else | |
1526 //if(region == 2) | |
1527 { | |
1528 uint8_t ptr = 0; | |
1529 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1530 strcpy(&display_text[ptr]," bytes with "); | |
1531 ptr += 12; | |
1532 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1533 strcpy(&display_text[ptr]," offset"); | |
1534 ptr += 7; | |
1535 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
1536 ptr += 25; // circa ungef�hr | |
1537 display_text[255] = ptr + 1; | |
1538 } | |
1539 | |
1540 | |
1541 // only non RTE !! | |
1542 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1543 ByteCompareStatus = 0; | |
1544 | |
1545 if(id == id_Region1_firmware) | |
1546 { | |
1547 /* standard firmware limited to 768000 */ | |
1548 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1549 ext_flash_erase_firmware(); | |
1550 ext_flash_write_firmware(pBuffer1, length1); | |
1551 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1552 | |
1553 if(lengthCompare != length1) | |
1554 ByteCompareStatus = 10000; | |
1555 for(int i = 0; i < length1; i++) | |
1556 { | |
1557 if(pBuffer1[0] != pBufferCompare[0]) | |
1558 ByteCompareStatus++; | |
1559 } | |
1560 } | |
1561 else | |
1562 //if(region == 2) | |
1563 { | |
1564 /* upper region firmware can be larger (1MB) */ | |
1565 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1566 ext_flash_erase_firmware2(); | |
1567 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1568 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1569 | |
1570 if(lengthCompare != length1 + length2) | |
1571 ByteCompareStatus = 10000; | |
1572 if(offsetTotal != offsetCompare) | |
1573 ByteCompareStatus += 20000; | |
1574 for(int i = 0; i < length1; i++) | |
1575 { | |
1576 if(pBuffer1[0] != pBufferCompare[0]) | |
1577 ByteCompareStatus++; | |
1578 } | |
1579 | |
1580 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1581 for(int i = 0; i < length2; i++) | |
1582 { | |
1583 if(pBuffer2[0] != pBufferCompare[0]) | |
1584 ByteCompareStatus++; | |
1585 } | |
1586 } | |
1587 | |
1588 releaseFrame(20,(uint32_t)pBufferCompare); | |
1589 | |
1590 if(ByteCompareStatus != 0) | |
1591 { | |
1592 strcpy(&display_text[0],"\n\rcopy error."); | |
1593 display_text[255] = 21; | |
1594 return 0; | |
1595 } | |
1596 else | |
1597 { | |
1598 strcpy(&display_text[0],"\n\rready to install."); | |
1599 display_text[255] = 21; | |
1600 return 1; | |
1601 } | |
1602 } | |
1603 | |
1604 | |
1605 uint8_t receive_update_data_mainCPU_firmware_subrotuine(uint8_t region, uint8_t* pBuffer1, uint8_t* pBuffer2) | |
1606 { | |
1607 uint8_t sBuffer[10]; | |
1608 uint32_t length1, length2, lengthCompare, offsetCompare, ByteCompareStatus; | |
1609 uint32_t lengthTotal, offsetTotal, pruefsumme, pruefsummeCalc; | |
1610 uint32_t checksum, checksumCalc; | |
1611 uint8_t id; | |
1612 | |
1613 | |
1614 //Get length | |
1615 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1616 return 0; | |
1617 | |
1618 lengthTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1619 | |
1620 //Get offset and/or id (id is 0xFF for RTE, 0xFE for firmware and offset if var) | |
1621 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1622 return 0; | |
1623 | |
1624 id = sBuffer[0]; | |
1625 | |
1626 pruefsummeCalc = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1627 pruefsummeCalc += lengthTotal; | |
1628 | |
1629 if((id != id_Region1_firmware) && (id != id_RTE) && (id != id_FONT) && (id != id_FONT_OLD)) | |
1630 return 0; | |
1631 | |
1632 if(id == id_FONT) | |
1633 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[1] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[3]; | |
1634 // alt, prior to id for font | |
1635 else | |
1636 offsetTotal = 256 * 256 * 256 * (uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1637 | |
1638 // get pruefsumme, bytes are in different order on Dev C++ code!!! | |
1639 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1640 return 0; | |
1641 | |
1642 pruefsumme = 256 * 256 * 256 * (uint32_t)sBuffer[3] + 256 * 256 * (uint32_t)sBuffer[2] + 256 * (uint32_t)sBuffer[1] + sBuffer[0]; | |
1643 | |
1644 //alt: pruefsummeCalc = lengthTotal + offsetTotal; | |
1645 | |
1646 if(pruefsummeCalc != pruefsumme) | |
1647 { | |
1648 uint8_t ptr = 0; | |
1649 strcpy(&display_text[ptr]," checksum error"); | |
1650 ptr += 15; | |
1651 strcpy(&display_text[ptr],"\n\r"); | |
1652 ptr += 2; | |
1653 ptr += gfx_number_to_string(10,0,&display_text[ptr],checksumCalc); | |
1654 display_text[ptr] = 0; | |
1655 display_text[255] = ptr + 1; | |
1656 return 0xFF; | |
1657 } | |
1658 | |
1659 if(lengthTotal > 768000) | |
1660 { | |
1661 length1 = 768000; | |
1662 length2 = lengthTotal - length1; | |
1663 } | |
1664 else | |
1665 { | |
1666 length1 = lengthTotal; | |
1667 length2 = 0; | |
1668 } | |
1669 | |
1670 if((pBuffer2 == 0) && (length2 != 0)) | |
1671 return 0; | |
1672 | |
1673 //get Code | |
1674 if(receive_uart_large_size(&UartHandle, pBuffer1, length1)!= HAL_OK) | |
1675 return 0; | |
1676 | |
1677 if(length2) | |
1678 if(receive_uart_large_size(&UartHandle, pBuffer2, length2)!= HAL_OK) | |
1679 return 0; | |
1680 | |
1681 //get Checksum | |
1682 if(HAL_UART_Receive(&UartHandle, sBuffer, 4,5000)!= HAL_OK) // 58000 | |
1683 return 0; | |
1684 | |
1685 checksum = 256 * 256 * 256 *(uint32_t)sBuffer[0] + 256 * 256 * (uint32_t)sBuffer[1] + 256 * (uint32_t)sBuffer[2] + sBuffer[3]; | |
1686 // uint32_t checksumCalc = crc32c_checksum(pBuffer1, length1, pBuffer2, length2); | |
1687 if(length2) | |
1688 checksumCalc = CRC_CalcBlockCRC_moreThan768000((uint32_t*)pBuffer1, (uint32_t*)pBuffer2, lengthTotal/4); | |
1689 else | |
1690 checksumCalc = CRC_CalcBlockCRC((uint32_t*)pBuffer1, length1/4); | |
1691 | |
1692 /* check id now */ | |
1693 if(region == 2) | |
1694 { | |
1695 if((id == id_Region1_firmware) || (id == id_RTE)) | |
1696 { | |
1697 strcpy(display_text,"wrong data."); | |
1698 display_text[255] = 32; | |
1699 return 0; | |
1700 } | |
1701 } | |
1702 else | |
1703 { | |
1704 if(id != id_Region1_firmware) | |
1705 { | |
1706 strcpy(display_text,"wrong data."); | |
1707 display_text[255] = 32; | |
1708 return 0; | |
1709 } | |
1710 } | |
1711 | |
1712 /* test checksum */ | |
1713 if(checksum != checksumCalc) | |
1714 { | |
1715 uint8_t ptr = 0; | |
1716 strcpy(&display_text[ptr]," pruefsummen error"); | |
1717 ptr += 15; | |
1718 strcpy(&display_text[ptr],"\n\r"); | |
1719 display_text[ptr] = 0; | |
1720 display_text[255] = ptr + 1; | |
1721 return 0xFF; | |
1722 } | |
1723 | |
1724 if(region == 2) | |
1725 { | |
1726 uint8_t ptr = 0; | |
1727 ptr += gfx_number_to_string(7,0,&display_text[ptr],lengthTotal); | |
1728 strcpy(&display_text[ptr]," bytes with "); | |
1729 ptr += 12; | |
1730 ptr += gfx_number_to_string(7,0,&display_text[ptr],offsetTotal); | |
1731 strcpy(&display_text[ptr]," offset"); | |
1732 ptr += 7; | |
1733 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
1734 ptr += 25; // circa ungef�hr | |
1735 display_text[255] = ptr + 1; | |
1736 | |
1737 } | |
1738 else | |
1739 { | |
1740 uint8_t ptr = 0; | |
1741 display_text[ptr++] = 'V'; | |
1742 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10000] & 0x1F); | |
1743 display_text[ptr++] = '.'; | |
1744 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10001] & 0x1F); | |
1745 display_text[ptr++] = '.'; | |
1746 ptr += gfx_number_to_string(2,0,&display_text[ptr],pBuffer1[0x10002] & 0x1F); | |
1747 display_text[ptr++] = ' '; | |
1748 if(pBuffer1[0x10003]) | |
1749 { | |
1750 strcpy(&display_text[ptr],"beta "); | |
1751 ptr +=5; | |
1752 } | |
1753 strcpy(&display_text[ptr],"\n\rpreparing for install."); | |
1754 ptr += 25; // circa ungef�hr | |
1755 display_text[255] = ptr + 1; | |
1756 } | |
1757 | |
1758 uint8_t* pBufferCompare = (uint8_t*)getFrame(20); | |
1759 ByteCompareStatus = 0; | |
1760 | |
1761 if(region == 2) | |
1762 { | |
1763 /* upper region firmware can be larger (1MB) */ | |
1764 if(ext_flash_read_firmware2(0, pBufferCompare,4, 0,0) != 0xFFFFFFFF) | |
1765 ext_flash_erase_firmware2(); | |
1766 ext_flash_write_firmware2(offsetTotal, pBuffer1, length1, pBuffer2, length2); | |
1767 lengthCompare = ext_flash_read_firmware2(&offsetCompare, pBufferCompare,768000, 0,768000); | |
1768 | |
1769 if(lengthCompare != length1 + length2) | |
1770 ByteCompareStatus = 10000; | |
1771 if(offsetTotal != offsetCompare) | |
1772 ByteCompareStatus += 20000; | |
1773 for(int i = 0; i < length1; i++) | |
1774 { | |
1775 if(pBuffer1[0] != pBufferCompare[0]) | |
1776 ByteCompareStatus++; | |
1777 } | |
1778 | |
1779 lengthCompare = ext_flash_read_firmware2(0, 0,768000, pBufferCompare,768000); | |
1780 for(int i = 0; i < length2; i++) | |
1781 { | |
1782 if(pBuffer2[0] != pBufferCompare[0]) | |
1783 ByteCompareStatus++; | |
1784 } | |
1785 } | |
1786 else | |
1787 { | |
1788 /* standard firmware limited to 768000 */ | |
1789 if(ext_flash_read_firmware(pBufferCompare,4,0) != 0xFFFFFFFF) | |
1790 ext_flash_erase_firmware(); | |
1791 ext_flash_write_firmware(pBuffer1, length1); | |
1792 lengthCompare = ext_flash_read_firmware(pBufferCompare,768000,0); | |
1793 | |
1794 if(lengthCompare != length1) | |
1795 ByteCompareStatus = 10000; | |
1796 for(int i = 0; i < length1; i++) | |
1797 { | |
1798 if(pBuffer1[0] != pBufferCompare[0]) | |
1799 ByteCompareStatus++; | |
1800 } | |
1801 } | |
1802 | |
1803 releaseFrame(20,(uint32_t)pBufferCompare); | |
1804 | |
1805 if(ByteCompareStatus != 0) | |
1806 { | |
1807 strcpy(&display_text[0],"\n\rcopy error."); | |
1808 display_text[255] = 21; | |
1809 return 0; | |
1810 } | |
1811 else | |
1812 { | |
1813 strcpy(&display_text[0],"\n\rready to install."); | |
1814 display_text[255] = 21; | |
1815 return 1; | |
1816 } | |
1817 } | |
1818 | |
1819 static void tComm_Error_Handler(void) | |
1820 { | |
1821 while(1) | |
1822 {} | |
1823 } |