From d7b8c90cb4d38ca985fa49e8d5abae0c87052f0a Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sat, 15 Oct 2022 21:42:46 +0200 Subject: [PATCH] Add new temperature thresholds to flash config --- src/flash_config.c | 2 +- src/flash_config.h | 36 ++++++++++++++++++++++-------------- utils/config_b26.yaml | 8 ++++++++ utils/config_dev.yaml | 8 ++++++++ utils/config_to_hex.py | 32 +++++++++++++++++--------------- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/flash_config.c b/src/flash_config.c index 365769b..a92d7b6 100644 --- a/src/flash_config.c +++ b/src/flash_config.c @@ -3,5 +3,5 @@ bool flash_config_is_present(void) { return (FLASH_CONFIG_CAL_FACTOR_U_BAT != 0xFFFF) - && (FLASH_CONFIG_U_BAT_REGULATION_CORRIDOR != -1); + && (FLASH_CONFIG_DEEPSLEEP_DURATION != 0xFFFFFFFF); } diff --git a/src/flash_config.h b/src/flash_config.h index 24dfde0..5065140 100644 --- a/src/flash_config.h +++ b/src/flash_config.h @@ -63,27 +63,35 @@ extern uint8_t __conf_start; /* Resume operation below this temperature (in units of 0.1 °C). */ #define FLASH_CONFIG_INTERNAL_TEMPERATURE_RECOVERY (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x012C)) +/* Minimum allowed external (BMP280) temperature (in units of 0.1 °C). If the + * temperature falls below this value, charging is stopped to prevent damage to + * the battery. */ +#define FLASH_CONFIG_EXTERNAL_TEMPERATURE_LIMIT (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0130)) + +/* Resume operation above this temperature (in units of 0.1 °C). */ +#define FLASH_CONFIG_EXTERNAL_TEMPERATURE_RECOVERY (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0134)) + /* Thresholds for load control */ /* Voltage above which the load is turned on (in mV). */ -#define FLASH_CONFIG_U_BAT_LOAD_ON (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0130)) +#define FLASH_CONFIG_U_BAT_LOAD_ON (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0138)) /* Voltage below which the load is turned off (in mV). */ -#define FLASH_CONFIG_U_BAT_LOAD_OFF (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0134)) +#define FLASH_CONFIG_U_BAT_LOAD_OFF (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x013c)) /* Current at which the overload protection triggers (in mA). */ -#define FLASH_CONFIG_LOAD_CURRENT_LIMIT_MA (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0138)) +#define FLASH_CONFIG_LOAD_CURRENT_LIMIT_MA (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0140)) /* Inrush tolerance time (in ms). Overload protection is not enforced for this * time after load power-on. */ -#define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x013C)) +#define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144)) /* Minimum voltage that the charge pump must produce above U_bat before any * power FET is switched on (in mV). */ -#define FLASH_CONFIG_MIN_CHARGE_PUMP_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0140)) +#define FLASH_CONFIG_MIN_CHARGE_PUMP_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0148)) /* The minimum time the load must be off before it can be switched on again (in ms). */ -#define FLASH_CONFIG_LOAD_ON_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144)) +#define FLASH_CONFIG_LOAD_ON_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x014c)) /* Measurement Averaging: @@ -99,21 +107,21 @@ extern uint8_t __conf_start; * */ /* Averaging factor for load current. */ -#define FLASH_CONFIG_AVG_ALPHA_I_SOLAR (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0148)) -#define FLASH_CONFIG_AVG_ALPHA_I_LOAD (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x014C)) -#define FLASH_CONFIG_AVG_ALPHA_U_BAT (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0150)) -#define FLASH_CONFIG_AVG_ALPHA_U_SW (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0154)) -#define FLASH_CONFIG_AVG_ALPHA_U_SOLAR (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0158)) -#define FLASH_CONFIG_AVG_ALPHA_TEMP (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x015C)) +#define FLASH_CONFIG_AVG_ALPHA_I_SOLAR (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0150)) +#define FLASH_CONFIG_AVG_ALPHA_I_LOAD (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0154)) +#define FLASH_CONFIG_AVG_ALPHA_U_BAT (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0158)) +#define FLASH_CONFIG_AVG_ALPHA_U_SW (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x015c)) +#define FLASH_CONFIG_AVG_ALPHA_U_SOLAR (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0160)) +#define FLASH_CONFIG_AVG_ALPHA_TEMP (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0164)) /* Generic configuration */ /* Time (in ms) to stay active in idle state before entering deep sleep. */ -#define FLASH_CONFIG_DEEPSLEEP_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0160)) +#define FLASH_CONFIG_DEEPSLEEP_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0168)) /* Deep sleep duration (in seconds). */ -#define FLASH_CONFIG_DEEPSLEEP_DURATION (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0164)) +#define FLASH_CONFIG_DEEPSLEEP_DURATION (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x016c)) /* Functions */ diff --git a/utils/config_b26.yaml b/utils/config_b26.yaml index 8175032..295bc4a 100644 --- a/utils/config_b26.yaml +++ b/utils/config_b26.yaml @@ -56,6 +56,14 @@ config: # Resume operation below this temperature (in units of 0.1 °C). INTERNAL_TEMPERATURE_RECOVERY: 450 + # Minimum allowed external (BMP280) temperature (in units of 0.1 °C). If the + # temperature falls below this value, charging is stopped to prevent damage to + # the battery. + EXTERNAL_TEMPERATURE_LIMIT: -30 + + # Resume operation above this temperature (in units of 0.1 °C). + EXTERNAL_TEMPERATURE_RECOVERY: 0 + # Thresholds for load control diff --git a/utils/config_dev.yaml b/utils/config_dev.yaml index 8a65a4d..03f7479 100644 --- a/utils/config_dev.yaml +++ b/utils/config_dev.yaml @@ -56,6 +56,14 @@ config: # Resume operation below this temperature (in units of 0.1 °C). INTERNAL_TEMPERATURE_RECOVERY: 450 + # Minimum allowed external (BMP280) temperature (in units of 0.1 °C). If the + # temperature falls below this value, charging is stopped to prevent damage to + # the battery. + EXTERNAL_TEMPERATURE_LIMIT: 250 + + # Resume operation above this temperature (in units of 0.1 °C). + EXTERNAL_TEMPERATURE_RECOVERY: 270 + # Thresholds for load control diff --git a/utils/config_to_hex.py b/utils/config_to_hex.py index f96949c..8891ed7 100755 --- a/utils/config_to_hex.py +++ b/utils/config_to_hex.py @@ -29,20 +29,22 @@ CONFIG_KEY_TO_OFFSET = { "SLEEP_SWITCH_DELAY": 0x0124, "INTERNAL_TEMPERATURE_LIMIT": 0x0128, "INTERNAL_TEMPERATURE_RECOVERY": 0x012C, - "U_BAT_LOAD_ON": 0x0130, - "U_BAT_LOAD_OFF": 0x0134, - "LOAD_CURRENT_LIMIT_MA": 0x0138, - "LOAD_CURRENT_INRUSH_TIME": 0x013C, - "MIN_CHARGE_PUMP_EXCESS_VOLTAGE": 0x0140, - "LOAD_ON_DELAY": 0x0144, - "AVG_ALPHA_I_SOLAR": 0x0148, - "AVG_ALPHA_I_LOAD": 0x014C, - "AVG_ALPHA_U_BAT": 0x0150, - "AVG_ALPHA_U_SW": 0x0154, - "AVG_ALPHA_U_SOLAR": 0x0158, - "AVG_ALPHA_TEMP": 0x015C, - "DEEPSLEEP_DELAY": 0x0160, - "DEEPSLEEP_DURATION": 0x0164, + "EXTERNAL_TEMPERATURE_LIMIT": 0x0130, + "EXTERNAL_TEMPERATURE_RECOVERY": 0x0134, + "U_BAT_LOAD_ON": 0x0138, + "U_BAT_LOAD_OFF": 0x013c, + "LOAD_CURRENT_LIMIT_MA": 0x0140, + "LOAD_CURRENT_INRUSH_TIME": 0x0144, + "MIN_CHARGE_PUMP_EXCESS_VOLTAGE": 0x0148, + "LOAD_ON_DELAY": 0x014c, + "AVG_ALPHA_I_SOLAR": 0x0150, + "AVG_ALPHA_I_LOAD": 0x0154, + "AVG_ALPHA_U_BAT": 0x0158, + "AVG_ALPHA_U_SW": 0x015c, + "AVG_ALPHA_U_SOLAR": 0x0160, + "AVG_ALPHA_TEMP": 0x0164, + "DEEPSLEEP_DELAY": 0x0168, + "DEEPSLEEP_DURATION": 0x016c, } @@ -63,7 +65,7 @@ if __name__ == "__main__": for key, offset in CONFIG_KEY_TO_OFFSET.items(): value = config['config'][key] - enc_bytes = struct.pack('