|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | sleeper_t |
| Non-blocking timer utility – similar to HAL_Delay but without CPU blocking. More... | |
| struct | valueChanger_t |
| Value-stability detector – determines when a periodically updated value has remained unchanged for a configured time window. More... | |
Typedefs | |
| typedef uint8_t | TVAL |
| Alias for the value type used by valueChanger_t (default: uint8_t). | |
Functions | |
| void | sleeper_Init (sleeper_t *v, uint32_t sleepMS) |
| Initialise the sleeper and start timing from now. | |
| int | sleeper_IsElapsed (const sleeper_t *v) |
| Check whether the configured time interval has elapsed. | |
| int | sleeper_IsElapsedNext (sleeper_t *v) |
| Check whether the time has elapsed and, if so, restart the timer for the next period (InicTime advances by SleepMS to avoid drift). | |
| void | sleeper_Next (sleeper_t *v) |
| Restart the timer so the next period begins from now. InicTime is updated to the current HAL tick. | |
| void | sleeper_SetSleepMS (sleeper_t *v, uint32_t sleepMS) |
| Change the sleep duration and restart the timer from now. | |
| int | sleeper_IsElapsedStop (sleeper_t *v) |
| Check whether the time has elapsed and, if so, stop the timer. | |
| void | sleeper_Stop (sleeper_t *v) |
| Stop the timer so that all subsequent IsElapsed checks return 0. | |
| void | valueChanger_Inic (valueChanger_t *v, TVAL inicValue, uint32_t timeMS) |
| Initialise a valueChanger_t instance. | |
| int | valueChanger_SetValue (valueChanger_t *v, TVAL newValue) |
| Submit a new value sample and check for stability. | |
| void | valueChanger_Lock (valueChanger_t *v) |
| Lock the valueChanger_t so that SetValue always returns 0. The lock is cleared automatically the next time SetValue receives a value different from LastValue. | |
| TVAL | valueChanger_GetValue (const valueChanger_t *v) |
| Return the most recently stored value. | |
| void | clearFlash () |
| Erase the external flash memory signature so that the next boot forces a full re-initialisation (used when flashing a new firmware version that changes persistent data structures). | |
| typedef uint8_t TVAL |
Alias for the value type used by valueChanger_t (default: uint8_t).
| void clearFlash | ( | ) |
| void sleeper_Init | ( | sleeper_t * | v, |
| uint32_t | sleepMS ) |
Initialise the sleeper and start timing from now.
| v | Pointer to the sleeper_t instance to initialise. |
| sleepMS | Duration in milliseconds after which IsElapsed returns 1. Pass 0 to create a stopped / instant timer. |
Definition at line 13 of file utils.c.
References sleeper_t::InicTime, sleeper_SetSleepMS(), sleeper_t::SleepMS, and sleeper_t::Stop.
Referenced by sps30_Service(), and valueChanger_Inic().
| int sleeper_IsElapsed | ( | const sleeper_t * | v | ) |
Check whether the configured time interval has elapsed.
| v | Pointer to a const sleeper_t instance. |
| 1 | The time has elapsed (or SleepMS == 0 and Stop == 0). |
| 0 | The time has not yet elapsed, or the timer is stopped. |
Definition at line 21 of file utils.c.
References HAL_GetTick(), sleeper_t::InicTime, sleeper_t::SleepMS, and sleeper_t::Stop.
Referenced by sensors_Work(), sleeper_IsElapsedNext(), sleeper_IsElapsedStop(), sps30_Service(), and valueChanger_SetValue().
| int sleeper_IsElapsedNext | ( | sleeper_t * | v | ) |
Check whether the time has elapsed and, if so, restart the timer for the next period (InicTime advances by SleepMS to avoid drift).
| v | Pointer to the sleeper_t instance. |
| 1 | The time has elapsed; timer restarted for the next cycle. |
| 0 | The time has not yet elapsed, or the timer is stopped. |
Definition at line 26 of file utils.c.
References sleeper_IsElapsed(), and sleeper_Next().
| int sleeper_IsElapsedStop | ( | sleeper_t * | v | ) |
Check whether the time has elapsed and, if so, stop the timer.
| v | Pointer to the sleeper_t instance. |
| 1 | The time has elapsed; timer is now stopped. |
| 0 | The time has not yet elapsed, or the timer was already stopped. |
Definition at line 47 of file utils.c.
References sleeper_IsElapsed(), and sleeper_Stop().
| void sleeper_Next | ( | sleeper_t * | v | ) |
Restart the timer so the next period begins from now. InicTime is updated to the current HAL tick.
| v | Pointer to the sleeper_t instance. |
Definition at line 35 of file utils.c.
References HAL_GetTick(), sleeper_t::InicTime, and sleeper_t::Stop.
Referenced by sensors_Work(), sleeper_IsElapsedNext(), sleeper_SetSleepMS(), and valueChanger_SetValue().
| void sleeper_SetSleepMS | ( | sleeper_t * | v, |
| uint32_t | sleepMS ) |
Change the sleep duration and restart the timer from now.
| v | Pointer to the sleeper_t instance. |
| sleepMS | New duration in milliseconds. |
Definition at line 41 of file utils.c.
References sleeper_Next(), and sleeper_t::SleepMS.
Referenced by sensors_Start(), sensors_Work(), and sleeper_Init().
| void sleeper_Stop | ( | sleeper_t * | v | ) |
Stop the timer so that all subsequent IsElapsed checks return 0.
| v | Pointer to the sleeper_t instance. |
Definition at line 56 of file utils.c.
References sleeper_t::Stop.
Referenced by sleeper_IsElapsedStop().
| TVAL valueChanger_GetValue | ( | const valueChanger_t * | v | ) |
Return the most recently stored value.
| v | Pointer to a const valueChanger_t instance. |
Definition at line 87 of file utils.c.
References valueChanger_t::LastValue.
| void valueChanger_Inic | ( | valueChanger_t * | v, |
| TVAL | inicValue, | ||
| uint32_t | timeMS ) |
Initialise a valueChanger_t instance.
| v | Pointer to the valueChanger_t to initialise. |
| inicValue | Initial value stored in LastValue. |
| timeMS | Stability window in milliseconds; SetValue returns 1 only after the value has been unchanged for this duration. |
Definition at line 64 of file utils.c.
References valueChanger_t::IsLocked, valueChanger_t::LastValue, sleeper_Init(), and valueChanger_t::Timer.
| void valueChanger_Lock | ( | valueChanger_t * | v | ) |
Lock the valueChanger_t so that SetValue always returns 0. The lock is cleared automatically the next time SetValue receives a value different from LastValue.
| v | Pointer to the valueChanger_t instance. |
Definition at line 82 of file utils.c.
References valueChanger_t::IsLocked.
| int valueChanger_SetValue | ( | valueChanger_t * | v, |
| TVAL | newValue ) |
Submit a new value sample and check for stability.
If newValue differs from LastValue, LastValue is updated, the stability timer is restarted, and the instance is unlocked. If newValue equals LastValue and the stability timer has elapsed, 1 is returned to signal that the value has been stable for the full window.
| v | Pointer to the valueChanger_t instance. |
| newValue | The latest sampled value. |
| 1 | The value has remained unchanged for the full stability window. |
| 0 | The value changed, the timer has not elapsed, or the instance is locked. |
Definition at line 71 of file utils.c.
References valueChanger_t::IsLocked, valueChanger_t::LastValue, sleeper_IsElapsed(), sleeper_Next(), and valueChanger_t::Timer.