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