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 TMRx peripheral

Description

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

File(s):

px_sysclk_init() configures TMRx 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 TMRx 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

Macros

#define PX_SYSCLK_CFG_TICKS_PER_SEC   100ul
 The number of system clock ticks per second. More...
 
#define PX_SYSCLK_CFG_USE_TMRX   2
 Specify which TMR peripheral must be used. More...
 
#define PX_SYSCLK_CFG_TMR_PRESCALER   1024
 Specify TMR Prescaler. More...
 
#define PX_SYSCLK_CFG_TIMEOUT_PERIOD_TICKS   PX_SYSCLK_CFG_TICKS_PER_SEC
 Specify periodic timeout (in sysclk ticks) More...
 

Typedefs

typedef uint16_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...
 
bool px_sysclk_disable (void)
 Disable system clock. More...
 
void px_sysclk_enable (void)
 Enable system clock. More...
 
px_sysclk_ticks_t px_sysclk_get_tick_count (void)
 Return number of ticks since system clock started. More...
 

Macro Definition Documentation

◆ PX_SYSCLK_CFG_TICKS_PER_SEC

#define PX_SYSCLK_CFG_TICKS_PER_SEC   100ul

The number of system clock ticks per second.

Definition at line 35 of file px_sysclk_cfg_template.h.

◆ PX_SYSCLK_CFG_USE_TMRX

#define PX_SYSCLK_CFG_USE_TMRX   2

Specify which TMR peripheral must be used.

Definition at line 38 of file px_sysclk_cfg_template.h.

◆ PX_SYSCLK_CFG_TMR_PRESCALER

#define PX_SYSCLK_CFG_TMR_PRESCALER   1024

Specify TMR Prescaler.

Definition at line 41 of file px_sysclk_cfg_template.h.

◆ PX_SYSCLK_CFG_TIMEOUT_PERIOD_TICKS

#define PX_SYSCLK_CFG_TIMEOUT_PERIOD_TICKS   PX_SYSCLK_CFG_TICKS_PER_SEC

Specify periodic timeout (in sysclk ticks)

Definition at line 44 of file px_sysclk_cfg_template.h.

Typedef Documentation

◆ px_sysclk_ticks_t

typedef uint16_t px_sysclk_ticks_t

Size definition of the tick counter.

Definition at line 73 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).

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_disable()

bool px_sysclk_disable ( void  )

Disable system clock.

Returns
true System clock was enabled
false System clock was disabled

Definition at line 185 of file px_sysclk.c.

◆ px_sysclk_enable()

void px_sysclk_enable ( void  )

Enable system clock.

Definition at line 194 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.