-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactn_timer.c
More file actions
59 lines (48 loc) · 1.27 KB
/
actn_timer.c
File metadata and controls
59 lines (48 loc) · 1.27 KB
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
59
#include "stm32f4_discovery.h"
#include "config.h"
#include "actn_timer.h"
void init_Action_Timer() {
/* Enable timer clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseInitTypeDef timerInitStructure;
/* Initialize clock */
timerInitStructure.TIM_Prescaler = 8400;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = MILLIS;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &timerInitStructure);
TIMER.active = false;
TIMER.done = false;
}
bool timer_Started() {
return TIMER.active;
}
bool timer_Done() {
return TIMER.done;
}
void stop_Timer() {
TIMER.active = false;
TIM_Cmd(TIM2, DISABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
}
void restart_Timer() {
TIMER.active = false;
TIMER.done = false;
TIM_Cmd(TIM2, DISABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
}
void start_Timer() {
TIMER.active = true;
TIMER.done = false;
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
void update_Timer() {
if (!timer_Started()) return;
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
stop_Timer();
TIMER.done = true;
}
}