L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
utils.h File Reference
#include <stdint.h>
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

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 Documentation

◆ TVAL

typedef uint8_t TVAL

Alias for the value type used by valueChanger_t (default: uint8_t).

Definition at line 95 of file utils.h.

Function Documentation

◆ clearFlash()

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).

Definition at line 94 of file utils.c.

◆ sleeper_Init()

void sleeper_Init ( sleeper_t * v,
uint32_t sleepMS )

Initialise the sleeper and start timing from now.

Parameters
vPointer to the sleeper_t instance to initialise.
sleepMSDuration 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleeper_IsElapsed()

int sleeper_IsElapsed ( const sleeper_t * v)

Check whether the configured time interval has elapsed.

Parameters
vPointer to a const sleeper_t instance.
Return values
1The time has elapsed (or SleepMS == 0 and Stop == 0).
0The 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleeper_IsElapsedNext()

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).

Parameters
vPointer to the sleeper_t instance.
Return values
1The time has elapsed; timer restarted for the next cycle.
0The time has not yet elapsed, or the timer is stopped.

Definition at line 26 of file utils.c.

References sleeper_IsElapsed(), and sleeper_Next().

Here is the call graph for this function:

◆ sleeper_IsElapsedStop()

int sleeper_IsElapsedStop ( sleeper_t * v)

Check whether the time has elapsed and, if so, stop the timer.

Note
Call sleeper_Next() to resume timing after this function returns 1.
Parameters
vPointer to the sleeper_t instance.
Return values
1The time has elapsed; timer is now stopped.
0The 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().

Here is the call graph for this function:

◆ sleeper_Next()

void sleeper_Next ( sleeper_t * v)

Restart the timer so the next period begins from now. InicTime is updated to the current HAL tick.

Parameters
vPointer 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleeper_SetSleepMS()

void sleeper_SetSleepMS ( sleeper_t * v,
uint32_t sleepMS )

Change the sleep duration and restart the timer from now.

Parameters
vPointer to the sleeper_t instance.
sleepMSNew 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleeper_Stop()

void sleeper_Stop ( sleeper_t * v)

Stop the timer so that all subsequent IsElapsed checks return 0.

Note
Call sleeper_Next() or sleeper_Init() to resume timing.
Parameters
vPointer to the sleeper_t instance.

Definition at line 56 of file utils.c.

References sleeper_t::Stop.

Referenced by sleeper_IsElapsedStop().

Here is the caller graph for this function:

◆ valueChanger_GetValue()

TVAL valueChanger_GetValue ( const valueChanger_t * v)

Return the most recently stored value.

Parameters
vPointer to a const valueChanger_t instance.
Returns
Current value held in LastValue.

Definition at line 87 of file utils.c.

References valueChanger_t::LastValue.

◆ valueChanger_Inic()

void valueChanger_Inic ( valueChanger_t * v,
TVAL inicValue,
uint32_t timeMS )

Initialise a valueChanger_t instance.

Parameters
vPointer to the valueChanger_t to initialise.
inicValueInitial value stored in LastValue.
timeMSStability 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.

Here is the call graph for this function:

◆ valueChanger_Lock()

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.

Parameters
vPointer to the valueChanger_t instance.

Definition at line 82 of file utils.c.

References valueChanger_t::IsLocked.

◆ valueChanger_SetValue()

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.

Parameters
vPointer to the valueChanger_t instance.
newValueThe latest sampled value.
Return values
1The value has remained unchanged for the full stability window.
0The 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.

Here is the call graph for this function: