annotate Discovery/Src/tComm.c @ 189:8b8074080d7b avg-temp

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