L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
timer_if.c File Reference

Configure RTC Alarm, Tick and Calendar manager. More...

#include <math.h>
#include "timer_if.h"
#include "main.h"
#include "rtc.h"
#include "utilities_def.h"
#include "stm32wlxx_ll_rtc.h"
Include dependency graph for timer_if.c:

Go to the source code of this file.

Macros

#define MIN_ALARM_DELAY   3
 Minimum timeout delay of Alarm in ticks.
#define RTC_BKP_SECONDS   RTC_BKP_DR0
 Backup seconds register.
#define RTC_BKP_SUBSECONDS   RTC_BKP_DR1
 Backup subseconds register.
#define RTC_BKP_MSBTICKS   RTC_BKP_DR2
 Backup msbticks register.
#define UTIL_TIMER_IRQ_MAP_INIT()
 Map UTIL_TIMER_IRQ can be overridden in utilities_conf.h to Map on Task rather then Isr.
#define UTIL_TIMER_IRQ_MAP_PROCESS()
#define TIMER_IF_DBG_PRINTF(...)
 not used

Functions

static uint32_t GetTimerTicks (void)
 Get rtc timer Value in rtc tick.
static void TIMER_IF_BkUp_Write_MSBticks (uint32_t MSBticks)
 Writes MSBticks to backup register Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter).
static uint32_t TIMER_IF_BkUp_Read_MSBticks (void)
 Reads MSBticks from backup register Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter).
UTIL_TIMER_Status_t TIMER_IF_Init (void)
 Init RTC hardware.
UTIL_TIMER_Status_t TIMER_IF_StartTimer (uint32_t timeout)
 Set the alarm.
UTIL_TIMER_Status_t TIMER_IF_StopTimer (void)
 Stop the Alarm.
uint32_t TIMER_IF_SetTimerContext (void)
 set timer Reference (TimerContext)
uint32_t TIMER_IF_GetTimerContext (void)
 Get the RTC timer Reference.
uint32_t TIMER_IF_GetTimerElapsedTime (void)
 Get the timer elapsed time since timer Reference (TimerContext) was set.
uint32_t TIMER_IF_GetTimerValue (void)
 Get the timer value.
uint32_t TIMER_IF_GetMinimumTimeout (void)
 Return the minimum timeout in ticks the RTC is able to handle.
uint32_t TIMER_IF_Convert_ms2Tick (uint32_t timeMilliSec)
 converts time in ms to time in ticks
uint32_t TIMER_IF_Convert_Tick2ms (uint32_t tick)
 converts time in ticks to time in ms
void TIMER_IF_DelayMs (uint32_t delay)
 a delay of delay ms by polling RTC
void HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef *hrtc)
void HAL_RTCEx_SSRUEventCallback (RTC_HandleTypeDef *hrtc)
uint32_t TIMER_IF_GetTime (uint16_t *mSeconds)
 Get rtc time.
void TIMER_IF_BkUp_Write_Seconds (uint32_t Seconds)
 write seconds in backUp register
void TIMER_IF_BkUp_Write_SubSeconds (uint32_t SubSeconds)
 writes SubSeconds in backUp register
uint32_t TIMER_IF_BkUp_Read_Seconds (void)
 reads seconds from backUp register
uint32_t TIMER_IF_BkUp_Read_SubSeconds (void)
 reads SubSeconds from backUp register

Variables

RTC_HandleTypeDef hrtc
 RTC handle.
const UTIL_TIMER_Driver_s UTIL_TimerDriver
 Timer driver callbacks handler.
const UTIL_SYSTIM_Driver_s UTIL_SYSTIMDriver
 SysTime driver callbacks handler.
static bool RTC_Initialized = false
 Indicates if the RTC is already Initialized or not.
static uint32_t RtcTimerContext = 0
 RtcTimerContext.

Detailed Description

Configure RTC Alarm, Tick and Calendar manager.

Author
MCD Application Team
Attention

Copyright (c) 2026 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

Definition in file timer_if.c.

Macro Definition Documentation

◆ MIN_ALARM_DELAY

#define MIN_ALARM_DELAY   3

Minimum timeout delay of Alarm in ticks.

Definition at line 86 of file timer_if.c.

Referenced by TIMER_IF_GetMinimumTimeout().

◆ RTC_BKP_MSBTICKS

#define RTC_BKP_MSBTICKS   RTC_BKP_DR2

Backup msbticks register.

Definition at line 101 of file timer_if.c.

Referenced by TIMER_IF_BkUp_Read_MSBticks(), and TIMER_IF_BkUp_Write_MSBticks().

