comparison Small_CPU/Src/baseCPU2.c @ 433:aa286a4926c2 Improve_BatteryGasGauge

Detect startup after power off: Introduced a variable in memory area which is not initialized during startup. In case of a start from power off the memory cell will be initialized (persistant as long as RTE is powered) and charge counter is set to 0 signaling the user to do a complete charge to calibrate the counter.
author ideenmodellierer
date Sun, 23 Feb 2020 21:09:56 +0100
parents 54a480c43e97
children 5b4c78c36b04
comparison
equal deleted inserted replaced
432:2b4440f75434 433:aa286a4926c2
149 149
150 // From Common/Drivers/ 150 // From Common/Drivers/
151 #include "stm32f4xx_hal.h" 151 #include "stm32f4xx_hal.h"
152 #include <stdio.h> 152 #include <stdio.h>
153 153
154 uint8_t coldstart __attribute__((section (".noinit")));
155
154 uint8_t hasExternalClock(void) { 156 uint8_t hasExternalClock(void) {
155 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) 157 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF))
156 return 1; 158 return 1;
157 else 159 else
158 return 0; 160 return 0;
179 .release_info = "stable Nov'19", 181 .release_info = "stable Nov'19",
180 182
181 /* for safety reasons and coming functions */ 183 /* for safety reasons and coming functions */
182 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, 184 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND,
183 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ 185 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */
184 .magic[3] = FIRMWARE_MAGIC_END }; 186 .magic[3] = FIRMWARE_MAGIC_END
187 };
188
185 189
186 uint8_t firmwareVersionHigh(void) { 190 uint8_t firmwareVersionHigh(void) {
187 return cpu2_FirmwareData.versionFirst; 191 return cpu2_FirmwareData.versionFirst;
188 } 192 }
189 193
337 init_surface_ring(0); 341 init_surface_ring(0);
338 } 342 }
339 init_battery_gas_gauge(); 343 init_battery_gas_gauge();
340 HAL_Delay(10); 344 HAL_Delay(10);
341 battery_gas_gauge_get_data(); 345 battery_gas_gauge_get_data();
342 // battery_gas_gauge_set(0); 346 if(coldstart != 0xA5)
347 {
348 coldstart = 0xA5;
349 battery_gas_gauge_set(0);
350 }
343 351
344 global.lifeData.battery_voltage = get_voltage(); 352 global.lifeData.battery_voltage = get_voltage();
345 global.lifeData.battery_charge = get_charge(); 353 global.lifeData.battery_charge = get_charge();
346 copyBatteryData(); 354 copyBatteryData();
347 355