-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimerLABSud.cpp
111 lines (89 loc) · 2.01 KB
/
TimerLABSud.cpp
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
//
//
//
#include "Energia.h"
#include "TimerLABSud.h"
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdbool.h>
#include <inc/tm4c1294ncpdt.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
static const unsigned long timerBase[] =
{
TIMER0_BASE, TIMER1_BASE
};
static const unsigned long timerCtrl[] =
{
SYSCTL_PERIPH_TIMER0, SYSCTL_PERIPH_TIMER1
};
static const unsigned long timerList[] =
{
TIMER_A, TIMER_A
};
static const unsigned long timerTimeOut[] =
{
TIMER_TIMA_TIMEOUT, TIMER_TIMA_TIMEOUT
};
static const unsigned long timerInt[] =
{
INT_TIMER0A, INT_TIMER1A
};
static void(*func[2])(void);
static void (*intFunc[2])(void) =
{
Timer0IntHandler, Timer1IntHandler
};
TimerLABSud::TimerLABSud()
{
m_uiTimer = 0;
}
TimerLABSud::TimerLABSud(uint8_t timer)
{
m_uiTimer = timer;
}
void TimerLABSud::set(uint32_t periode, void(*f)(void))
{
//unsigned long ulPeriod = (SysCtlClockGet() / 1000); //En ms
unsigned long ulPeriod = 120000;
ulPeriod = ulPeriod * periode;
SysCtlPeripheralEnable(timerCtrl[m_uiTimer]);
TimerIntRegister(timerBase[m_uiTimer], timerList[m_uiTimer], intFunc[m_uiTimer]);
TimerConfigure(timerBase[m_uiTimer], TIMER_CFG_PERIODIC);
TimerLoadSet(timerBase[m_uiTimer], timerList[m_uiTimer], ulPeriod - 1);
IntEnable(timerInt[m_uiTimer]);
TimerIntEnable(timerBase[m_uiTimer], timerTimeOut[m_uiTimer]);
IntMasterEnable();
func[m_uiTimer] = f;
}
void TimerLABSud::start(void)
{
TimerEnable(timerBase[m_uiTimer], timerList[m_uiTimer]);
}
void TimerLABSud::stop(void)
{
TimerDisable(timerBase[m_uiTimer], timerList[m_uiTimer]);
}
void TimerLABSud::TimerIntHandler()
{
TimerIntClear(timerBase[m_uiTimer], timerTimeOut[m_uiTimer]);
if (func[m_uiTimer])
{
func[m_uiTimer]();
}
}
void Timer0IntHandler(void)
{
Timer0.TimerIntHandler();
}
void Timer1IntHandler(void)
{
Timer1.TimerIntHandler();
}
TimerLABSud Timer0;
TimerLABSud Timer1(1);