-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.c
41 lines (34 loc) · 785 Bytes
/
delay.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
#include "delay.h"
static __IO uint32_t sysTickCounter;
void SysTick_Init(void) {
/****************************************
*SystemFrequency/1000 1ms *
*SystemFrequency/100000 10us *
*SystemFrequency/1000000 1us *
*****************************************/
while (SysTick_Config(SystemCoreClock / 1000000) != 0) {
} // One SysTick interrupt now equals 1us
}
/**
* This method needs to be called in the SysTick_Handler
*/
void TimeTick_Decrement(void) {
if (sysTickCounter != 0x00) {
sysTickCounter--;
}
}
void delay_nus(u32 n) {
sysTickCounter = n;
while (sysTickCounter != 0) {
}
}
void delay_1ms(void) {
sysTickCounter = 1000;
while (sysTickCounter != 0) {
}
}
void delay_nms(u32 n) {
while (n--) {
delay_1ms();
}
}