2022-09-25 15:57:05 +02:00
|
|
|
#ifndef FLASH_CONFIG_H
|
|
|
|
#define FLASH_CONFIG_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2022-09-25 17:24:21 +02:00
|
|
|
#include <stdbool.h>
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
extern uint8_t __conf_start;
|
|
|
|
|
|
|
|
#define FLASH_CONFIG_BASE_PTR ((uint8_t*)(&__conf_start))
|
|
|
|
|
|
|
|
/***** Calibration factors *****/
|
|
|
|
|
|
|
|
/* Calibration factor defined here are divided by 1000 to determine the actual
|
|
|
|
* scaling factor. Therefore, if the voltage determined by the firmware is 2%
|
|
|
|
* lower than the actual voltage, you have to scale by 1.02 and therefore
|
|
|
|
* specify 1020 in this list. */
|
|
|
|
|
|
|
|
#define FLASH_CONFIG_CAL_FACTOR_U_BAT (*(uint16_t*)(FLASH_CONFIG_BASE_PTR + 0x0000))
|
|
|
|
#define FLASH_CONFIG_CAL_FACTOR_U_SOLAR (*(uint16_t*)(FLASH_CONFIG_BASE_PTR + 0x0002))
|
|
|
|
#define FLASH_CONFIG_CAL_FACTOR_U_SW (*(uint16_t*)(FLASH_CONFIG_BASE_PTR + 0x0004))
|
|
|
|
#define FLASH_CONFIG_CAL_FACTOR_I_SOLAR (*(uint16_t*)(FLASH_CONFIG_BASE_PTR + 0x0006))
|
|
|
|
#define FLASH_CONFIG_CAL_FACTOR_I_LOAD (*(uint16_t*)(FLASH_CONFIG_BASE_PTR + 0x0008))
|
|
|
|
|
|
|
|
/***** General configuration *****/
|
|
|
|
|
|
|
|
/* Battery regulation corridor width (in mV). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_REGULATION_CORRIDOR (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0100))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Initial charge battery voltage threshold (in mV). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_INITIAL_FULL (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0104))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Cancel initial charge voltage hold below this battery voltage (in mV). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_INITIAL_HOLD_CANCEL (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0108))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Transition to floating voltage levels after this time (in ms). */
|
|
|
|
#define FLASH_CONFIG_INITIAL_CHARGE_HOLD_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x010C))
|
|
|
|
|
|
|
|
/* Duration of the transistion from initial charging to float (in ms). */
|
|
|
|
#define FLASH_CONFIG_INITIAL_TO_FLOAT_TRANSITION_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0110))
|
|
|
|
|
|
|
|
/* Float charge battery voltage threshold (in mV). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_FLOAT_FULL (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0114))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Minimum voltage difference to U_bat that the solar panels must produce
|
|
|
|
* before charging is resumed after it was switched off (in mV). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_SLEEP_SOLAR_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0118))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Minimum charge current required before charging is stopped to save power at
|
|
|
|
* the charge pump (in mA). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_SLEEP_SOLAR_CURRENT (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x011C))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Delay between state change and sleep state check (in ms). */
|
|
|
|
#define FLASH_CONFIG_SLEEP_STATE_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0120))
|
|
|
|
|
|
|
|
/* Delay between charging switch state change and sleep state check(in ms). */
|
|
|
|
#define FLASH_CONFIG_SLEEP_SWITCH_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0124))
|
|
|
|
|
|
|
|
/* Maximum allowed microcontroller temperature (in units of 0.1 °C). If this
|
|
|
|
* temperature is exceeded, charging is stopped. The load is kept on. Do not
|
|
|
|
* set this too high as the heat has to propagate from the power MOSFETs. */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_INTERNAL_TEMPERATURE_LIMIT (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0128))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Resume operation below this temperature (in units of 0.1 °C). */
|
2022-09-25 17:24:21 +02:00
|
|
|
#define FLASH_CONFIG_INTERNAL_TEMPERATURE_RECOVERY (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x012C))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
2022-10-15 21:42:46 +02:00
|
|
|
/* 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))
|
|
|
|
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Thresholds for load control */
|
|
|
|
|
|
|
|
/* Voltage above which the load is turned on (in mV). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_LOAD_ON (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0138))
|
2022-09-25 15:57:05 +02:00
|
|
|
/* Voltage below which the load is turned off (in mV). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_U_BAT_LOAD_OFF (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x013c))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Current at which the overload protection triggers (in mA). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_LOAD_CURRENT_LIMIT_MA (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0140))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Inrush tolerance time (in ms). Overload protection is not enforced for this
|
|
|
|
* time after load power-on. */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_LOAD_CURRENT_INRUSH_TIME (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0144))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Minimum voltage that the charge pump must produce above U_bat before any
|
|
|
|
* power FET is switched on (in mV). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_MIN_CHARGE_PUMP_EXCESS_VOLTAGE (*(int32_t*)(FLASH_CONFIG_BASE_PTR + 0x0148))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* The minimum time the load must be off before it can be switched on again (in ms). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_LOAD_ON_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x014c))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Measurement Averaging:
|
|
|
|
* Alpha is specified in units of 1/1000. 1000 means that only the latest
|
|
|
|
* value is relevant, 0 means that the measurement has no influence. The latter
|
|
|
|
* is useless.
|
|
|
|
*
|
|
|
|
* The formula to calculate the next averaged value avg from a measurement meas is:
|
|
|
|
* avg[k] = meas * (alpha/1000) + avg[k-1] * (1 - alpha/1000)
|
|
|
|
*
|
|
|
|
* For overload protection (battery voltage, load current), the latest values
|
|
|
|
* are always used.
|
|
|
|
* */
|
|
|
|
|
|
|
|
/* Averaging factor for load current. */
|
2022-10-15 21:42:46 +02:00
|
|
|
#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))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Generic configuration */
|
|
|
|
|
|
|
|
/* Time (in ms) to stay active in idle state before entering deep sleep. */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_DEEPSLEEP_DELAY (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x0168))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
|
|
|
/* Deep sleep duration (in seconds). */
|
2022-10-15 21:42:46 +02:00
|
|
|
#define FLASH_CONFIG_DEEPSLEEP_DURATION (*(uint32_t*)(FLASH_CONFIG_BASE_PTR + 0x016c))
|
2022-09-25 15:57:05 +02:00
|
|
|
|
2022-09-25 17:24:21 +02:00
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
|
|
|
bool flash_config_is_present(void);
|
|
|
|
|
2022-09-25 15:57:05 +02:00
|
|
|
#endif // FLASH_CONFIG_H
|