-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys_timer.c
46 lines (39 loc) · 858 Bytes
/
sys_timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* sys_timer.c
*
* Created on: 2024-01-29
* Author: GDR
*/
#include "cyhal.h"
#include "sys_timer.h"
static uint32_t sys_time_ms = 0;
static void systic_callback(void)
{
sys_time_ms++;
}
_Bool sys_timer_init(void)
{
uint32_t clkPerifreq = Cy_SysClk_ClkPeriGetFrequency();
Cy_SysTick_Init(CY_SYSTICK_CLOCK_SOURCE_CLK_CPU, clkPerifreq/1000 );
Cy_SysTick_EnableInterrupt();
Cy_SysTick_Enable();
/* Find unused callback slot. */
for (uint32_t i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
{
if (Cy_SysTick_GetCallback(i) == NULL)
{
/* Set callback */
Cy_SysTick_SetCallback(i, systic_callback);
return true;
}
}
return false;
}
uint32_t get_system_time_ms(void)
{
return sys_time_ms;
}
uint32_t *get_system_time_pointer_ms(void)
{
return &sys_time_ms;
}