31
31
#define TIMER_PRIORITY 12
32
32
#define ADC_PRIORITY 12
33
33
#define CAN_PRIORITY 12
34
+ #define CANFD_PRIORITY 12
34
35
#define FIRST_INT_SLOT_FREE 0
35
36
36
37
IRQManager::IRQManager () : last_interrupt_index{0 } {
@@ -868,19 +869,7 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
868
869
********************************************************************** */
869
870
else if (p == IRQ_CAN && cfg != NULL ) {
870
871
if ((last_interrupt_index + CAN_REQ_NUM) < PROG_IRQ_NUM ) {
871
- # if IS_CAN_FD
872
- canfd_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
873
- #define can_error_isr canfd_error_isr
874
- #define can_rx_isr canfd_rx_fifo_isr
875
- #define can_tx_isr canfd_channel_tx_isr
876
- // TODO: ATTENTION:
877
- // this is just a workaround, CANFD interrupts are different and somehow
878
- // more specialized
879
- // This is not expected to work until set_can_error_link_event and similar functions
880
- // are ported
881
- # else
882
872
can_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
883
- # endif
884
873
can_cfg_t * p_cfg = reinterpret_cast <CanIrqReq_t *>(cfg)->cfg ;
885
874
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
886
875
@@ -908,6 +897,7 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
908
897
}
909
898
#endif /* CAN_HOWMANY > 0 */
910
899
900
+
911
901
#if ETHERNET_HOWMANY > 0
912
902
/* **********************************************************************
913
903
ETHERNET
@@ -926,6 +916,41 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
926
916
}
927
917
}
928
918
#endif
919
+
920
+ #if CANFD_HOWMANY > 0
921
+ /* **********************************************************************
922
+ CANFD
923
+ ********************************************************************** */
924
+ else if (p == IRQ_CANFD && cfg != NULL ) {
925
+ if ((last_interrupt_index + CAN_REQ_NUM) < PROG_IRQ_NUM ) {
926
+ canfd_instance_ctrl_t * p_ctrl = reinterpret_cast <CanFdIrqReq_t *>(cfg)->ctrl ;
927
+ can_cfg_t * p_cfg = reinterpret_cast <CanFdIrqReq_t *>(cfg)->cfg ;
928
+ p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
929
+
930
+ /* Error interrupt */
931
+ p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
932
+ *(irq_ptr + last_interrupt_index) = (uint32_t )canfd_error_isr;
933
+ set_canfd_error_link_event (last_interrupt_index, p_cfg->channel );
934
+ R_BSP_IrqCfgEnable (p_cfg->error_irq , p_cfg->ipl , p_ctrl);
935
+ last_interrupt_index++;
936
+
937
+ /* Receive interrupt */
938
+ p_cfg->rx_irq = (IRQn_Type)last_interrupt_index;
939
+ *(irq_ptr + last_interrupt_index) = (uint32_t )canfd_rx_fifo_isr;
940
+ set_canfd_rx_link_event (last_interrupt_index, p_cfg->channel );
941
+ R_BSP_IrqCfgEnable (p_cfg->rx_irq , p_cfg->ipl , p_ctrl);
942
+ last_interrupt_index++;
943
+
944
+ /* Transmit interrupt */
945
+ p_cfg->tx_irq = (IRQn_Type)last_interrupt_index;
946
+ *(irq_ptr + last_interrupt_index) = (uint32_t )canfd_channel_tx_isr;
947
+ set_canfd_tx_link_event (last_interrupt_index, p_cfg->channel );
948
+ R_BSP_IrqCfgEnable (p_cfg->tx_irq , p_cfg->ipl , p_ctrl);
949
+ last_interrupt_index++;
950
+ }
951
+ }
952
+ #endif /* CANFD_HOWMANY > 0 */
953
+
929
954
else {
930
955
rv = false ;
931
956
}
@@ -1666,6 +1691,51 @@ void IRQManager::set_can_tx_link_event(int li, int ch)
1666
1691
#endif
1667
1692
}
1668
1693
1694
+ void IRQManager::set_canfd_error_link_event (int li, int ch)
1695
+ {
1696
+ if (0 ) {}
1697
+ #ifdef ELC_EVENT_CAN0_CHERR
1698
+ else if (ch == 0 ) {
1699
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN0_CHERR);
1700
+ }
1701
+ #endif
1702
+ #ifdef ELC_EVENT_CAN1_CHERR
1703
+ else if (ch == 1 ) {
1704
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN1_CHERR);
1705
+ }
1706
+ #endif
1707
+ }
1708
+
1709
+ void IRQManager::set_canfd_rx_link_event (int li, int ch)
1710
+ {
1711
+ if (0 ) {}
1712
+ #ifdef ELC_EVENT_CAN0_COMFRX
1713
+ else if (ch == 0 ) {
1714
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN0_COMFRX);
1715
+ }
1716
+ #endif
1717
+ #ifdef ELC_EVENT_CAN1_COMFRX
1718
+ else if (ch == 1 ) {
1719
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN1_COMFRX);
1720
+ }
1721
+ #endif
1722
+ }
1723
+
1724
+ void IRQManager::set_canfd_tx_link_event (int li, int ch)
1725
+ {
1726
+ if (0 ) {}
1727
+ #ifdef ELC_EVENT_CAN0_TX
1728
+ else if (ch == 0 ) {
1729
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN0_TX);
1730
+ }
1731
+ #endif
1732
+ #ifdef ELC_EVENT_CAN1_TX
1733
+ else if (ch == 1 ) {
1734
+ R_ICU->IELSR [li] = BSP_PRV_IELS_ENUM (EVENT_CAN1_TX);
1735
+ }
1736
+ #endif
1737
+ }
1738
+
1669
1739
bool IRQManager::set_dma_link_event (int li, int ch) {
1670
1740
bool rv = false ;
1671
1741
if (0 ) {}
0 commit comments