diff 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
line wrap: on
line diff
--- a/Small_CPU/Src/baseCPU2.c	Tue Feb 18 12:41:45 2020 +0100
+++ b/Small_CPU/Src/baseCPU2.c	Sun Feb 23 21:09:56 2020 +0100
@@ -151,6 +151,8 @@
 #include "stm32f4xx_hal.h"
 #include <stdio.h>
 
+uint8_t coldstart __attribute__((section (".noinit")));
+
 uint8_t hasExternalClock(void) {
 	if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF))
 		return 1;
@@ -181,7 +183,9 @@
 		/* for safety reasons and coming functions */
 		.magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND,
 		.magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */
-		.magic[3] = FIRMWARE_MAGIC_END };
+		.magic[3] = FIRMWARE_MAGIC_END
+};
+
 
 uint8_t firmwareVersionHigh(void) {
 	return cpu2_FirmwareData.versionFirst;
@@ -339,7 +343,11 @@
 	init_battery_gas_gauge();
 	HAL_Delay(10);
 	battery_gas_gauge_get_data();
-//	battery_gas_gauge_set(0);
+	if(coldstart != 0xA5)
+	{
+		coldstart = 0xA5;
+		battery_gas_gauge_set(0);
+	}
 
 	global.lifeData.battery_voltage = get_voltage();
 	global.lifeData.battery_charge = get_charge();