px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_sysclk.h : System Clock using a SysTick peripheral

Description

Driver to initalise SysTick peripheral so that a periodic system clock tick interrupt is generated.

File(s):

px_sysclk_init() configures SysTick to expire every 1/PX_SYSCLK_TICKS_PER_SEC second and generate an interrupt during which a clock tick counter is incremented. px_sysclk_get_tick_count() must be called to fetch a copy of the clock tick counter in an interrupt safe way (atomically).

A periodic timeout function can also be called by the system clock timer interrupt, for example a software RTC can be implemented by calling an RTC update function once a second. The period is specified in 'px_sysclk_cfg.h' with PX_SYSCLK_TIMEOUT_PERIOD_TICKS and the function to call with.

See px_systmr.h : Polled software timers which builds on px_sysclk.h : System Clock using a SysTick peripheral to provide multiple software timers. Example:

#include "px_sysclk.h"
#include "px_systmr.h"
#include "px_compiler.h"
void px_systmr_test(void)
{
// Create a timer object
// Initialise module
// Enable interrupts
px_interrupts_enable();
// Start timer with a 250 ms timeout
px_systmr_start(&tmr, TMR_MS_TO_TICKS(250));
// Loop forever
while(true)
{
// Wait until timer has expired
while(!px_systmr_has_expired(&tmr))
{
;
}
// Restart timer
// Do someting...
}
}
void px_systmr_start(px_systmr_t *systmr, const px_systmr_ticks_t delay_in_ticks)
Start a timer.
Definition: px_systmr.c:35
void px_systmr_restart(px_systmr_t *systmr)
Restart a timer with the delay set with px_systmr_start().
Definition: px_systmr.c:109
bool px_systmr_has_expired(px_systmr_t *systmr)
See if a timer has expired.
Definition: px_systmr.c:57
Structure to track state of a timer.
Definition: px_systmr.h:75
void px_sysclk_init(void)
Start system clock (one clock tick every 1/PX_SYSCLK_TICKS_PER_SEC seconds)
Definition: px_sysclk.c:79

Typedefs

typedef uint32_t px_sysclk_ticks_t
 Size definition of the tick counter. More...
 

Functions

void px_sysclk_init (void)
 Start system clock (one clock tick every 1/PX_SYSCLK_TICKS_PER_SEC seconds) More...
 
px_sysclk_ticks_t px_sysclk_get_tick_count (void)
 Return number of ticks since system clock started. More...
 
void px_sysclk_reset_tick_count (void)
 Reset tick count. More...
 

Typedef Documentation

◆ px_sysclk_ticks_t

typedef uint32_t px_sysclk_ticks_t

Size definition of the tick counter.

Definition at line 74 of file px_sysclk.h.

Function Documentation

◆ px_sysclk_init()

void px_sysclk_init ( void  )

Start system clock (one clock tick every 1/PX_SYSCLK_TICKS_PER_SEC seconds)

Definition at line 79 of file px_sysclk.c.

◆ px_sysclk_get_tick_count()

px_sysclk_ticks_t px_sysclk_get_tick_count ( void  )

Return number of ticks since system clock started.

Returns
px_sysclk_ticks_t Number of clock ticks

Definition at line 97 of file px_sysclk.c.

◆ px_sysclk_reset_tick_count()

void px_sysclk_reset_tick_count ( void  )

Reset tick count.

Definition at line 102 of file px_sysclk.c.