◆ RTC_BKP_SECONDS

#define RTC_BKP_SECONDS   RTC_BKP_DR0

Backup seconds register.

Definition at line 91 of file timer_if.c.

Referenced by TIMER_IF_BkUp_Read_Seconds(), and TIMER_IF_BkUp_Write_Seconds().

◆ RTC_BKP_SUBSECONDS

#define RTC_BKP_SUBSECONDS   RTC_BKP_DR1

Backup subseconds register.

Definition at line 96 of file timer_if.c.

Referenced by TIMER_IF_BkUp_Read_SubSeconds(), and TIMER_IF_BkUp_Write_SubSeconds().

◆ TIMER_IF_DBG_PRINTF

#define TIMER_IF_DBG_PRINTF ( ...)

◆ UTIL_TIMER_IRQ_MAP_INIT

#define UTIL_TIMER_IRQ_MAP_INIT ( )

Map UTIL_TIMER_IRQ can be overridden in utilities_conf.h to Map on Task rather then Isr.

Definition at line 109 of file timer_if.c.

Referenced by TIMER_IF_Init().

◆ UTIL_TIMER_IRQ_MAP_PROCESS

#define UTIL_TIMER_IRQ_MAP_PROCESS ( )
Value:
UTIL_TIMER_IRQ_Handler()

Definition at line 113 of file timer_if.c.

Referenced by HAL_RTC_AlarmAEventCallback().

Function Documentation

◆ GetTimerTicks()

uint32_t GetTimerTicks ( void )
inlinestatic

Get rtc timer Value in rtc tick.

Returns
val the rtc timer value (upcounting)

Definition at line 504 of file timer_if.c.

Referenced by HAL_RTCEx_SSRUEventCallback(), TIMER_IF_DelayMs(), TIMER_IF_GetTime(), TIMER_IF_GetTimerElapsedTime(), TIMER_IF_GetTimerValue(), TIMER_IF_SetTimerContext(), and TIMER_IF_StartTimer().

Here is the caller graph for this function:

◆ HAL_RTC_AlarmAEventCallback()

void HAL_RTC_AlarmAEventCallback ( RTC_HandleTypeDef * hrtc)

Definition at line 377 of file timer_if.c.

References hrtc, and UTIL_TIMER_IRQ_MAP_PROCESS.

◆ HAL_RTCEx_SSRUEventCallback()

void HAL_RTCEx_SSRUEventCallback ( RTC_HandleTypeDef * hrtc)

Definition at line 388 of file timer_if.c.

References GetTimerTicks(), hrtc, TIMER_IF_BkUp_Read_MSBticks(), TIMER_IF_BkUp_Write_MSBticks(), and TIMER_IF_DBG_PRINTF.

Here is the call graph for this function:

◆ TIMER_IF_BkUp_Read_MSBticks()

uint32_t TIMER_IF_BkUp_Read_MSBticks ( void )
static

Reads MSBticks from backup register Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter).

Note
MSBticks incremented every time the 32bits RTC timer wraps around (~44days)
Return values
MSBticks

Definition at line 491 of file timer_if.c.

References hrtc, and RTC_BKP_MSBTICKS.

Referenced by HAL_RTCEx_SSRUEventCallback(), and TIMER_IF_GetTime().

Here is the caller graph for this function:

◆ TIMER_IF_BkUp_Read_Seconds()

uint32_t TIMER_IF_BkUp_Read_Seconds ( void )

reads seconds from backUp register

Note
Used to store seconds difference between RTC time and Unix time
Returns
Time in seconds

Definition at line 449 of file timer_if.c.

References hrtc, and RTC_BKP_SECONDS.

◆ TIMER_IF_BkUp_Read_SubSeconds()

uint32_t TIMER_IF_BkUp_Read_SubSeconds ( void )

reads SubSeconds from backUp register

Note
Used to store SubSeconds difference between RTC time and Unix time
Returns
Time in SubSeconds

Definition at line 462 of file timer_if.c.

References hrtc, and RTC_BKP_SUBSECONDS.

◆ TIMER_IF_BkUp_Write_MSBticks()

void TIMER_IF_BkUp_Write_MSBticks ( uint32_t MSBticks)
static

Writes MSBticks to backup register Absolute RTC time in tick is (MSBticks)<<32 + (32bits binary counter).

Note
MSBticks incremented every time the 32bits RTC timer wraps around (~44days)
Parameters
[in]MSBticks

Definition at line 480 of file timer_if.c.

