diff --git a/include/can.h b/include/can.h index e0a075b..aa2ae3a 100644 --- a/include/can.h +++ b/include/can.h @@ -50,5 +50,15 @@ bool can_is_rx_pending(can_data_t *hcan); bool can_send(can_data_t *hcan, struct gs_host_frame *frame); +/** return CAN->ESR register which contains tx/rx error counters and + * LEC (last error code). + */ uint32_t can_get_error_status(can_data_t *hcan); + +#define CAN_ERRCOUNT_THRESHOLD 15 /* send an error frame if tx/rx counters increase by more than this amount */ + +/** parse status value returned by can_get_error_status(). + * @param frame : will hold the generated error frame + * @return 1 when status changes (if any) need a new error frame sent + */ bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, struct gs_host_frame *frame); diff --git a/src/can.c b/src/can.c index d866a7e..80c0a54 100644 --- a/src/can.c +++ b/src/can.c @@ -290,10 +290,10 @@ bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, s should_send = true; } /* If either error counter increased by 15. */ - if (((int)last_tx_error_cnt + 15) < tx_error_cnt) { + if (((int)last_tx_error_cnt + CAN_ERRCOUNT_THRESHOLD) < tx_error_cnt) { should_send = true; } - if (((int)last_rx_error_cnt + 15) < rx_error_cnt) { + if (((int)last_rx_error_cnt + CAN_ERRCOUNT_THRESHOLD) < rx_error_cnt) { should_send = true; }