@@ -5,15 +5,13 @@ uint32_t safety_rx_invalid = 0;
55uint32_t tx_buffer_overflow = 0 ;
66uint32_t rx_buffer_overflow = 0 ;
77
8- can_health_t can_health [CAN_HEALTH_ARRAY_SIZE ] = {{0 }, {0 }, {0 }};
8+ can_health_t can_health [PANDA_CAN_CNT ] = {{0 }, {0 }, {0 }};
99
1010// Ignition detected from CAN meessages
1111bool ignition_can = false;
1212uint32_t ignition_can_cnt = 0U ;
1313
14- int can_live = 0 ;
15- int pending_can_live = 0 ;
16- int can_silent = ALL_CAN_SILENT ;
14+ bool can_silent = true;
1715bool can_loopback = false;
1816
1917// ********************* instantiate queues *********************
@@ -39,7 +37,7 @@ can_buffer(tx3_q, CAN_TX_BUFFER_SIZE)
3937
4038// FIXME:
4139// cppcheck-suppress misra-c2012-9.3
42- can_ring * can_queues [CAN_QUEUES_ARRAY_SIZE ] = {& can_tx1_q , & can_tx2_q , & can_tx3_q };
40+ can_ring * can_queues [PANDA_CAN_CNT ] = {& can_tx1_q , & can_tx2_q , & can_tx3_q };
4341
4442// ********************* interrupt safe queue *********************
4543bool can_pop (can_ring * q , CANPacket_t * elem ) {
@@ -130,11 +128,10 @@ void can_clear(can_ring *q) {
130128
131129// Helpers
132130// Panda: Bus 0=CAN1 Bus 1=CAN2 Bus 2=CAN3
133- bus_config_t bus_config [BUS_CONFIG_ARRAY_SIZE ] = {
131+ bus_config_t bus_config [PANDA_CAN_CNT ] = {
134132 { .bus_lookup = 0U , .can_num_lookup = 0U , .forwarding_bus = -1 , .can_speed = 5000U , .can_data_speed = 20000U , .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
135133 { .bus_lookup = 1U , .can_num_lookup = 1U , .forwarding_bus = -1 , .can_speed = 5000U , .can_data_speed = 20000U , .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
136134 { .bus_lookup = 2U , .can_num_lookup = 2U , .forwarding_bus = -1 , .can_speed = 5000U , .can_data_speed = 20000U , .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
137- { .bus_lookup = 0xFFU , .can_num_lookup = 0xFFU , .forwarding_bus = -1 , .can_speed = 333U , .can_data_speed = 333U , .canfd_auto = false, .canfd_enabled = false, .brs_enabled = false, .canfd_non_iso = false },
138135};
139136
140137void can_init_all (void ) {
@@ -158,20 +155,18 @@ void can_set_forwarding(uint8_t from, uint8_t to) {
158155#endif
159156
160157void ignition_can_hook (CANPacket_t * msg ) {
161- int bus = GET_BUS (msg );
162- if (bus == 0 ) {
163- int addr = GET_ADDR (msg );
158+ if (msg -> bus == 0U ) {
164159 int len = GET_LEN (msg );
165160
166161 // GM exception
167- if ((addr == 0x1F1 ) && (len == 8 )) {
162+ if ((msg -> addr == 0x1F1U ) && (len == 8 )) {
168163 // SystemPowerMode (2=Run, 3=Crank Request)
169164 ignition_can = (msg -> data [0 ] & 0x2U ) != 0U ;
170165 ignition_can_cnt = 0U ;
171166 }
172167
173168 // Rivian R1S/T GEN1 exception
174- if ((addr == 0x152 ) && (len == 8 )) {
169+ if ((msg -> addr == 0x152U ) && (len == 8 )) {
175170 // 0x152 overlaps with Subaru pre-global which has this bit as the high beam
176171 int counter = msg -> data [1 ] & 0xFU ; // max is only 14
177172
@@ -185,7 +180,7 @@ void ignition_can_hook(CANPacket_t *msg) {
185180 }
186181
187182 // Tesla Model 3/Y exception
188- if ((addr == 0x221 ) && (len == 8 )) {
183+ if ((msg -> addr == 0x221U ) && (len == 8 )) {
189184 // 0x221 overlaps with Rivian which has random data on byte 0
190185 int counter = msg -> data [6 ] >> 4 ;
191186
@@ -200,7 +195,7 @@ void ignition_can_hook(CANPacket_t *msg) {
200195 }
201196
202197 // Mazda exception
203- if ((addr == 0x9E ) && (len == 8 )) {
198+ if ((msg -> addr == 0x9EU ) && (len == 8 )) {
204199 ignition_can = (msg -> data [0 ] >> 5 ) == 0x6U ;
205200 ignition_can_cnt = 0U ;
206201 }
@@ -234,7 +229,7 @@ bool can_check_checksum(CANPacket_t *packet) {
234229
235230void can_send (CANPacket_t * to_push , uint8_t bus_number , bool skip_tx_hook ) {
236231 if (skip_tx_hook || safety_tx_hook (to_push ) != 0 ) {
237- if (bus_number < PANDA_BUS_CNT ) {
232+ if (bus_number < PANDA_CAN_CNT ) {
238233 // add CAN packet to send queue
239234 tx_buffer_overflow += can_push (can_queues [bus_number ], to_push ) ? 0U : 1U ;
240235 process_can (CAN_NUM_FROM_BUS_NUM (bus_number ));
0 commit comments