References hrtc, and RTC_BKP_MSBTICKS.

Referenced by HAL_RTCEx_SSRUEventCallback(), and TIMER_IF_Init().

Here is the caller graph for this function:

◆ TIMER_IF_BkUp_Write_Seconds()

void TIMER_IF_BkUp_Write_Seconds ( uint32_t Seconds)

write seconds in backUp register

Note
Used to store seconds difference between RTC time and Unix time
Parameters
[in]Secondstime in seconds

Definition at line 427 of file timer_if.c.

References hrtc, and RTC_BKP_SECONDS.

◆ TIMER_IF_BkUp_Write_SubSeconds()

void TIMER_IF_BkUp_Write_SubSeconds ( uint32_t SubSeconds)

writes SubSeconds in backUp register

Note
Used to store SubSeconds difference between RTC time and Unix time
Parameters
[in]SubSecondstime in SubSeconds

Definition at line 438 of file timer_if.c.

References hrtc, and RTC_BKP_SUBSECONDS.

◆ TIMER_IF_Convert_ms2Tick()

uint32_t TIMER_IF_Convert_ms2Tick ( uint32_t timeMilliSec)

converts time in ms to time in ticks

Parameters
[in]timeMilliSectime in milliseconds
Returns
time in timer ticks

Definition at line 333 of file timer_if.c.

References RTC_N_PREDIV_S.

Referenced by TIMER_IF_DelayMs().

Here is the caller graph for this function:

◆ TIMER_IF_Convert_Tick2ms()

uint32_t TIMER_IF_Convert_Tick2ms ( uint32_t tick)

converts time in ticks to time in ms

Parameters
[in]ticktime in timer ticks
Returns
time in timer milliseconds

Definition at line 346 of file timer_if.c.

References RTC_N_PREDIV_S.

Referenced by TIMER_IF_GetTime().

Here is the caller graph for this function:

◆ TIMER_IF_DelayMs()

void TIMER_IF_DelayMs ( uint32_t delay)

a delay of delay ms by polling RTC

Parameters
delayin ms

Definition at line 359 of file timer_if.c.

References GetTimerTicks(), and TIMER_IF_Convert_ms2Tick().

Referenced by HAL_Delay().

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

◆ TIMER_IF_GetMinimumTimeout()

uint32_t TIMER_IF_GetMinimumTimeout ( void )

Return the minimum timeout in ticks the RTC is able to handle.

Returns
minimum value for a timeout in ticks

Definition at line 320 of file timer_if.c.

References MIN_ALARM_DELAY.

◆ TIMER_IF_GetTime()

uint32_t TIMER_IF_GetTime ( uint16_t * subSeconds)

Get rtc time.

Parameters
[out]subSecondsin ticks
Returns
time seconds

Definition at line 403 of file timer_if.c.

References GetTimerTicks(), RTC_N_PREDIV_S, RTC_PREDIV_S, TIMER_IF_BkUp_Read_MSBticks(), and TIMER_IF_Convert_Tick2ms().

Here is the call graph for this function:

◆ TIMER_IF_GetTimerContext()

uint32_t TIMER_IF_GetTimerContext ( void )

Get the RTC timer Reference.

Returns
Timer Value in Ticks

Definition at line 280 of file timer_if.c.

References RtcTimerContext, and TIMER_IF_DBG_PRINTF.

◆ TIMER_IF_GetTimerElapsedTime()

uint32_t TIMER_IF_GetTimerElapsedTime ( void )

Get the timer elapsed time since timer Reference (TimerContext) was set.

Returns
RTC Elapsed time in ticks

Definition at line 291 of file timer_if.c.

References GetTimerTicks(), and RtcTimerContext.

Here is the call graph for this function:

◆ TIMER_IF_GetTimerValue()

uint32_t TIMER_IF_GetTimerValue ( void )

Get the timer value.

Returns
RTC Timer value in ticks

Definition at line 304 of file timer_if.c.

References GetTimerTicks(), and RTC_Initialized.

Referenced by HAL_GetTick().

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

◆ TIMER_IF_Init()

UTIL_TIMER_Status_t TIMER_IF_Init ( void )

Init RTC hardware.

Returns
Status based on UTIL_TIMER_Status_t

DeActivate the Alarm A enabled by STM32CubeMX during MX_RTC_Init()

Definition at line 183 of file timer_if.c.

References hrtc, MX_RTC_Init(), RTC_Initialized, TIMER_IF_BkUp_Write_MSBticks(), TIMER_IF_SetTimerContext(), TIMER_IF_StopTimer(), and UTIL_TIMER_IRQ_MAP_INIT.

