annotate Discovery/Src/tComm.c @ 321:37ee61f93124 O2_SensorSync

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