STM32 RTOS 0.2.3
Bare-metal preemptive RTOS for STM32F446RE
Loading...
Searching...
No Matches
systick.c
Go to the documentation of this file.
1
5#include "systick.h"
6
11
12DriverStatus_e systickInit(SysTickRegisters_t *systick, uint32_t core_hz, uint32_t tick_hz)
13{
15 uint32_t reload = 0U;
16
17 if ((core_hz == 0U) || (tick_hz == 0U))
18 {
20 }
21 else
22 {
23 /* tick_hz > core_hz gives 0 clocks, rejected below. */
24 uint32_t period_clocks = core_hz / tick_hz;
25
26 if (period_clocks < 2U)
27 {
29 }
30 else
31 {
32 reload = period_clocks - 1U;
33 }
34 }
35
36 if ((status == DRIVER_STATUS_OK) && (reload > SYSTICK_LOAD_RELOAD_Msk))
37 {
39 }
40
41 if (status == DRIVER_STATUS_OK)
42 {
43 systick->CTRL = 0U;
44 systick->LOAD = reload;
45 systick->VAL = 0U;
47 }
48
49 return status;
50}
51
53{
54 systick->CTRL = 0U;
55 systick->LOAD = 0U;
56 systick->VAL = 0U;
57}
58
DriverStatus_e
Outcome of a driver call: a category for control flow, not a diagnosis.
@ DRIVER_STATUS_OK
Succeeded.
@ DRIVER_STATUS_ERR_INVALID_PARAM
A parameter is outside its valid domain.
DRIVER_MUST_CHECK DriverStatus_e systickInit(SysTickRegisters_t *systick, uint32_t core_hz, uint32_t tick_hz)
Start SysTick at tick_hz from the processor clock, with its interrupt on.
Definition systick.c:12
void systickDeinit(SysTickRegisters_t *systick)
Stop SysTick and zero CTRL, LOAD and VAL.
Definition systick.c:52
#define SYSTICK_LOAD_RELOAD_Msk
<span class="regaccess">rw</span> Reload value: the tick period is RELOAD + 1 clocks.
Definition systick_reg.h:48
#define SYSTICK_CTRL_TICKINT
<span class="regaccess">rw</span> Raise the SysTick exception when the counter reaches 0.
Definition systick_reg.h:35
#define SYSTICK_CTRL_ENABLE
<span class="regaccess">rw</span> Counter enable.
Definition systick_reg.h:32
#define SYSTICK_CTRL_CLKSOURCE
<span class="regaccess">rw</span> Clock source: 1 = processor clock (HCLK), 0 = HCLK / 8.
Definition systick_reg.h:38
SysTick register block.
Definition systick_reg.h:19
volatile uint32_t CTRL
0x00: control and status
Definition systick_reg.h:20
volatile uint32_t LOAD
0x04: reload value
Definition systick_reg.h:21
volatile uint32_t VAL
0x08: current value; any write clears it
Definition systick_reg.h:22
SysTick driver: the periodic tick timer.