STM32 RTC Scheduler
RTC-based scheduler for ultra-low power applications
scheduler.c File Reference

This file contains the RTC-based scheduler function implementations. More...

#include "scheduler.h"
#include "rtc.h"

Go to the source code of this file.

Functions

void Scheduler_ProcessRemainingTime (const uint32_t elapsedTime)
 This function calculates the remaining time for each job. More...
 
void SchedulerInit (void)
 Initialize the scheduler by setting its structure values to zero.
 
uint8_t SchedulerAddJob (const uint32_t period, const Callback_t callback)
 Add a new job to the scheduler. More...
 
void SchedulerProcess (void)
 Process the scheduler. More...
 
void SchedulerExecutePendingJobs (void)
 Execute the pending jobs. More...
 
void SchedulerStop (void)
 Stop the scheduler. More...
 

Variables

Scheduler_t scheduler
 

Detailed Description

This file contains the RTC-based scheduler function implementations.

STM32 RTC Scheduler

Author
Akos Pasztor
See also
Please refer to README for detailed information.

Definition in file scheduler.c.

Function Documentation

◆ Scheduler_ProcessRemainingTime()

void Scheduler_ProcessRemainingTime ( const uint32_t  elapsedTime)

This function calculates the remaining time for each job.

Parameters
elapsedTimeThe elapsed time since the launch of the scheduler.

Definition at line 220 of file scheduler.c.

◆ SchedulerAddJob()

uint8_t SchedulerAddJob ( const uint32_t  period,
const Callback_t  callback 
)

Add a new job to the scheduler.

Parameters
periodThe period in [s] which the job needs to be executed.
callbackThe callback function that is called upon job execution.
Returns
A non-zero value if the job has been successfully added; othwerwise zero.

Definition at line 43 of file scheduler.c.

◆ SchedulerExecutePendingJobs()

void SchedulerExecutePendingJobs ( void  )

Execute the pending jobs.

This function checks the current state of each job. If a job is pending, its callback is executed.

Note
The processing function of the scheduler does not automatically execute the callbacks of the pending jobs. Therefore, this function must be called after calling the processing function of the scheduler.
Warning
Depending on the implementation, this function may be called from an interrupt context, or a task context (or both). Consequently, the callback functions of the jobs are executed from the same context. This must be taken into account, i.e. care must be taken upon writing the callbacks of the jobs. For instance, calling this function from an ISR means that the jobs are also executed within the context of the ISR, thus the callbacks must not block and they can only call interrupt-safe RTOS API functions.

Definition at line 159 of file scheduler.c.

◆ SchedulerProcess()

void SchedulerProcess ( void  )

Process the scheduler.

This function needs to be called each time upon an RTC alarm interrupt. The function checks all jobs whether they need to be executed and sets the appropriate pending flags.

Note
The function does not automatically execute the callbacks of the pending jobs to provide more flexibility for the application. The pending jobs can be executed by calling the SchedulerExecutePendingJobs() function.

Definition at line 85 of file scheduler.c.

◆ SchedulerStop()

void SchedulerStop ( void  )

Stop the scheduler.

This function stops the running scheduler and deactivates the RTC alarm. The function also processes the jobs.

Note
The function does not automatically execute the callbacks of the pending jobs to provide more flexibility for the application. The pending jobs can be executed by calling the SchedulerExecutePendingJobs() function.

Definition at line 188 of file scheduler.c.

Variable Documentation

◆ scheduler

Scheduler_t scheduler

The scheduler object

Definition at line 20 of file scheduler.c.