Skip to content

Commit

Permalink
feat(error): keep latest expired error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonidotpy committed Mar 6, 2024
1 parent f6ae651 commit 06edaf4
Show file tree
Hide file tree
Showing 5 changed files with 2,139 additions and 2,128 deletions.
1 change: 1 addition & 0 deletions mainboard/Inc/error/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ bool error_reset(error_id type, uint8_t offset);
size_t error_get_fatal();
size_t error_count();
void error_dump(error_t errors[]);
error_id error_get_latest_expired(void);
bool compare_timeouts(error_t *a, error_t *b);

void _error_handle_tim_oc_irq();
Expand Down
10 changes: 8 additions & 2 deletions mainboard/Src/error/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const uint32_t error_timeouts[ERROR_NUM_ERRORS] = {
};

llist er_list = NULL;
error_id latest_expired_error = ERROR_NUM_ERRORS;

/**
* @returns The time left before the error becomes fatal
Expand Down Expand Up @@ -154,6 +155,7 @@ error_t *error_get_top() {
bool error_set_fatal(error_t *error) {
if (error != NULL && error->state != STATE_FATAL) {
error->state = STATE_FATAL;
latest_expired_error = error->id;
return true;
}
return false;
Expand Down Expand Up @@ -219,7 +221,11 @@ void error_dump(error_t errors[]) {
llist_export(er_list, (void *)errors, sizeof(error_t));
}

error_id error_get_latest_expired(void) {
return latest_expired_error;
}

void _error_handle_tim_oc_irq() {
error_set_fatal(error_get_top());
HAL_TIM_OC_Stop_IT(&HTIM_ERR, TIM_CHANNEL_1);
}
error_set_fatal(error_get_top());
}
2 changes: 1 addition & 1 deletion mainboard/Src/feedback.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ void feedback_get_all_states(feedback_feed_t out_value[FEEDBACK_N]) {
// if (index < FEEDBACK_MUX_N)
// return FEEDBACK_CONVERT_ADC_MUX_TO_VOLTAGE(feedbacks[index]) < FEEDBACK_MUX_ANALOG_THRESHOLD_L;
// return FEEDBACK_CONVERT_ADC_SD_TO_VOLTAGE(feedbacks[index]) < FEEDBACK_SD_ANALOG_THRESHOLD_L;
// }
// }
3 changes: 3 additions & 0 deletions mainboard/Src/peripherals/can_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ HAL_StatusTypeDef can_car_send(uint16_t id) {
error_dump(errors);

for(size_t i = 0; i < error_count(); ++i) {
if (error_get_latest_expired() == errors[i].id)
errors[i].state = STATE_FATAL;

switch(errors[i].id) {
case ERROR_CELL_LOW_VOLTAGE:
if (errors[i].state == STATE_WARNING)
Expand Down

0 comments on commit 06edaf4

Please sign in to comment.