mirror of https://github.com/commaai/panda.git
Change can_health request method (#1472)
* init * fix typo * remove tx lost as fake and add rx lsot
This commit is contained in:
parent
0f4e8f79f5
commit
9d56e80390
|
@ -91,14 +91,15 @@ void update_can_health_pkt(uint8_t can_number, bool error_irq) {
|
|||
can_health[can_number].transmit_error_cnt = ((esr_reg & CAN_ESR_TEC) >> CAN_ESR_TEC_Pos);
|
||||
}
|
||||
|
||||
// CAN error
|
||||
// ***************************** CAN *****************************
|
||||
// CANx_SCE IRQ Handler
|
||||
void can_sce(uint8_t can_number) {
|
||||
ENTER_CRITICAL();
|
||||
update_can_health_pkt(can_number, true);
|
||||
EXIT_CRITICAL();
|
||||
}
|
||||
|
||||
// ***************************** CAN *****************************
|
||||
// CANx_TX IRQ Handler
|
||||
void process_can(uint8_t can_number) {
|
||||
if (can_number != 0xffU) {
|
||||
|
||||
|
@ -154,12 +155,11 @@ void process_can(uint8_t can_number) {
|
|||
}
|
||||
}
|
||||
|
||||
update_can_health_pkt(can_number, false);
|
||||
EXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
|
||||
// CAN receive handlers
|
||||
// CANx_RX0 IRQ Handler
|
||||
// blink blue when we are receiving CAN messages
|
||||
void can_rx(uint8_t can_number) {
|
||||
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
|
||||
|
@ -214,7 +214,6 @@ void can_rx(uint8_t can_number) {
|
|||
rx_buffer_overflow += can_push(&can_rx_q, &to_push) ? 0U : 1U;
|
||||
|
||||
// next
|
||||
update_can_health_pkt(can_number, false);
|
||||
CAN->RF0R |= CAN_RF0R_RFOM0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ void can_set_gmlan(uint8_t bus) {
|
|||
print("GMLAN not available on red panda\n");
|
||||
}
|
||||
|
||||
// ***************************** CAN *****************************
|
||||
void update_can_health_pkt(uint8_t can_number, bool error_irq) {
|
||||
ENTER_CRITICAL();
|
||||
|
||||
|
@ -61,11 +60,11 @@ void update_can_health_pkt(uint8_t can_number, bool error_irq) {
|
|||
|
||||
if (error_irq) {
|
||||
can_health[can_number].total_error_cnt += 1U;
|
||||
if ((CANx->IR & (FDCAN_IR_TEFL)) != 0) {
|
||||
can_health[can_number].total_tx_lost_cnt += 1U;
|
||||
if ((CANx->IR & (FDCAN_IR_RF0L)) != 0) {
|
||||
can_health[can_number].total_rx_lost_cnt += 1U;
|
||||
}
|
||||
// Actually reset can core only on arbitration or data phase errors and when CEL couter reaches at least 100 errors
|
||||
if (((CANx->IR & (FDCAN_IR_PED | FDCAN_IR_PEA)) != 0) && (((ecr_reg & FDCAN_ECR_CEL) >> FDCAN_ECR_CEL_Pos) == 100U)) {
|
||||
if (((CANx->IR & (FDCAN_IR_PED | FDCAN_IR_PEA)) != 0) && (((ecr_reg & FDCAN_ECR_CEL) >> FDCAN_ECR_CEL_Pos) >= 100U)) {
|
||||
llcan_clear_send(CANx);
|
||||
}
|
||||
// Clear error interrupts
|
||||
|
@ -74,6 +73,8 @@ void update_can_health_pkt(uint8_t can_number, bool error_irq) {
|
|||
EXIT_CRITICAL();
|
||||
}
|
||||
|
||||
// ***************************** CAN *****************************
|
||||
// FDCANx_IT1 IRQ Handler (TX)
|
||||
void process_can(uint8_t can_number) {
|
||||
if (can_number != 0xffU) {
|
||||
ENTER_CRITICAL();
|
||||
|
@ -128,12 +129,11 @@ void process_can(uint8_t can_number) {
|
|||
}
|
||||
}
|
||||
|
||||
update_can_health_pkt(can_number, false);
|
||||
EXIT_CRITICAL();
|
||||
}
|
||||
}
|
||||
|
||||
// CAN receive handlers
|
||||
// FDCANx_IT0 IRQ Handler (RX and errors)
|
||||
// blink blue when we are receiving CAN messages
|
||||
void can_rx(uint8_t can_number) {
|
||||
FDCAN_GlobalTypeDef *CANx = CANIF_FROM_CAN_NUM(can_number);
|
||||
|
@ -217,8 +217,9 @@ void can_rx(uint8_t can_number) {
|
|||
}
|
||||
|
||||
// Error handling
|
||||
bool error_irq = ((CANx->IR & (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EP | FDCAN_IR_BO | FDCAN_IR_RF0L)) != 0);
|
||||
update_can_health_pkt(can_number, error_irq);
|
||||
if ((CANx->IR & (FDCAN_IR_PED | FDCAN_IR_PEA | FDCAN_IR_EP | FDCAN_IR_BO | FDCAN_IR_RF0L | FDCAN_IR_ELO)) != 0) {
|
||||
update_can_health_pkt(can_number, true);
|
||||
}
|
||||
}
|
||||
|
||||
void FDCAN1_IT0_IRQ_Handler(void) { can_rx(0); }
|
||||
|
|
|
@ -167,6 +167,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
|
|||
case 0xc2:
|
||||
COMPILE_TIME_ASSERT(sizeof(can_health_t) <= USBPACKET_MAX_SIZE);
|
||||
if (req->param1 < 3U) {
|
||||
update_can_health_pkt(req->param1, false);
|
||||
can_health[req->param1].can_speed = (bus_config[req->param1].can_speed / 10U);
|
||||
can_health[req->param1].can_data_speed = (bus_config[req->param1].can_data_speed / 10U);
|
||||
can_health[req->param1].canfd_enabled = bus_config[req->param1].canfd_enabled;
|
||||
|
|
Loading…
Reference in New Issue