Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_hal/lv_hal_tick.c
1476 views
1
/**
2
* @file systick.c
3
* Provide access to the system tick with 1 millisecond resolution
4
*/
5
6
/*********************
7
* INCLUDES
8
*********************/
9
#ifdef LV_CONF_INCLUDE_SIMPLE
10
#include "lv_conf.h"
11
#else
12
#include "../../lv_conf.h"
13
#endif
14
15
#include "lv_hal_tick.h"
16
#include <stddef.h>
17
18
#if LV_TICK_CUSTOM == 1
19
#include LV_TICK_CUSTOM_INCLUDE
20
#endif
21
22
/*********************
23
* DEFINES
24
*********************/
25
26
/**********************
27
* TYPEDEFS
28
**********************/
29
30
/**********************
31
* STATIC PROTOTYPES
32
**********************/
33
34
/**********************
35
* STATIC VARIABLES
36
**********************/
37
static uint32_t sys_time = 0;
38
static volatile uint8_t tick_irq_flag;
39
40
/**********************
41
* MACROS
42
**********************/
43
44
/**********************
45
* GLOBAL FUNCTIONS
46
**********************/
47
48
/**
49
* You have to call this function periodically
50
* @param tick_period the call period of this function in milliseconds
51
*/
52
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)
53
{
54
tick_irq_flag = 0;
55
sys_time += tick_period;
56
}
57
58
/**
59
* Get the elapsed milliseconds since start up
60
* @return the elapsed milliseconds
61
*/
62
uint32_t lv_tick_get(void)
63
{
64
#if LV_TICK_CUSTOM == 0
65
uint32_t result;
66
do {
67
tick_irq_flag = 1;
68
result = sys_time;
69
} while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */
70
71
return result;
72
#else
73
return LV_TICK_CUSTOM_SYS_TIME_EXPR;
74
#endif
75
}
76
77
/**
78
* Get the elapsed milliseconds since a previous time stamp
79
* @param prev_tick a previous time stamp (return value of systick_get() )
80
* @return the elapsed milliseconds since 'prev_tick'
81
*/
82
uint32_t lv_tick_elaps(uint32_t prev_tick)
83
{
84
uint32_t act_time = lv_tick_get();
85
86
/*If there is no overflow in sys_time simple subtract*/
87
if(act_time >= prev_tick) {
88
prev_tick = act_time - prev_tick;
89
} else {
90
prev_tick = UINT32_MAX - prev_tick + 1;
91
prev_tick += act_time;
92
}
93
94
return prev_tick;
95
}
96
97
/**********************
98
* STATIC FUNCTIONS
99
**********************/
100
101
102