-
Notifications
You must be signed in to change notification settings - Fork 2
/
interrupts.cpp
178 lines (148 loc) · 4.77 KB
/
interrupts.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
******************************************************************************
Interrupt Handlers
VCU1200 Vehicle Control Unit Firmware
Erik Stafl
1/23/2015
Written for Tiva TM4C123BH6PGE
Language: C++
Copyright (c) 2013-2016 Stafl Systems, LLC. All rights reserved.
******************************************************************************
*/
#include "interrupts.h"
void SysTickIntHandler()
{
board.setWakeup();
}
void WatchdogIntHandler()
{
}
void ADC0IntHandler()
{
// Clear the interrupt flag
ADCIntClear(ADC0_BASE, 0);
// Update measured values from ADC0
ADCSequenceDataGet(ADC0_BASE, 0, board.ADC0_values);
// Flag New Data for Processing ADC Values
board.updateADCValues(VCU1200_Board::ADC_0);
}
void ADC1IntHandler()
{
// Clear the interrupt flag
ADCIntClear(ADC1_BASE, 0);
// Update measured values from ADC1
ADCSequenceDataGet(ADC1_BASE, 0, board.ADC1_values);
// Flag New Data for Processing ADC Values
board.updateADCValues(VCU1200_Board::ADC_1);
}
void CAN0IntHandler()
{
unsigned long status;
status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
if (status == CAN_INT_INTID_STATUS)
{
//
// Read the controller status. This will return a field of status
// error bits that can indicate various errors. Error processing
// is not done in this example for simplicity. Refer to the
// API documentation for details about the error status bits.
// The act of reading this status will clear the interrupt. If the
// CAN peripheral is not connected to a CAN bus with other CAN devices
// present, then errors will occur and will be indicated in the
// controller status.
//
status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
if (status & CAN_STATUS_BUS_OFF || status & CAN_STATUS_EPASS)
{
// Request Re-initialization of CAN Bus
CANEnable(CAN0_BASE);
}
return;
}
// Receive Messages
board.can.can_1.can_rx_message.pui8MsgData = board.can.can_1.can_rx_data;
if (status >= 17 && status <= 32)
{
// Receive Messages
board.can.can_1.can_rx_message.pui8MsgData = board.can.can_1.can_rx_data;
// Retrieve Message Data for Valid CAN Messages
CANMessageGet(CAN0_BASE, status, &board.can.can_1.can_rx_message, 0);
// Process Received Message
CANReceiver* receiver = board.can.can_1.getHandler(status);
if (receiver != 0)
{
board.can.can_1.getHandler(status)->receiveCANMessage(CAN_1, &board.can.can_1.can_rx_message, status);
}
}
if (status != 0 && status <= 32)
{
// Clear the interrupt
CANIntClear(CAN0_BASE, status);
}
}
void CAN1IntHandler()
{
unsigned long status;
status = CANIntStatus(CAN1_BASE, CAN_INT_STS_CAUSE);
if (status == CAN_INT_INTID_STATUS)
{
//
// Read the controller status. This will return a field of status
// error bits that can indicate various errors. Error processing
// is not done in this example for simplicity. Refer to the
// API documentation for details about the error status bits.
// The act of reading this status will clear the interrupt. If the
// CAN peripheral is not connected to a CAN bus with other CAN devices
// present, then errors will occur and will be indicated in the
// controller status.
//
status = CANStatusGet(CAN1_BASE, CAN_STS_CONTROL);
if (status & CAN_STATUS_BUS_OFF || status & CAN_STATUS_EPASS)
{
// Request Re-initialization of CAN Bus
CANEnable(CAN1_BASE);
}
return;
}
// Receive Messages
board.can.can_2.can_rx_message.pui8MsgData = board.can.can_2.can_rx_data;
if (status >= 17 && status <= 32)
{
// Receive Messages
board.can.can_2.can_rx_message.pui8MsgData = board.can.can_2.can_rx_data;
// Retrieve Message Data for Valid CAN Messages
CANMessageGet(CAN1_BASE, status, &board.can.can_2.can_rx_message, 0);
// Process Received Message
CANReceiver* receiver = board.can.can_2.getHandler(status);
if (receiver != 0)
{
board.can.can_2.getHandler(status)->receiveCANMessage(CAN_2, &board.can.can_2.can_rx_message, status);
}
}
if (status != 0 && status <= 32)
{
// Clear the interrupt
CANIntClear(CAN1_BASE, status);
}
}
void WTimer1IntHandler()
{
// Digital Input 12
if (TimerIntStatus(WTIMER1_BASE, true) & TIMER_CAPB_EVENT)
{
// Get Value of Timer B
if (board.readInput(VCU1200_Board::DIGITAL_INPUT_12, 3))
{
board.receiveEncoderPulse(VCU1200_Board::DIGITAL_INPUT_12, TimerValueGet(WTIMER1_BASE, TIMER_B));
}
// Clear Interrupt
TimerIntClear(WTIMER1_BASE, TIMER_CAPB_EVENT);
}
if (TimerIntStatus(WTIMER1_BASE, true) & TIMER_TIMA_TIMEOUT)
{
// Process Timer Overflow
board.timerOverflow(VCU1200_Board::DIGITAL_INPUT_12);
// Clear Interrupt
TimerIntClear(WTIMER1_BASE, TIMER_TIMA_TIMEOUT);
}
}