|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Implementation of the low-battery nag policy. More...
Go to the source code of this file.
Functions | |
| ra8_err_t | ra8_batt_monitor_init (ra8_batt_monitor_t *mon) |
| Reset a nag monitor to the un-nagged, fully-armed state. | |
| ra8_err_t | ra8_batt_update (ra8_batt_monitor_t *mon, uint8_t soc_pct, bool charging, ra8_batt_nag_t *out_nag) |
| Fold one SOC reading into the monitor and report the nag to raise. | |
| const char * | ra8_batt_nag_str (ra8_batt_nag_t nag) |
| Map a nag level to a short, stable upper-case label. | |
Variables | |
| static const char *const | s_tag = "ra8_batt" |
| Component tag for diagnostic logging. | |
Implementation of the low-battery nag policy.
Edge-triggered band detection with hysteresis. See ra8_batt.h for the contract. Pure logic: no loop, no recursion, no allocation, no MMIO.
Definition in file ra8_batt.c.
| ra8_err_t ra8_batt_monitor_init | ( | ra8_batt_monitor_t * | mon | ) |
Reset a nag monitor to the un-nagged, fully-armed state.
Writes zero to both band-raised flags inside mon, placing the monitor into the fully-armed state so that the first subsequent call to ra8_batt_update can raise either the low or critical nag. The operation is a single struct clear with no loops, no allocation, and no hardware access, making it safe to call from any initialisation context on both the RA8D2 target and the host unit-test harness.
| [out] | mon | Monitor to initialise. |
| k_ra8_ok | Monitor zeroed; both bands armed. |
| k_ra8_err_null_ptr | mon is nullptr. |
mon points to writable storage. Definition at line 27 of file ra8_batt.c.
References ra8_batt_monitor_t::critical_raised, k_ra8_ok, ra8_batt_monitor_t::low_raised, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by main().
| const char * ra8_batt_nag_str | ( | ra8_batt_nag_t | nag | ) |
Map a nag level to a short, stable upper-case label.
| [in] | nag | Nag level. |
| OK | For k_ra8_batt_nag_none. |
| LOW | For k_ra8_batt_nag_low. |
| CRITICAL | For k_ra8_batt_nag_critical. |
| ? | For any out-of-range value. |
Definition at line 71 of file ra8_batt.c.
References k_ra8_batt_nag_critical, k_ra8_batt_nag_low, k_ra8_batt_nag_none, and RA8_ASSERT.
| ra8_err_t ra8_batt_update | ( | ra8_batt_monitor_t * | mon, |
| uint8_t | soc_pct, | ||
| bool | charging, | ||
| ra8_batt_nag_t * | out_nag ) |
Fold one SOC reading into the monitor and report the nag to raise.
Re-arms each band when charging or when soc_pct has recovered above the band threshold by k_ra8_batt_rearm_margin, then, only while not charging, raises the low and/or critical band the reading newly enters. When a reading enters both bands at once (a large drop), the returned nag is the worse one (k_ra8_batt_nag_critical). soc_pct above k_ra8_batt_pct_max is clamped.
| [in,out] | mon | Monitor state (updated in place). |
| [in] | soc_pct | Current state-of-charge percent (clamped to 0..100). |
| [in] | charging | True when the fuel gauge reports a charging rate. |
| [out] | out_nag | Receives the nag to surface this step. |
| k_ra8_ok | Step folded; out_nag written. |
| k_ra8_err_null_ptr | mon or out_nag is nullptr. |
mon was initialised by ra8_batt_monitor_init. out_nag points to writable storage. out_nag holds one of ra8_batt_nag_t. Definition at line 36 of file ra8_batt.c.
References ra8_batt_monitor_t::critical_raised, k_ra8_batt_critical_pct, k_ra8_batt_low_pct, k_ra8_batt_nag_critical, k_ra8_batt_nag_low, k_ra8_batt_nag_none, k_ra8_batt_pct_max, k_ra8_batt_rearm_margin, k_ra8_ok, ra8_batt_monitor_t::low_raised, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by er_poll_battery(), and main().
|
static |
Component tag for diagnostic logging.
Definition at line 25 of file ra8_batt.c.