-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.c
58 lines (46 loc) · 1.36 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
#include "timer.h"
#include "modules/modules.h"
#include "utils/counter.h"
METHOD_INIT_IMPL(M_timer, tim)
{
}
METHOD_DEINIT_IMPL(M_timer, tim)
{
}
static void timer_control(M_timer* tim)
{
// if((tim->status & STATUS_RUN) && (tim->control & CONTROL_RESET)){
// tim->m_ref_counter = sys_time.r_counter_ms;
// }
if(tim->control & CONTROL_START){
tim->out_expired = FLAG_NONE;
tim->out_timeout = STROBE_NONE;
tim->m_ref_counter = sys_time.r_counter_ms;
tim->status = STATUS_RUN;
}
if(tim->control & CONTROL_STOP){
tim->out_expired = FLAG_NONE;
tim->out_timeout = STROBE_NONE;
tim->status = STATUS_NONE;
}
tim->control = CONTROL_NONE;
}
METHOD_CALC_IMPL(M_timer, tim)
{
tim->out_timeout = STROBE_NONE;
timer_control(tim);
if(tim->status & STATUS_RUN){
// Пройденное время с начала счёта.
uint32_t elapsed_time = counter_calc_diff(sys_time.r_counter_ms, tim->m_ref_counter);
// Если времени прошло больше чем интервал таймера.
if(elapsed_time >= tim->r_interval){
tim->status = STATUS_NONE;
tim->out_expired = FLAG_ACTIVE;
tim->out_timeout = STROBE_ACTIVE;
}
}
}
METHOD_CONTROL_IMPL(M_timer, tim)
{
timer_control(tim);
}