Here is the call graph for this function:

◆ TIMER_IF_SetTimerContext()

uint32_t TIMER_IF_SetTimerContext ( void )

set timer Reference (TimerContext)

Returns
Timer Reference Value in Ticks

Definition at line 266 of file timer_if.c.

References GetTimerTicks(), RtcTimerContext, and TIMER_IF_DBG_PRINTF.

Referenced by TIMER_IF_Init().

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

◆ TIMER_IF_StartTimer()

UTIL_TIMER_Status_t TIMER_IF_StartTimer ( uint32_t timeout)

Set the alarm.

Note
The alarm is set at timeout from timer Reference (TimerContext)
Parameters
timeoutDuration of the Timer in ticks
Returns
Status based on UTIL_TIMER_Status_t

Definition at line 220 of file timer_if.c.

References Error_Handler(), GetTimerTicks(), hrtc, RtcTimerContext, TIMER_IF_DBG_PRINTF, and TIMER_IF_StopTimer().

Here is the call graph for this function:

◆ TIMER_IF_StopTimer()

UTIL_TIMER_Status_t TIMER_IF_StopTimer ( void )

Stop the Alarm.

Returns
Status based on UTIL_TIMER_Status_t

Definition at line 248 of file timer_if.c.

References hrtc.

Referenced by TIMER_IF_Init(), and TIMER_IF_StartTimer().

Here is the caller graph for this function:

Variable Documentation

◆ hrtc

RTC_HandleTypeDef hrtc
extern

RTC handle.

Definition at line 27 of file rtc.c.

◆ RTC_Initialized

bool RTC_Initialized = false
static

Indicates if the RTC is already Initialized or not.

Definition at line 144 of file timer_if.c.

Referenced by TIMER_IF_GetTimerValue(), and TIMER_IF_Init().

◆ RtcTimerContext

uint32_t RtcTimerContext = 0
static

◆ UTIL_SYSTIMDriver

const UTIL_SYSTIM_Driver_s UTIL_SYSTIMDriver
Initial value:
=
{
}
uint32_t TIMER_IF_GetTime(uint16_t *subSeconds)
Get rtc time.
Definition timer_if.c:403
uint32_t TIMER_IF_BkUp_Read_Seconds(void)
reads seconds from backUp register
Definition timer_if.c:449
void TIMER_IF_BkUp_Write_Seconds(uint32_t Seconds)
write seconds in backUp register
Definition timer_if.c:427
uint32_t TIMER_IF_BkUp_Read_SubSeconds(void)
reads SubSeconds from backUp register
Definition timer_if.c:462
void TIMER_IF_BkUp_Write_SubSeconds(uint32_t SubSeconds)
writes SubSeconds in backUp register
Definition timer_if.c:438

SysTime driver callbacks handler.

Definition at line 64 of file timer_if.c.

◆ UTIL_TimerDriver

const UTIL_TIMER_Driver_s UTIL_TimerDriver
Initial value:
=
{
NULL,
}
uint32_t TIMER_IF_Convert_ms2Tick(uint32_t timeMilliSec)
converts time in ms to time in ticks
Definition timer_if.c:333
uint32_t TIMER_IF_Convert_Tick2ms(uint32_t tick)
converts time in ticks to time in ms
Definition timer_if.c:346
uint32_t TIMER_IF_GetTimerElapsedTime(void)
Get the timer elapsed time since timer Reference (TimerContext) was set.
Definition timer_if.c:291
uint32_t TIMER_IF_GetTimerValue(void)
Get the timer value.
Definition timer_if.c:304
UTIL_TIMER_Status_t TIMER_IF_StopTimer(void)
Stop the Alarm.
Definition timer_if.c:248
uint32_t TIMER_IF_GetMinimumTimeout(void)
Return the minimum timeout in ticks the RTC is able to handle.
Definition timer_if.c:320
UTIL_TIMER_Status_t TIMER_IF_StartTimer(uint32_t timeout)
Set the alarm.
Definition timer_if.c:220
uint32_t TIMER_IF_SetTimerContext(void)
set timer Reference (TimerContext)
Definition timer_if.c:266
UTIL_TIMER_Status_t TIMER_IF_Init(void)
Init RTC hardware.
Definition timer_if.c:183
uint32_t TIMER_IF_GetTimerContext(void)
Get the RTC timer Reference.
Definition timer_if.c:280

Timer driver callbacks handler.

Definition at line 42 of file timer_if.c.