mirror of
https://github.com/candle-usb/candleLight_fw.git
synced 2025-01-28 06:02:52 +08:00
remove triggering error message based on counter values
Since all bit errors already trigger sending a error msg, remove the code triggering on counters going upwards, since they are send anyway. See [1] "This if statement doesn't normally do anything", get rid of it. [1] https://github.com/candle-usb/candleLight_fw/pull/61
This commit is contained in:
parent
d991308d63
commit
9a663007f5
@ -57,8 +57,6 @@ bool can_send(can_data_t *hcan, struct gs_host_frame *frame);
|
||||
*/
|
||||
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
|
||||
|
30
src/can.c
30
src/can.c
@ -272,7 +272,13 @@ bool can_send(can_data_t *hcan, struct gs_host_frame *frame)
|
||||
uint32_t can_get_error_status(can_data_t *hcan)
|
||||
{
|
||||
CAN_TypeDef *can = hcan->instance;
|
||||
return can->ESR;
|
||||
|
||||
uint32_t err = can->ESR;
|
||||
|
||||
/* Write 7 to LEC so we know if it gets set to the same thing again */
|
||||
can->ESR = 7<<4;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static bool status_is_active(uint32_t err)
|
||||
@ -286,6 +292,7 @@ bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, s
|
||||
* whether there's anything worth sending. This variable tracks that final
|
||||
* result. */
|
||||
bool should_send = false;
|
||||
(void) hcan;
|
||||
|
||||
frame->echo_id = 0xFFFFFFFF;
|
||||
frame->can_id = CAN_ERR_FLAG | CAN_ERR_CRTL;
|
||||
@ -323,23 +330,6 @@ bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, s
|
||||
frame->data[6] = tx_error_cnt;
|
||||
frame->data[7] = rx_error_cnt;
|
||||
|
||||
uint8_t last_tx_error_cnt = (last_err>>16) & 0xFF;
|
||||
uint8_t last_rx_error_cnt = (last_err>>24) & 0xFF;
|
||||
/* If either error counter transitioned to/from 0. */
|
||||
if ((tx_error_cnt == 0) != (last_tx_error_cnt == 0)) {
|
||||
should_send = true;
|
||||
}
|
||||
if ((rx_error_cnt == 0) != (last_rx_error_cnt == 0)) {
|
||||
should_send = true;
|
||||
}
|
||||
/* If either error counter increased by 15. */
|
||||
if (((int)last_tx_error_cnt + CAN_ERRCOUNT_THRESHOLD) < tx_error_cnt) {
|
||||
should_send = true;
|
||||
}
|
||||
if (((int)last_rx_error_cnt + CAN_ERRCOUNT_THRESHOLD) < rx_error_cnt) {
|
||||
should_send = true;
|
||||
}
|
||||
|
||||
if (err & CAN_ESR_EPVF) {
|
||||
frame->data[1] |= CAN_ERR_CRTL_RX_PASSIVE | CAN_ERR_CRTL_TX_PASSIVE;
|
||||
if (!(last_err & CAN_ESR_EPVF)) {
|
||||
@ -389,9 +379,5 @@ bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, s
|
||||
break;
|
||||
}
|
||||
|
||||
CAN_TypeDef *can = hcan->instance;
|
||||
/* Write 7 to LEC so we know if it gets set to the same thing again */
|
||||
can->ESR = 7<<4;
|
||||
|
||||
return should_send;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user