Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into 81-fault-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
tszwinglitw committed Jan 9, 2025
2 parents 6af98a0 + 0dfb523 commit 1cc76f3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define FAULT_CANID 0x703 // TODO: cleanup
#define NOISE_CANID 0x88
#define DEBUG_CANID 0x702
#define FAULT_TIMER_CANID 0x6FF

typedef struct {
uint32_t prev_tick;
Expand All @@ -47,6 +48,7 @@ typedef enum {
FAULT, // TODO: cleanup
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 @@ -193,6 +193,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 @@ -100,6 +100,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 @@ -117,6 +121,7 @@ void init_can_msg_config()
bms_can_msgs[FAULT] = fault_detail_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 @@ -164,6 +169,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 @@ -558,6 +558,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
31 changes: 16 additions & 15 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,28 +340,29 @@ bool sm_fault_eval(fault_eval_t *item)

if (is_timer_active(&item->timer)) {
if (!fault_present) {
printf("\t\t\t*******Fault cleared: %s\r\n", item->id);
cancel_timer(&item->timer);
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(&item->timer) && fault_present) {
printf("\t\t\t*******Faulted: %s\r\n", item->id);
// compute_send_fault_message(FAULT_STAT_FAULTED, item->data_1,
// item->lim_1);
return 1;
} else
if (is_timer_expired(&index->timer) && fault_present) {
printf("\t\t\t*******Faulted: %s\r\n", index->id);
compute_send_fault_timer_message(2, index->code,
index->data_1);
return index->code;
}

else
return 0;

}

else if (!is_timer_active(&item->timer) && fault_present) {
printf("\t\t\t*******Starting fault timer: %s\r\n", item->id);
start_timer(&item->timer, item->timeout);
// if (item->code == DISCHARGE_LIMIT_ENFORCEMENT_FAULT) {
// compute_send_fault_message(FAULT_STAT_TIMER_START, item->data_1,
// item->lim_1);
// }
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);
compute_send_fault_timer_message(1, index->code, index->data_1);

return 0;
}
Expand Down

0 comments on commit 1cc76f3

Please sign in to comment.