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

This file contains the RTC-based scheduler definitions, structures and function prototypes. More...

#include "stm32l4xx_hal.h"

Go to the source code of this file.

Data Structures

struct  Job_t
 
struct  Scheduler_t
 

Macros

#define MAX_NUM_OF_JOBS   10U
 

Typedefs

typedef void(* Callback_t) (void)
 

Functions

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

Detailed Description

This file contains the RTC-based scheduler definitions, structures and function prototypes.

STM32 RTC Scheduler

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

Definition in file scheduler.h.

Macro Definition Documentation

◆ MAX_NUM_OF_JOBS

#define MAX_NUM_OF_JOBS   10U

Maximum number of jobs that are allowed to be configured

Definition at line 27 of file scheduler.h.

Typedef Documentation

◆ Callback_t

typedef void(* Callback_t) (void)

Shorthand type for callback functions

Definition at line 31 of file scheduler.h.

Function Documentation

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