GPS Device
Loading...
Searching...
No Matches
SysTick Public APIs

Functions

ERR_te systick_init (SYSTICK_CFG_ts const *systick_cfg)
 Initializes and starts the SysTick timer.
void systick_deinit (void)
 Deinitializes the SysTick timer.
void systick_get_def_cfg (SYSTICK_CFG_ts *systick_cfg_o)
 Populates a configuration structure with the default SysTick settings.
uint32_t systick_get_ms (void)
 Returns the number of milliseconds elapsed since SysTick was initialized.
void SysTick_Handler (void)
 SysTick exception handler. Increments the millisecond counter on each 1 ms wrap.

Detailed Description

Function Documentation

◆ systick_init()

ERR_te systick_init ( SYSTICK_CFG_ts const * systick_cfg)

Initializes and starts the SysTick timer.

See also
systick_init

Definition at line 41 of file arm_cortex_m4_systick.c.

41 {
42 if(internal_state.initialized) {
44 }
45
46 // Disable SysTick before reconfiguring
47 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_ENABLE);
48
49 // Clear internal state
50 internal_state = (struct internal_state_s){ 0 };
51
52 // Configure interrupt enable
53 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_TICKINT);
54 SYSTICK->SYST_CSR |= (systick_cfg->interrupt << SYST_CSR_TICKINT);
55
56 // Configure clock source
57 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_CLKSOURCE);
58 SYSTICK->SYST_CSR |= (systick_cfg->clk_source << SYST_CSR_CLKSOURCE);
59
60 // Clear current value
61 SYSTICK->SYST_CVR = 0;
62
63 // Compute reload value for a 1 ms tick period from the AHB clock
64 uint32_t cpu_clk = rcc_get_ahb_clk();
65 uint32_t one_ms_clk_cycle = cpu_clk / 1000;
66 uint32_t reload_value = one_ms_clk_cycle + 1;
67 if (reload_value == 0 || reload_value > 0x01000000U) {
68 return ERR_UNKNOWN;
69 }
70
71 // Set reload value (24-bit register)
72 SYSTICK->SYST_RVR &= ~(0xFFFFFF);
73 SYSTICK->SYST_RVR |= (reload_value - 1);
74
75 // Enable SysTick
76 SYSTICK->SYST_CSR |= (1U << SYST_CSR_ENABLE);
77
78 internal_state.initialized = true;
79
80 return ERR_OK;
81}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
@ SYST_CSR_ENABLE
@ SYST_CSR_TICKINT
@ SYST_CSR_CLKSOURCE
@ ERR_UNKNOWN
Definition err.h:37
@ ERR_OK
Definition err.h:36
@ ERR_MODULE_ALREADY_INITIALIZED
Definition err.h:54
uint32_t rcc_get_ahb_clk(void)
Returns the current AHB bus clock frequency in Hz.
Internal state of the SysTick driver.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ systick_deinit()

void systick_deinit ( void )

Deinitializes the SysTick timer.

See also
systick_deinit

Definition at line 84 of file arm_cortex_m4_systick.c.

84 {
85 if(!internal_state.initialized) {
86 return;
87 }
88
89 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_ENABLE);
90
91 internal_state = (struct internal_state_s){ 0 };
92
93 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_TICKINT);
94 SYSTICK->SYST_CSR &= ~(1U << SYST_CSR_CLKSOURCE);
95
96 SYSTICK->SYST_CVR = 0;
97
98 SYSTICK->SYST_RVR &= ~(0xFFFFFF);
99}

◆ systick_get_def_cfg()

void systick_get_def_cfg ( SYSTICK_CFG_ts * systick_cfg_o)

Populates a configuration structure with the default SysTick settings.

See also
systick_get_def_cfg

Definition at line 102 of file arm_cortex_m4_systick.c.

102 {
104 systick_cfg_o->interrupt = SYSTICK_IT_TRUE;
105}
@ SYSTICK_CLK_SOURCE_PROCESSOR
@ SYSTICK_IT_TRUE
SYSTICK_CLK_SOURCE_te clk_source
SYSTICK_IT_te interrupt

◆ systick_get_ms()

uint32_t systick_get_ms ( void )

Returns the number of milliseconds elapsed since SysTick was initialized.

See also
systick_get_ms

Definition at line 108 of file arm_cortex_m4_systick.c.

108 {
109 if(!internal_state.initialized) {
110 return 0;
111 }
112
113 return internal_state.elapsed_ms;
114}
Here is the caller graph for this function:

◆ SysTick_Handler()

void SysTick_Handler ( void )

SysTick exception handler. Increments the millisecond counter on each 1 ms wrap.

Called automatically by the Cortex-M4 exception mechanism every time the SysTick counter reaches zero. Must not be called directly from application code.

Definition at line 123 of file arm_cortex_m4_systick.c.

123 {
124 internal_state.elapsed_ms++;
125}