@@ -510,7 +510,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
510510 ********************************************************************** */
511511 else if (p == IRQ_SCI_UART && cfg != NULL ) {
512512 uart_cfg_t *p_cfg = (uart_cfg_t *)cfg;
513+
513514 if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
515+ if (last_interrupt_index + UART_INTERRUPT_COUNT > PROG_IRQ_NUM){
516+ rv = false ;
517+ goto end_config;
518+ }
514519 /* TX interrupt */
515520 p_cfg->txi_ipl = UART_SCI_PRIORITY;
516521 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -596,13 +601,18 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
596601
597602#if WIRE_HOWMANY > 0
598603 /* I2C true NOT SCI */
599- else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
604+ else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
605+
600606 I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
601607 i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
602608 i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
603609 mcfg->ipl = I2C_MASTER_PRIORITY;
604610
605611 if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
612+ if (last_interrupt_index + WIRE_MASTER_INTERRUPT_COUNT >= PROG_IRQ_NUM){
613+ rv = false ;
614+ goto end_config;
615+ }
606616 /* TX interrupt */
607617 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
608618 scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -643,11 +653,15 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
643653 R_BSP_IrqEnable (mcfg->eri_irq );
644654 }
645655 /* I2C SCI MASTER (only) */
646- else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
656+ else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
647657 I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
648658 i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
649659 mcfg->ipl = I2C_MASTER_PRIORITY;
650- if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
660+ if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
661+ if (last_interrupt_index + WIRE_SCI_MASTER_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
662+ rv = false ;
663+ goto end_config;
664+ }
651665 /* TX interrupt */
652666 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
653667 *(irq_ptr + last_interrupt_index) = (uint32_t )sci_i2c_txi_isr;
@@ -691,8 +705,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
691705 i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
692706 scfg->ipl = I2C_SLAVE_PRIORITY;
693707 scfg->eri_ipl = I2C_SLAVE_PRIORITY;
694-
695- if (scfg->txi_irq == FSP_INVALID_VECTOR) {
708+
709+ if (scfg->txi_irq == FSP_INVALID_VECTOR) {
710+ if (last_interrupt_index + WIRE_SLAVE_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
711+ rv = false ;
712+ goto end_config;
713+ }
696714 /* TX interrupt */
697715 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
698716 scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -749,12 +767,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
749767 /* **********************************************************************
750768 SPI MASTER
751769 ********************************************************************** */
752- else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
770+ else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
753771 spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->ctrl ;
754772 spi_cfg_t * p_cfg = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->cfg ;
755773 uint8_t const hw_channel = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->hw_channel ;
756774
757775 if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
776+ if (last_interrupt_index + SPI_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
777+ rv = false ;
778+ goto end_config;
779+ }
758780 /* TX interrupt */
759781 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
760782 p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -797,12 +819,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
797819 /* **********************************************************************
798820 SCI SPI MASTER
799821 ********************************************************************** */
800- else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
822+ else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
801823 sci_spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->ctrl ;
802824 spi_cfg_t * p_cfg = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->cfg ;
803825 uint8_t const hw_channel = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->hw_channel ;
804826
805827 if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
828+ if (last_interrupt_index + SPI_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
829+ rv = false ;
830+ goto end_config;
831+ }
806832 /* TX interrupt */
807833 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
808834 p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -846,12 +872,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
846872 /* **********************************************************************
847873 CAN
848874 ********************************************************************** */
849- else if (p == IRQ_CAN && cfg != NULL ) {
875+ else if (p == IRQ_CAN && cfg != NULL ) {
850876 can_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
851877 can_cfg_t * p_cfg = reinterpret_cast <CanIrqReq_t *>(cfg)->cfg ;
852878 p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
853879
854880 if (p_cfg->error_irq == FSP_INVALID_VECTOR) {
881+ if (last_interrupt_index + CAN_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
882+ rv = false ;
883+ goto end_config;
884+ }
855885 /* Error interrupt */
856886 p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
857887 *(irq_ptr + last_interrupt_index) = (uint32_t )can_error_isr;
@@ -906,6 +936,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
906936 p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
907937
908938 if (p_cfg->error_irq == FSP_INVALID_VECTOR) {
939+ if (last_interrupt_index + CANFD_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
940+ rv = false ;
941+ goto end_config;
942+ }
909943 /* Error interrupt */
910944 p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
911945 *(irq_ptr + last_interrupt_index) = (uint32_t )canfd_error_isr;
@@ -941,7 +975,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
941975 sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
942976 /* SDCARD_ACCESS */
943977 if (sd_cfg->access_irq == FSP_INVALID_VECTOR) {
944-
978+ if (last_interrupt_index + SD_INTERRUPT_COUNT >= PROG_IRQ_NUM){
979+ rv = false ;
980+ goto end_config;
981+ }
945982 sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
946983 sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
947984 *(irq_ptr + last_interrupt_index) = (uint32_t )sdhimmc_accs_isr;
0 commit comments