Skip to content

Commit

Permalink
set up bms can watchdog
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Mar 17, 2024
1 parent d85e8d3 commit 6d1764f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ void vCanDispatch(void* pv_params);
extern osThreadId_t can_dispatch_handle;
extern const osThreadAttr_t can_dispatch_attributes;

void vBMSCANMonitor(void* pv_params);
extern osThreadId_t bms_can_monitor_handle;
extern const osThreadAttr_t bms_can_monitor_attributes;

int8_t queue_can_msg(can_msg_t msg);
can_t* init_can1(CAN_HandleTypeDef* hcan);

Expand Down
1 change: 1 addition & 0 deletions Core/Inc/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef enum {
SHUTDOWN_MONITOR_FAULT = 0x40,
DTI_ROUTING_FAULT = 0x80,
STEERINGIO_ROUTING_FAULT = 0x100,
BMS_CAN_MONITOR_FAULT = 0x120,
MAX_FAULTS
} fault_code_t;

Expand Down
45 changes: 44 additions & 1 deletion Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
#include "fault.h"
#include "steeringio.h"
#include "serial_monitor.h"
#include "timer.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#define CAN_MSG_QUEUE_SIZE 25 /* messages */
#define CAN_TEST_MSG 0x069 /* CAN TEST MSG */
#define CAN_BMS_MONITOR 0x070 /*BMS MONITOR WATCHDOG*/ /*Arbitrary*/

#define BMS_WATCHDOG_DURATION 10 /*Duration of btween petting bms monitor watchdog*/


/* Relevant Info for Initializing CAN 1 */
static uint16_t id_list[] = {
DTI_CANID_ERPM, DTI_CANID_CURRENTS, DTI_CANID_TEMPS_FAULT,
DTI_CANID_ID_IQ, DTI_CANID_SIGNALS, STEERING_CANID_IO, CAN_TEST_MSG
DTI_CANID_ID_IQ, DTI_CANID_SIGNALS, STEERING_CANID_IO, CAN_TEST_MSG,
CAN_BMS_MONITOR
};

void can1_callback(CAN_HandleTypeDef* hcan);
Expand Down Expand Up @@ -85,6 +91,7 @@ void can1_callback(CAN_HandleTypeDef* hcan)
break;
case CAN_TEST_MSG:
serial_print("UR MOM \n");
case CAN_BMS_MONITOR:
default:
break;
}
Expand Down Expand Up @@ -139,6 +146,42 @@ void vCanDispatch(void* pv_params)
}
}

osThreadId_t bms_can_monitor_handle;
osThreadAttr_t bms_can_monitor_attributes = {
.name = "BMSCANMonitor",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityLow1 /*Adjust priority*/
}

void vBMSCANMonitor(void* pv_params)
{

fault_data_t fault_data = { .id = BMS_CAN_MONITOR_FAULT, .severity = DEFCON1 }; /*Ask about severity*/

bms_can_queue = osMessageQueueNew(CAN_MSG_QUEUE_SIZE, sizeof(can_msg_t), NULL);

can_msg_t msg_from_queue;
HAL_StatusTypeDef msg_status;
can_t* can1 = (can_t*)pv_params;

nertimer_t* timer;

if (osOK == osMessageQueueGet(can_outbound_queue, &msg_from_queue, NULL, osWaitForever)) {
if (msg_from_queue.id == CAN_BMS_MONITOR) {
if (!is_timer_active(&timer)) {
start_timer(&timer, BMS_WATCHDOG_DURATION);
} else {
cancel_timer(&timer);
}
}
}

if (is_timer_expired(&timer)) {
fault_data.diag = "Failing To Receive CAN Messages from Sheperd";
queue_fault(&fault_data);
}
}

int8_t queue_can_msg(can_msg_t msg)
{
if (!can_outbound_queue)
Expand Down
1 change: 1 addition & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ int main(void)
dti_router_handle = osThreadNew(vDTIRouter, mc, &dti_router_attributes);
// steeringio_router_handle = osThreadNew(vSteeringIORouter, wheel, &steeringio_router_attributes);
can_dispatch_handle = osThreadNew(vCanDispatch, can1, &can_dispatch_attributes);
bms_can_monitor_handle = osThreadNew(vBMSCANMonitor, can1 &bms_can_monitor_attributes);
serial_monitor_handle = osThreadNew(vSerialMonitor, NULL, &serial_monitor_attributes);

/* Control Logic */
Expand Down

0 comments on commit 6d1764f

Please sign in to comment.