Skip to content

Commit 1e0cf6e

Browse files
committed
heartbeat on dash lvpdb pcu
1 parent c75faed commit 1e0cf6e

30 files changed

Lines changed: 173 additions & 207 deletions

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"-DCMAKE_COMMAND=cube-cmake"
3535
],
3636
"[c]": {
37-
"editor.defaultFormatter": "ms-vscode.cpptools",
37+
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
3838
"editor.formatOnSave": true
3939
},
4040
"[cpp]": {

BMS/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.5
1+
1.5.6

DART/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.3
1+
1.5.4

DASH/Core/Src/freertos.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@
5353
/* DASHTaskRx / DASHTaskTx stacks: set in CubeMX (DASH.ioc, FREERTOS.Tasks01). Regenerating
5454
* from the .ioc overwrites osThreadAttr_t blocks above; keep those tasks at 1024 words. */
5555
/* USER CODE END Variables */
56-
/* Definitions for btnTxLoopTask */
57-
osThreadId_t btnTxLoopTaskHandle;
58-
const osThreadAttr_t btnTxLoopTask_attributes = {
59-
.name = "btnTxLoopTask",
60-
.stack_size = 1024 * 4,
56+
/* Definitions for ioLoopTask */
57+
osThreadId_t ioLoopTaskHandle;
58+
const osThreadAttr_t ioLoopTask_attributes = {
59+
.name = "ioLoopTask",
60+
.stack_size = 512 * 4,
6161
.priority = (osPriority_t) osPriorityHigh1,
6262
};
6363
/* Definitions for displayTask */
6464
osThreadId_t displayTaskHandle;
6565
const osThreadAttr_t displayTask_attributes = {
6666
.name = "displayTask",
6767
.stack_size = 1024 * 4,
68-
.priority = (osPriority_t) osPriorityHigh,
68+
.priority = (osPriority_t) osPriorityAboveNormal,
6969
};
7070
/* Definitions for uartRxTask */
7171
osThreadId_t uartRxTaskHandle;
@@ -86,14 +86,14 @@ osThreadId_t DASHTaskRxHandle;
8686
const osThreadAttr_t DASHTaskRx_attributes = {
8787
.name = "DASHTaskRx",
8888
.stack_size = 1024 * 4,
89-
.priority = (osPriority_t) osPriorityLow,
89+
.priority = (osPriority_t) osPriorityHigh2,
9090
};
9191
/* Definitions for DASHTaskTx */
9292
osThreadId_t DASHTaskTxHandle;
9393
const osThreadAttr_t DASHTaskTx_attributes = {
9494
.name = "DASHTaskTx",
9595
.stack_size = 1024 * 4,
96-
.priority = (osPriority_t) osPriorityLow,
96+
.priority = (osPriority_t) osPriorityHigh3,
9797
};
9898
/* Definitions for canTxQueue */
9999
osMessageQueueId_t canTxQueueHandle;
@@ -151,7 +151,7 @@ const osSemaphoreAttr_t uartTxSem_attributes = {
151151

152152
/* USER CODE END FunctionPrototypes */
153153

154-
void StartBtnTxLoop(void *argument);
154+
void StartIoLoop(void *argument);
155155
void StartDisplayTask(void *argument);
156156
void StartUartRxTask(void *argument);
157157
void StartUartTxTask(void *argument);
@@ -285,8 +285,8 @@ void MX_FREERTOS_Init(void) {
285285
/* USER CODE END RTOS_QUEUES */
286286

287287
/* Create the thread(s) */
288-
/* creation of btnTxLoopTask */
289-
btnTxLoopTaskHandle = osThreadNew(StartBtnTxLoop, NULL, &btnTxLoopTask_attributes);
288+
/* creation of ioLoopTask */
289+
ioLoopTaskHandle = osThreadNew(StartIoLoop, NULL, &ioLoopTask_attributes);
290290

291291
/* creation of displayTask */
292292
displayTaskHandle = osThreadNew(StartDisplayTask, NULL, &displayTask_attributes);
@@ -305,7 +305,7 @@ void MX_FREERTOS_Init(void) {
305305

306306
/* USER CODE BEGIN RTOS_THREADS */
307307
/* Validate all thread creations - fail fast on low heap */
308-
REQUIRE_RTOS_HANDLE(btnTxLoopTaskHandle);
308+
REQUIRE_RTOS_HANDLE(ioLoopTaskHandle);
309309
REQUIRE_RTOS_HANDLE(displayTaskHandle);
310310
REQUIRE_RTOS_HANDLE(uartRxTaskHandle);
311311
REQUIRE_RTOS_HANDLE(uartTxTaskHandle);
@@ -320,22 +320,22 @@ void MX_FREERTOS_Init(void) {
320320

321321
}
322322

323-
/* USER CODE BEGIN Header_StartBtnTxLoop */
323+
/* USER CODE BEGIN Header_StartIoLoop */
324324
/**
325-
* @brief Function implementing the btnTxLoopTask thread.
325+
* @brief Function implementing the ioLoopTask thread.
326326
* @param argument: Not used
327327
* @retval None
328328
*/
329-
/* USER CODE END Header_StartBtnTxLoop */
330-
__weak void StartBtnTxLoop(void *argument)
329+
/* USER CODE END Header_StartIoLoop */
330+
__weak void StartIoLoop(void *argument)
331331
{
332-
/* USER CODE BEGIN StartBtnTxLoop */
332+
/* USER CODE BEGIN StartIoLoop */
333333
/* Infinite loop */
334334
for (;;)
335335
{
336336
osDelay(1);
337337
}
338-
/* USER CODE END StartBtnTxLoop */
338+
/* USER CODE END StartIoLoop */
339339
}
340340

341341
/* USER CODE BEGIN Header_StartDisplayTask */

DASH/Core/User/Inc/FEB_IO.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@ typedef struct
3030
bool switch_coolant_pump_radiator_fan;
3131
bool switch_accumulator_fans;
3232
bool switch_logging;
33+
bool switch_4;
3334

3435
// Button states
3536
bool button_rtd;
37+
bool button_2;
38+
bool button_3;
39+
bool button_4;
3640

3741
// Buzzer state
3842
bool buzzer_enabled;
3943
} IO_States_t;
4044

4145
IO_States_t FEB_IO_GetLastIOStates(void);
4246

47+
bool FEB_IO_StatusOk(void);
48+
4349
void FEB_IO_Set_Buzzer(bool new_state);
4450

4551
#endif

DASH/Core/User/Src/FEB_CAN.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
#include "feb_can_lib.h"
2222
#include "cmsis_os2.h"
2323
#include "FreeRTOS.h"
24+
#include "feb_log.h"
2425
#include "task.h"
2526
#include "feb_console.h"
2627
#include "main.h"
2728
#include "FEB_CAN_State.h"
2829
#include "FEB_CAN_PingPong.h"
30+
#include "FEB_CAN_LVPDB.h"
31+
#include "FEB_CAN_PCU.h"
32+
#include "FEB_CAN_BMS.h"
2933

3034
/* ========================== External HAL handles ========================== */
3135
extern CAN_HandleTypeDef hcan1;
@@ -55,6 +59,7 @@ static void DASH_CAN_RxCallback(FEB_CAN_Instance_t instance, uint32_t can_id, FE
5559
(void)user_data;
5660
(void)can_id;
5761
(void)length;
62+
// LOG_D("CAN RX", "%X %X %X %X %X %X %X %X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
5863
}
5964

6065
/* ========================== CAN Initialization ========================== */
@@ -142,9 +147,9 @@ void StartDASHTaskRx(void *argument)
142147
/* CAN init MUST occur after scheduler start */
143148
DASH_CAN_Init();
144149
FEB_CAN_PingPong_Init();
145-
// FEB_CAN_BMS_Init();
146-
// FEB_CAN_PCU_Init();
147-
// FEB_CAN_LVPDB_Init();
150+
FEB_CAN_BMS_Init();
151+
FEB_CAN_PCU_Init();
152+
FEB_CAN_LVPDB_Init();
148153

149154
/* Signal that CAN is ready for state publishing */
150155
FEB_CAN_State_SetReady();

DASH/Core/User/Src/FEB_CAN_LVPDB.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "FEB_CAN_LVPDB.h"
1010
#include "feb_can.h"
1111
#include "feb_can_lib.h"
12+
#include "feb_log.h"
1213
#include "stm32f4xx_hal.h"
1314
#include <stdbool.h>
1415

@@ -32,6 +33,7 @@ static LVPDB_State_t lvpdb_state = {.lv_24v_voltage = 0, .lv_12v_voltage = 0, .l
3233
static void rx_callback_lv_voltages(FEB_CAN_Instance_t instance, uint32_t can_id, FEB_CAN_ID_Type_t id_type,
3334
const uint8_t *data, uint8_t length, void *user_data)
3435
{
36+
LOG_I("CAN RX", "Received can message %X %X", data[0], data[1]);
3537
struct feb_can_lvpdb_lv_24v_bus_and_12v_bus_voltages_t msg;
3638
if (feb_can_lvpdb_lv_24v_bus_and_12v_bus_voltages_unpack(&msg, data, length) == 0)
3739
{
@@ -53,13 +55,12 @@ void FEB_CAN_LVPDB_Init(void)
5355
.can_id = FEB_CAN_LVPDB_LV_24V_BUS_AND_12V_BUS_VOLTAGES_FRAME_ID,
5456
.id_type = FEB_CAN_ID_STD,
5557
.filter_type = FEB_CAN_FILTER_EXACT,
56-
.mask = 0,
5758
.fifo = FEB_CAN_FIFO_0,
5859
.callback = rx_callback_lv_voltages,
5960
.user_data = NULL,
6061
};
6162

62-
(void)FEB_CAN_RX_Register(&rx_params);
63+
FEB_CAN_RX_Register(&rx_params);
6364
}
6465

6566
uint16_t FEB_CAN_LVPDB_GetLast24VVoltage(void)

DASH/Core/User/Src/FEB_CAN_State.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "feb_log.h"
1212
#include <stdbool.h>
1313
#include <string.h>
14+
#include "FEB_IO.h"
1415

1516
#define TAG_STATE "[STATE]"
1617

@@ -46,23 +47,23 @@ void FEB_CAN_State_Tick(void)
4647
return;
4748
}
4849

50+
uint8_t tx_data[FEB_CAN_DASH_TPS_LENGTH];
51+
memset(tx_data, 0x00, sizeof(tx_data));
52+
// feb_can_dash_tps_pack(tx_data, &((struct feb_can_dash_tps_t){.current = }), sizeof(tx_data));
53+
// FEB_CAN_TX_Send(FEB_CAN_INSTANCE_1, FEB_CAN_DASH_TPS_FRAME_ID, FEB_CAN_ID_STD, tx_data, FEB_CAN_DASH_TPS_LENGTH);
54+
4955
/* Divider for 100ms period (called every 1ms) */
5056
static uint16_t heartbeat_divider = 0;
5157
heartbeat_divider++;
52-
5358
if (heartbeat_divider >= 100)
5459
{
5560
heartbeat_divider = 0;
5661

57-
/* TODO: Wire to actual DASH error state when implemented */
58-
/* dash_heartbeat_msg.error0 = error_flags_0; */
59-
/* dash_heartbeat_msg.error1 = error_flags_1; */
60-
/* ... etc ... */
62+
dash_heartbeat_msg.io_expander_error = !FEB_IO_StatusOk();
6163

62-
/* Pack and send */
6364
uint8_t tx_data[FEB_CAN_DASH_HEARTBEAT_LENGTH];
65+
memset(tx_data, 0x00, sizeof(tx_data));
6466
feb_can_dash_heartbeat_pack(tx_data, &dash_heartbeat_msg, sizeof(tx_data));
65-
6667
FEB_CAN_TX_Send(FEB_CAN_INSTANCE_1, FEB_CAN_DASH_HEARTBEAT_FRAME_ID, FEB_CAN_ID_STD, tx_data,
6768
FEB_CAN_DASH_HEARTBEAT_LENGTH);
6869
}
@@ -75,31 +76,33 @@ void FEB_CAN_State_Tick(void)
7576
*/
7677
static uint16_t state_divider = 0;
7778
state_divider++;
78-
7979
if (state_divider >= 100)
8080
{
8181
state_divider = 0;
8282

83-
uint8_t tx_data[2];
83+
uint8_t tx_data[FEB_CAN_DASH_STATE_LENGTH];
8484
memset(tx_data, 0x00, sizeof(tx_data));
8585

8686
IO_States_t states = FEB_IO_GetLastIOStates();
8787

8888
if (feb_can_dash_state_pack(tx_data,
8989
&((struct feb_can_dash_state_t){.buzzer = states.buzzer_enabled,
9090
.button1 = states.button_rtd,
91+
.button2 = states.button_2,
92+
.button3 = states.button_3,
93+
.button4 = states.button_4,
9194
.switch1 = states.switch_accumulator_fans,
92-
.switch2 = states.button_rtd,
93-
// .switch2 = states.switch_coolant_pump_radiator_fan,
95+
.switch2 = states.switch_coolant_pump_radiator_fan,
9496
.switch3 = states.switch_logging,
97+
.switch4 = states.switch_4,
9598
.ready_to_drive = FEB_State_GetLastRTD()}),
96-
2) == 2)
99+
sizeof(tx_data)) == FEB_CAN_DASH_STATE_LENGTH)
97100
{
98101
FEB_CAN_Status_t st = FEB_CAN_TX_Send(FEB_CAN_INSTANCE_1, FEB_CAN_DASH_STATE_FRAME_ID, FEB_CAN_ID_STD, tx_data,
99102
FEB_CAN_DASH_STATE_LENGTH);
100103
if (st == FEB_CAN_OK)
101104
{
102-
LOG_D(TAG_STATE, "Sending Dash IO State Over CAN: %02X %02X", tx_data[0], tx_data[1]);
105+
// LOG_D(TAG_STATE, "Sending Dash IO State Over CAN: %02X %02X", tx_data[0], tx_data[1]);
103106
}
104107
else
105108
{

DASH/Core/User/Src/FEB_IO.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include "FEB_CAN.h"
33
#include "FEB_CAN_PCU.h"
44
#include "FEB_i2c_protected.h"
5+
#include "feb_log.h"
56
#include "stm32f4xx_hal.h"
67
#include <stdbool.h>
78
#include <stdint.h>
89
#include <stdio.h>
910
#include <string.h>
11+
#include "FEB_RTD.h"
1012

1113
// /* ------------------- External handles ------------------- */
1214
extern I2C_HandleTypeDef hi2c1;
@@ -29,10 +31,15 @@ static uint32_t end_buzzer_tick = 0;
2931

3032
static IO_States_t state = {.switch_coolant_pump_radiator_fan = false,
3133
.switch_accumulator_fans = false,
32-
.button_rtd = false,
3334
.switch_logging = false,
35+
.button_rtd = false,
36+
.button_2 = false,
37+
.button_3 = false,
38+
.button_4 = false,
3439
.buzzer_enabled = false};
3540

41+
static HAL_StatusTypeDef status;
42+
3643
// MARK: Initialization
3744
void FEB_IO_Init(void)
3845
{
@@ -41,7 +48,7 @@ void FEB_IO_Init(void)
4148
init_val[0] = 0b11100001;
4249
init_val[1] = 0b11111111;
4350

44-
FEB_I2C_Master_Transmit(&hi2c1, IOEXP_ADDR << 1, init_val, 2, HAL_MAX_DELAY);
51+
status = FEB_I2C_Master_Transmit(&hi2c1, IOEXP_ADDR << 1, init_val, 2, HAL_MAX_DELAY);
4552
}
4653

4754
// /* ------------------- Reset ------------------- */
@@ -136,7 +143,7 @@ void FEB_IO_Update_GPIO(void)
136143
uint8_t received_data[2];
137144
memset(received_data, 0x00, sizeof(received_data));
138145

139-
FEB_I2C_Master_Receive(&hi2c1, IOEXP_ADDR << 1, received_data, 2, HAL_MAX_DELAY);
146+
status = FEB_I2C_Master_Receive(&hi2c1, IOEXP_ADDR << 1, received_data, 2, HAL_MAX_DELAY);
140147

141148
// 00010010 received_data
142149
// 00010000 (1 << 5)
@@ -145,10 +152,14 @@ void FEB_IO_Update_GPIO(void)
145152
// printf("[-] %X %X\n", received_data[0], received_data[1]);
146153

147154
state.button_rtd = (bool)(received_data[0] & (1 << 1));
155+
state.button_2 = (bool)(received_data[0] & (1 << 2));
156+
state.button_3 = (bool)(received_data[0] & (1 << 3));
157+
state.button_4 = (bool)(received_data[0] & (1 << 4));
148158

149159
state.switch_logging = !(bool)(received_data[1] & (1 << 1));
150-
state.switch_coolant_pump_radiator_fan = !(bool)(received_data[1] & (1 << 2));
151-
state.switch_accumulator_fans = !(bool)(received_data[1] & (1 << 3));
160+
state.switch_accumulator_fans = !(bool)(received_data[1] & (1 << 2));
161+
state.switch_coolant_pump_radiator_fan = !(bool)(received_data[1] & (1 << 3));
162+
state.switch_4 = !(bool)(received_data[1] & (1 << 0));
152163

153164
FEB_IO_Update_Buzzer();
154165
}
@@ -163,7 +174,7 @@ void FEB_IO_Set_Buzzer(bool new_state)
163174
send_val[0] = state.buzzer_enabled ? 0b11100000 : 0b11100001;
164175
send_val[1] = 0b11111111;
165176

166-
FEB_I2C_Master_Transmit(&hi2c1, IOEXP_ADDR << 1, send_val, 2, HAL_MAX_DELAY);
177+
status = FEB_I2C_Master_Transmit(&hi2c1, IOEXP_ADDR << 1, send_val, 2, HAL_MAX_DELAY);
167178
}
168179

169180
void FEB_IO_Update_Buzzer(void)
@@ -247,3 +258,19 @@ IO_States_t FEB_IO_GetLastIOStates(void)
247258
{
248259
return state;
249260
}
261+
262+
bool FEB_IO_StatusOk(void)
263+
{
264+
return status != HAL_ERROR && status != HAL_TIMEOUT;
265+
}
266+
267+
void StartIoLoop(void *argument)
268+
{
269+
for (;;)
270+
{
271+
FEB_IO_Update_GPIO();
272+
FEB_State_Update_RTD();
273+
274+
osDelay(1);
275+
}
276+
}

DASH/Core/User/Src/FEB_UI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void StartDisplayTask(void *argument)
9494
// last_blink = lv_tick_get();
9595
// }
9696

97-
osDelay(500); // slower delay so you can see it changing
97+
osDelay(1); // slower delay so you can see it changing
9898
}
9999
}
100100

0 commit comments

Comments
 (0)