-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_DeviceStatus.c
189 lines (180 loc) · 4.49 KB
/
Task_DeviceStatus.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
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
179
180
181
182
183
184
185
186
187
188
189
#include "same70-base_16/FreeRTOS/Source/include/FreeRTOS.h"
#include "same70-base_16/FreeRTOS/Source/include/task.h"
#include "same70-base_16/FreeRTOS/Source/include/queue.h"
#include "same70-base_16/FreeRTOS/Source/include/timers.h"
#include "Task_Menu.h"
#include "Dash_drivers/mcanFreeRTOSWrapper.h"
#include "canID_definitions.h"
#include "revolve_can_definitions_16/revolve_can_definitions.h"
#define NUM_DEVICES 16
TimerHandle_t deviceTimer[NUM_DEVICES];
/*
ECU = 0
TRQ_0 = 1
BSPD = 2
TEL = 3
ADC_FR = 4
ADC_FL = 5
ADC_RR = 6
ADC_RL = 7
INV = 8
FAN = 9
BMS = 10
GLVBMS = 11
IMU = 12
STEER_POS = 13
IMD = 14
TRQ_1 = 15
*/
void vDeviceTimerCallback(TimerHandle_t pxTimer) {
uint8_t device_id;
device_id = (uint8_t) pvTimerGetTimerID(pxTimer);
switch (device_id) {
case 0:
deviceState.ECU = DEAD;
break;
case 1:
deviceState.TRQ_0 = DEAD;
break;
case 2:
deviceState.BSPD = DEAD;
break;
case 3:
deviceState.TEL = DEAD;
break;
case 4:
deviceState.ADC_FR = DEAD;
break;
case 5:
deviceState.ADC_FL = DEAD;
break;
case 6:
deviceState.ADC_RR = DEAD;
break;
case 7:
deviceState.ADC_RL = DEAD;
break;
case 8:
deviceState.INV = DEAD;
break;
case 9:
deviceState.FAN = DEAD;
break;
case 10:
deviceState.BMS = DEAD;
break;
case 11:
deviceState.GLVBMS = DEAD;
break;
case 12:
deviceState.IMU = DEAD;
break;
case 13:
deviceState.STEER_POS = DEAD;
break;
case 14:
deviceState.IMD = DEAD;
break;
case 15:
deviceState.TRQ_1 = DEAD;
break;
}
}
void deviceStatusTask() {
TickType_t xLastWakeTime;
portBASE_TYPE xStatus;
const portTickType xTicksToWait = 1 / portTICK_RATE_MS;
uint8_t device_id;
for (uint8_t x = 0 ; x < NUM_DEVICES; x++) {
deviceTimer[x] = xTimerCreate("Device_Timer",2500/portTICK_RATE_MS, pdTRUE, (void *) x ,vDeviceTimerCallback);
if (deviceTimer[x] == NULL) {
//Timer not created .. Heap?
}
else if (xTimerStart(deviceTimer[x],0) != pdPASS) {
//Start not successfull
}
}
while(1) {
while (xQueueReceive( xDeviceStatusQueue, &device_id, xTicksToWait) == pdPASS ) {
//xStatus = xQueueReceive( xDeviceStatusQueue, &device_id, xTicksToWait);
//if ( xStatus == pdPASS) {
switch (device_id) {
case ALIVE_ECU:
xTimerReset(deviceTimer[0],1/portTICK_RATE_MS);
deviceState.ECU = ALIVE;
break;
case ALIVE_TRQ_CAN_0:
xTimerReset(deviceTimer[1],1/portTICK_RATE_MS);
deviceState.TRQ_0 = ALIVE;
break;
case ALIVE_TRQ_CAN_1:
xTimerReset(deviceTimer[15],1/portTICK_RATE_MS);
deviceState.TRQ_1 = ALIVE;
break;
case ALIVE_UNINIT_TRQ_CAN_0:
xTimerReset(deviceTimer[1],1/portTICK_RATE_MS);
deviceState.TRQ_0 = UNITIALIZED;
break;
case ALIVE_UNINIT_TRQ_CAN_1:
xTimerReset(deviceTimer[15],1/portTICK_RATE_MS);
deviceState.TRQ_1 = UNITIALIZED;
break;
// case ALIVE_BSPD:
// xTimerReset(deviceTimer[2],1/portTICK_RATE_MS);
// deviceState.BSPD = ALIVE;
// break;
case ALIVE_TELEMETRY:
xTimerReset(deviceTimer[3],1/portTICK_RATE_MS);
deviceState.TEL = ALIVE;
break;
// case ALIVE_ADC_FR:
// xTimerReset(deviceTimer[4],1/portTICK_RATE_MS);
// deviceState.ADC_FR = ALIVE;
// break;
// case ALIVE_ADC_FL:
// xTimerReset(deviceTimer[5],1/portTICK_RATE_MS);
// deviceState.ADC_FL = ALIVE;
// break;
// case ALIVE_ADC_RR:
// xTimerReset(deviceTimer[6],1/portTICK_RATE_MS);
// deviceState.ADC_RR = ALIVE;
// break;
// case ALIVE_ADC_RL:
// xTimerReset(deviceTimer[7],1/portTICK_RATE_MS);
// deviceState.ADC_RL = ALIVE;
// break;
// case ALIVE_INVERTER:
// xTimerReset(deviceTimer[8],1/portTICK_RATE_MS);
// deviceState.INV = ALIVE;
// break;
case ALIVE_FAN:
xTimerReset(deviceTimer[9],1/portTICK_RATE_MS);
deviceState.FAN = ALIVE;
break;
case ALIVE_BMS:
xTimerReset(deviceTimer[10],1/portTICK_RATE_MS);
deviceState.BMS = ALIVE;
break;
case ALIVE_GLVBMS:
xTimerReset(deviceTimer[11],1/portTICK_RATE_MS);
deviceState.GLVBMS = ALIVE;
break;
// case ALIVE_IMU:
// xTimerReset(deviceTimer[12],1/portTICK_RATE_MS);
// deviceState.IMU = ALIVE;
// break;
// case ALIVE_STEER_POS:
// xTimerReset(deviceTimer[13],1/portTICK_RATE_MS);
// deviceState.STEER_POS = ALIVE;
// break;
case ALIVE_IMD:
xTimerReset(deviceTimer[14],1/portTICK_RATE_MS);
deviceState.IMD = ALIVE;
break;
default:
break;
}
}
vTaskDelay(100/portTICK_RATE_MS);
}
}