Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added non-critical faults and included test in can_handler.c #87

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Core/Inc/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ typedef enum {
} bms_fault_t;
// clang-format on

/**
* @brief Enuemrated possible non-critical fault codes for the BMS
* @note the values increase at powers of two to perform bitwise operations on a main fault code
* to set or get the error codes
*/
typedef enum {
/* non-critical cases */
FAILED_CAN_RECEIVAL = 0x1,

} bms_nc_fault_t;

/**
* @brief Stores critical values for the pack, and where that critical value can be found
*
Expand Down Expand Up @@ -123,6 +134,14 @@ typedef struct {
bool is_charger_connected;
} acc_data_t;

typedef struct
{
bms_fault_t fault_code;

uint8_t can_fault;
} nc_fault_collection_t;


/**
* @brief Represents individual BMS states
*/
Expand Down
9 changes: 9 additions & 0 deletions Core/Inc/stateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ uint32_t sm_fault_return(acc_data_t *accData);
*/
uint32_t sm_fault_eval(fault_eval_t* index);

/**
* @brief Used to collect non-critical fault codes to append to the current status
*
* @param nc_fault_data
* @param fault_code
* @return fault_code
*/
void sm_nc_fault_collect(nc_fault_collection_t *nc_fault_data);

/**
* @brief handles the state machine, calls the appropriate handler function and runs every loop functions
*
Expand Down
8 changes: 6 additions & 2 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#include "analyzer.h"
#include "ringbuffer.h"
#include "can_handler.h"
#include "stateMachine.h"

ringbuffer_t* can1_rx_queue = NULL;
ringbuffer_t* can2_rx_queue = NULL;
nc_fault_collection_t nc_fault_collection;

void can_receive_callback(CAN_HandleTypeDef* hcan)
{
CAN_RxHeaderTypeDef rx_header;
can_msg_t new_msg;

/* Read in CAN message */
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, new_msg.data) != HAL_OK) {


nc_fault_collection.fault_code = FAILED_CAN_RECEIVAL;
sm_nc_fault_collect(&nc_fault_collection);
// TODO add non crtical fault capability - could create one for failed can receieve
return;
}

new_msg.len = rx_header.DLC;
new_msg.id = rx_header.StdId;
if (hcan == &hcan1) {
Expand Down
8 changes: 8 additions & 0 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern UART_HandleTypeDef huart4;

acc_data_t* prevAccData;
uint32_t bms_fault = FAULTS_CLEAR;
uint32_t bms_nc_fault = FAULTS_CLEAR;

BMSState_t current_state = BOOT_STATE;
uint32_t previousFault = 0;
Expand Down Expand Up @@ -291,6 +292,13 @@ uint32_t sm_fault_eval(fault_eval_t* index)
return 0;
}

void sm_nc_fault_collect(nc_fault_collection_t *nc_fault_data) {
switch (nc_fault_data->fault_code) {
case FAILED_CAN_RECEIVAL: nc_fault_data->can_fault += 1; break;
default: break;
}
}

bool sm_charging_check(acc_data_t* bmsdata)
{
if (!compute_charger_connected())
Expand Down
Loading