Skip to content

Commit

Permalink
[Debug] - Add timer start/stop notices (#143)
Browse files Browse the repository at this point in the history
* Added CAN messages for timer start/stop

* Added CAN message for fault timers

* Formatting

* Changed format of fault timer CAN

* Changed fault_code to uint32_t

* Changed fault timer can id

* Removed calls to old fault timer CAN function

* Updated Embedded-Base submodule
  • Loading branch information
bjackson312006 authored Jan 6, 2025
1 parent 31400f3 commit 0dfb523
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define FAULT_CANID 0x703
#define NOISE_CANID 0x88
#define DEBUG_CANID 0x702
#define FAULT_TIMER_CANID 0x6FF

typedef struct {
uint32_t prev_tick;
Expand All @@ -45,6 +46,7 @@ typedef enum {
FAULT,
NOISE,
DEBUG,
FAULT_TIMER,
RL_MSG_COUNT
} rate_lim_t;

Expand Down
3 changes: 3 additions & 0 deletions Core/Inc/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ void compute_send_segment_temp_message(acc_data_t *bmsdata);

void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl);

void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code,
uint16_t data_1);

/**
* @brief Send CAN message for debugging the car on the fly.
*
Expand Down
8 changes: 8 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void init_can_msg_config()
debug_msg.id = DEBUG_CANID;
debug_msg.len = 8; // yaml decodes this to 8 bytes

can_msg_t fault_timer_msg;
fault_timer_msg.id = FAULT_TIMER_CANID;
fault_timer_msg.len = 4;

// rl_data_t rl_discharge_data = { .msg_rate = 5000 };
// rl_data_t rl_charge_data = { .msg_rate = 0 };

Expand All @@ -112,6 +116,7 @@ void init_can_msg_config()
bms_can_msgs[FAULT] = fault_msg;
bms_can_msgs[NOISE] = noise_msg;
bms_can_msgs[DEBUG] = debug_msg;
bms_can_msgs[FAULT_TIMER] = fault_timer_msg;

// rl_data[DISCHARGE] = rl_discharge_data;
// rl_data[CHARGE] = rl_charge_data;
Expand Down Expand Up @@ -159,6 +164,9 @@ rl_data_t *get_rl_msg(uint32_t can_id)
case DEBUG_CANID:
return &rl_data[DEBUG];
break;
case FAULT_TIMER_CANID:
return &rl_data[FAULT_TIMER];
break;
default:
break;
}
Expand Down
24 changes: 24 additions & 0 deletions Core/Src/compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,30 @@ void compute_send_fault_message(uint8_t status, int16_t curr, int16_t in_dcl)
queue_can_msg(bms_can_msgs[FAULT]);
}

void compute_send_fault_timer_message(uint8_t start_stop, uint32_t fault_code,
uint16_t data_1)
{
struct __attribute__((__packed__)) {
uint8_t start_stop;
uint8_t fault_code;
int16_t data_1;
} fault_timer_msg_data;

fault_timer_msg_data.start_stop = start_stop;
fault_timer_msg_data.fault_code = log2(fault_code);
fault_timer_msg_data.data_1 = data_1;

endian_swap(&fault_timer_msg_data.fault_code,
sizeof(fault_timer_msg_data.fault_code));
endian_swap(&fault_timer_msg_data.data_1,
sizeof(fault_timer_msg_data.data_1));

memcpy(bms_can_msgs[FAULT_TIMER].data, &fault_timer_msg_data,
sizeof(fault_timer_msg_data));

queue_can_msg(bms_can_msgs[FAULT_TIMER]);
}

void compute_send_voltage_noise_message(acc_data_t *bmsdata)
{
struct __attribute__((__packed__)) {
Expand Down
11 changes: 5 additions & 6 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,15 @@ uint32_t sm_fault_eval(fault_eval_t *index)
if (!fault_present) {
printf("\t\t\t*******Fault cleared: %s\r\n", index->id);
cancel_timer(&index->timer);
compute_send_fault_timer_message(0, index->code,
index->data_1);
return 0;
}

if (is_timer_expired(&index->timer) && fault_present) {
printf("\t\t\t*******Faulted: %s\r\n", index->id);
compute_send_fault_message(2, index->data_1,
index->lim_1);
compute_send_fault_timer_message(2, index->code,
index->data_1);
return index->code;
}

Expand All @@ -321,10 +323,7 @@ uint32_t sm_fault_eval(fault_eval_t *index)
else if (!is_timer_active(&index->timer) && fault_present) {
printf("\t\t\t*******Starting fault timer: %s\r\n", index->id);
start_timer(&index->timer, index->timeout);
if (index->code == DISCHARGE_LIMIT_ENFORCEMENT_FAULT) {
compute_send_fault_message(1, index->data_1,
index->lim_1);
}
compute_send_fault_timer_message(1, index->code, index->data_1);

return 0;
}
Expand Down

0 comments on commit 0dfb523

Please sign in to comment.