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