-
Notifications
You must be signed in to change notification settings - Fork 2
/
timer.c
115 lines (105 loc) · 2.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* timer.c
*
* Created on: Nov 8, 2015
* Author: Ryan
*/
#include "timer.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
void TimerFullWidthInit(uint32_t ui32Base, uint32_t ui32Config, uint32_t ui32Value) {
uint32_t ui32Peripheral;
switch (ui32Base) {
case TIMER0_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER0;
break;
}
case TIMER1_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER1;
break;
}
case TIMER2_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER2;
break;
}
case TIMER3_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER3;
break;
}
case TIMER4_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER4;
break;
}
case TIMER5_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER5;
break;
}
case TIMER6_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER6;
break;
}
case TIMER7_BASE: {
ui32Peripheral = SYSCTL_PERIPH_TIMER7;
break;
}
}
//
// Enable the peripherals used by the timer
//
MAP_SysCtlPeripheralEnable(ui32Peripheral);
while (!MAP_SysCtlPeripheralReady(ui32Peripheral));
//
// Configure the 32-bit periodic timer for the status code length define.
//
MAP_TimerConfigure(ui32Base, ui32Config);
MAP_TimerLoadSet(ui32Base, TIMER_A, MAP_SysCtlClockGet() / ui32Value);
//
// Enable the timer.
//
MAP_TimerEnable(ui32Base, TIMER_A);
}
uint32_t TimerFullWidthIntInit(uint32_t ui32Base, int16_t i16Priority, uint32_t ui32IntFlags, void (*pfnHandler)(void)) {
uint32_t ui32TimerInt;
switch (ui32Base) {
case TIMER0_BASE: {
ui32TimerInt = INT_TIMER0A;
break;
}
case TIMER1_BASE: {
ui32TimerInt = INT_TIMER1A;
break;
}
case TIMER2_BASE: {
ui32TimerInt = INT_TIMER2A;
break;
}
case TIMER3_BASE: {
ui32TimerInt = INT_TIMER3A;
break;
}
case TIMER4_BASE: {
ui32TimerInt = INT_TIMER4A;
break;
}
case TIMER5_BASE: {
ui32TimerInt = INT_TIMER5A;
break;
}
default: {
return 0;
}
}
//
// Setup the interrupts for the timer.
//
if (i16Priority >= 0) MAP_IntPrioritySet(ui32TimerInt, (i16Priority * 0xF));
TimerIntRegister(ui32Base, TIMER_A, pfnHandler);
MAP_IntEnable(ui32TimerInt);
MAP_TimerIntEnable(ui32Base, ui32IntFlags);
return ui32TimerInt;
}