Lines Matching full:can

8 /* Include soc.h prior to Zephyr CAN headers to pull in HAL fixups */
10 #include <zephyr/drivers/can.h>
11 #include <zephyr/drivers/can/transceiver.h>
66 CAN_TypeDef *can; /*!< CAN Registers*/ member
67 CAN_TypeDef *master_can; /*!< CAN Registers for shared filter */
69 void (*config_irq)(CAN_TypeDef *can);
118 CAN_TypeDef *can = cfg->can; in can_stm32_rx_isr_handler() local
125 while (can->RF0R & CAN_RF0R_FMP0) { in can_stm32_rx_isr_handler()
126 mbox = &can->sFIFOMailBox[0]; in can_stm32_rx_isr_handler()
147 can->RF0R |= CAN_RF0R_RFOM0; in can_stm32_rx_isr_handler()
150 if (can->RF0R & CAN_RF0R_FOVR0) { in can_stm32_rx_isr_handler()
161 CAN_TypeDef *can = cfg->can; in can_stm32_get_state() local
166 } else if (can->ESR & CAN_ESR_BOFF) { in can_stm32_get_state()
168 } else if (can->ESR & CAN_ESR_EPVF) { in can_stm32_get_state()
170 } else if (can->ESR & CAN_ESR_EWGF) { in can_stm32_get_state()
179 ((can->ESR & CAN_ESR_TEC) >> CAN_ESR_TEC_Pos); in can_stm32_get_state()
181 ((can->ESR & CAN_ESR_REC) >> CAN_ESR_REC_Pos); in can_stm32_get_state()
197 CAN_TypeDef *can = cfg->can; in can_stm32_bus_state_change_isr() local
199 switch (can->ESR & CAN_ESR_LEC) { in can_stm32_bus_state_change_isr()
223 can->ESR |= CAN_ESR_LEC; in can_stm32_bus_state_change_isr()
241 CAN_TypeDef *can = cfg->can; in can_stm32_tx_isr_handler() local
245 bus_off = can->ESR & CAN_ESR_BOFF; in can_stm32_tx_isr_handler()
247 if ((can->TSR & CAN_TSR_RQCP0) | bus_off) { in can_stm32_tx_isr_handler()
248 status = can->TSR & CAN_TSR_TXOK0 ? 0 : in can_stm32_tx_isr_handler()
249 can->TSR & CAN_TSR_TERR0 ? -EIO : in can_stm32_tx_isr_handler()
250 can->TSR & CAN_TSR_ALST0 ? -EBUSY : in can_stm32_tx_isr_handler()
254 can->TSR |= CAN_TSR_RQCP0; in can_stm32_tx_isr_handler()
258 if ((can->TSR & CAN_TSR_RQCP1) | bus_off) { in can_stm32_tx_isr_handler()
259 status = can->TSR & CAN_TSR_TXOK1 ? 0 : in can_stm32_tx_isr_handler()
260 can->TSR & CAN_TSR_TERR1 ? -EIO : in can_stm32_tx_isr_handler()
261 can->TSR & CAN_TSR_ALST1 ? -EBUSY : in can_stm32_tx_isr_handler()
265 can->TSR |= CAN_TSR_RQCP1; in can_stm32_tx_isr_handler()
269 if ((can->TSR & CAN_TSR_RQCP2) | bus_off) { in can_stm32_tx_isr_handler()
270 status = can->TSR & CAN_TSR_TXOK2 ? 0 : in can_stm32_tx_isr_handler()
271 can->TSR & CAN_TSR_TERR2 ? -EIO : in can_stm32_tx_isr_handler()
272 can->TSR & CAN_TSR_ALST2 ? -EBUSY : in can_stm32_tx_isr_handler()
276 can->TSR |= CAN_TSR_RQCP2; in can_stm32_tx_isr_handler()
280 if (can->TSR & CAN_TSR_TME) { in can_stm32_tx_isr_handler()
290 CAN_TypeDef *can = cfg->can; in can_stm32_isr() local
295 if (can->MSR & CAN_MSR_ERRI) { in can_stm32_isr()
297 can->MSR |= CAN_MSR_ERRI; in can_stm32_isr()
316 CAN_TypeDef *can = cfg->can; in can_stm32_state_change_isr() local
319 if (can->MSR & CAN_MSR_ERRI) { in can_stm32_state_change_isr()
322 can->MSR |= CAN_MSR_ERRI; in can_stm32_state_change_isr()
328 static int can_stm32_enter_init_mode(CAN_TypeDef *can) in can_stm32_enter_init_mode() argument
332 can->MCR |= CAN_MCR_INRQ; in can_stm32_enter_init_mode()
335 while ((can->MSR & CAN_MSR_INAK) == 0U) { in can_stm32_enter_init_mode()
337 can->MCR &= ~CAN_MCR_INRQ; in can_stm32_enter_init_mode()
345 static int can_stm32_leave_init_mode(CAN_TypeDef *can) in can_stm32_leave_init_mode() argument
349 can->MCR &= ~CAN_MCR_INRQ; in can_stm32_leave_init_mode()
352 while ((can->MSR & CAN_MSR_INAK) != 0U) { in can_stm32_leave_init_mode()
361 static int can_stm32_leave_sleep_mode(CAN_TypeDef *can) in can_stm32_leave_sleep_mode() argument
365 can->MCR &= ~CAN_MCR_SLEEP; in can_stm32_leave_sleep_mode()
368 while ((can->MSR & CAN_MSR_SLAK) != 0) { in can_stm32_leave_sleep_mode()
394 CAN_TypeDef *can = cfg->can; in can_stm32_start() local
407 LOG_ERR("failed to enable CAN transceiver (err %d)", ret); in can_stm32_start()
414 ret = can_stm32_leave_init_mode(can); in can_stm32_start()
419 /* Attempt to disable the CAN transceiver in case of error */ in can_stm32_start()
439 CAN_TypeDef *can = cfg->can; in can_stm32_stop() local
449 ret = can_stm32_enter_init_mode(can); in can_stm32_stop()
460 can->TSR |= CAN_TSR_ABRQ2 | CAN_TSR_ABRQ1 | CAN_TSR_ABRQ0; in can_stm32_stop()
465 LOG_ERR("failed to enable CAN transceiver (err %d)", ret); in can_stm32_stop()
482 CAN_TypeDef *can = cfg->can; in can_stm32_set_mode() local
504 can->BTR |= CAN_BTR_LBKM; in can_stm32_set_mode()
506 can->BTR &= ~CAN_BTR_LBKM; in can_stm32_set_mode()
511 can->BTR |= CAN_BTR_SILM; in can_stm32_set_mode()
513 can->BTR &= ~CAN_BTR_SILM; in can_stm32_set_mode()
518 can->MCR |= CAN_MCR_NART; in can_stm32_set_mode()
520 can->MCR &= ~CAN_MCR_NART; in can_stm32_set_mode()
526 can->MCR &= ~CAN_MCR_ABOM; in can_stm32_set_mode()
528 can->MCR |= CAN_MCR_ABOM; in can_stm32_set_mode()
543 CAN_TypeDef *can = cfg->can; in can_stm32_set_timing() local
553 can->BTR = (can->BTR & ~(CAN_BTR_SJW_Msk | CAN_BTR_BRP_Msk | in can_stm32_set_timing()
599 CAN_TypeDef *can = cfg->can; in can_stm32_init() local
611 LOG_ERR("CAN transceiver not ready"); in can_stm32_init()
631 LOG_ERR("CAN pinctrl setup failed (%d)", ret); in can_stm32_init()
635 ret = can_stm32_enter_init_mode(can); in can_stm32_init()
641 ret = can_stm32_leave_sleep_mode(can); in can_stm32_init()
648 bank_offset = (cfg->can == cfg->master_can) ? 0 : CAN_STM32_NUM_FILTER_BANKS; in can_stm32_init()
653 can->MCR &= ~CAN_MCR_TTCM & ~CAN_MCR_ABOM & ~CAN_MCR_AWUM & in can_stm32_init()
656 can->MCR |= CAN_MCR_TTCM; in can_stm32_init()
660 can->MCR |= CAN_MCR_ABOM; in can_stm32_init()
665 LOG_ERR("Can't find timing for given param"); in can_stm32_init()
684 cfg->config_irq(can); in can_stm32_init()
685 can->IER |= CAN_IER_TMEIE; in can_stm32_init()
696 CAN_TypeDef *can = cfg->can; in can_stm32_set_state_change_callback() local
702 can->IER &= ~(CAN_IER_BOFIE | CAN_IER_EPVIE | CAN_IER_EWGIE); in can_stm32_set_state_change_callback()
704 can->IER |= CAN_IER_BOFIE | CAN_IER_EPVIE | CAN_IER_EWGIE; in can_stm32_set_state_change_callback()
713 CAN_TypeDef *can = cfg->can; in can_stm32_recover() local
725 if (!(can->ESR & CAN_ESR_BOFF)) { in can_stm32_recover()
733 ret = can_stm32_enter_init_mode(can); in can_stm32_recover()
738 can_stm32_leave_init_mode(can); in can_stm32_recover()
742 while (can->ESR & CAN_ESR_BOFF) { in can_stm32_recover()
763 CAN_TypeDef *can = cfg->can; in can_stm32_send() local
783 LOG_ERR("unsupported CAN frame flags 0x%02x", frame->flags); in can_stm32_send()
791 if (can->ESR & CAN_ESR_BOFF) { in can_stm32_send()
796 transmit_status_register = can->TSR; in can_stm32_send()
805 transmit_status_register = can->TSR; in can_stm32_send()
810 mailbox = &can->sTxMailBox[0]; in can_stm32_send()
814 mailbox = &can->sTxMailBox[1]; in can_stm32_send()
818 mailbox = &can->sTxMailBox[2]; in can_stm32_send()
901 CAN_TypeDef *can = cfg->master_can; in can_stm32_set_filter() local
908 if (cfg->can != cfg->master_can) { in can_stm32_set_filter()
909 /* CAN slave instance: start with offset */ in can_stm32_set_filter()
936 LOG_DBG("Adding filter_id %d, CAN ID: 0x%x, mask: 0x%x", in can_stm32_set_filter()
940 can->FMR |= CAN_FMR_FINIT; in can_stm32_set_filter()
942 can_stm32_set_filter_bank(filter_id, &can->sFilterRegister[bank_num], in can_stm32_set_filter()
946 can->FA1R |= 1U << bank_num; in can_stm32_set_filter()
947 can->FMR &= ~(CAN_FMR_FINIT); in can_stm32_set_filter()
975 LOG_ERR("unsupported CAN filter flags 0x%02x", filter->flags); in can_stm32_add_rx_filter()
1003 CAN_TypeDef *can = cfg->master_can; in can_stm32_remove_rx_filter() local
1017 if (cfg->can != cfg->master_can) { in can_stm32_remove_rx_filter()
1050 can->FMR |= CAN_FMR_FINIT; in can_stm32_remove_rx_filter()
1052 can_stm32_set_filter_bank(filter_id, &can->sFilterRegister[bank_num], in can_stm32_remove_rx_filter()
1056 can->FA1R &= ~(1U << bank_num); in can_stm32_remove_rx_filter()
1060 can->FMR &= ~(CAN_FMR_FINIT); in can_stm32_remove_rx_filter()
1066 static DEVICE_API(can, can_api_funcs) = {
1100 static void config_can_##inst##_irq(CAN_TypeDef *can) \
1106 can->IER |= CAN_IER_TMEIE | CAN_IER_ERRIE | CAN_IER_FMPIE0 | \
1109 can->IER |= CAN_IER_LECIE; \
1114 static void config_can_##inst##_irq(CAN_TypeDef *can) \
1129 can->IER |= CAN_IER_TMEIE | CAN_IER_ERRIE | CAN_IER_FMPIE0 | \
1132 can->IER |= CAN_IER_LECIE; \
1141 .can = (CAN_TypeDef *)DT_INST_REG_ADDR(inst), \