-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.c
77 lines (63 loc) · 1.38 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* timer.c
*
* Created on: Feb 13, 2017
* Author: srazak
* Modified on: Sept 2, 2019
* Author: efeoflus
*
*/
#include <stdint.h>
#include <stdbool.h>
#include <tm4c123gh6pm.h>
#include <sysctl.h>
void SystickInit()
{
NVIC_ST_CTRL_R = 0;
NVIC_ST_RELOAD_R = 0x00FFFFFF;
NVIC_ST_CURRENT_R = 0;
NVIC_ST_CTRL_R = 0x00000005;
}
/** busy waiting for one tick, 12.5ns if using 80MHZ **/
void SysTick_Wait(uint32_t delay)
{
NVIC_ST_RELOAD_R = delay - 1;
NVIC_ST_CURRENT_R = 0;
while ((NVIC_ST_CTRL_R&0x00010000)==0){}
}
void SysTick_Wait10ms(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(800000);
}
void SysTick_Wait1ms(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(80000);
}
void SysTick_Wait100microsec(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(8000);
}
void SysTick_Wait10microsec(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(800);
}
void SysTick_Wait1microsec(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(80);
}
void SysTick_Wait100nanosec(uint32_t delay)
{
uint32_t i;
for (i = 0; i <delay;i++)
SysTick_Wait(8);
}