@@ -67,8 +67,10 @@ bool IRQManager::addADCScanEnd(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
6767 /* set the displacement to the "programmable" part of the table */
6868 irq_ptr += FIXED_IRQ_NUM;
6969 bool rv = true ;
70-
71- if (adc->cfg .scan_end_irq == FSP_INVALID_VECTOR) {
70+ if (last_interrupt_index >= PROG_IRQ_NUM){
71+ rv = false ;
72+ }
73+ else if (adc->cfg .scan_end_irq == FSP_INVALID_VECTOR) {
7274 if (set_adc_end_link_event (last_interrupt_index, adc->cfg .unit )) {
7375 adc->cfg .scan_end_ipl = TIMER_PRIORITY;
7476 adc->cfg .scan_end_irq = (IRQn_Type)last_interrupt_index;
@@ -101,8 +103,10 @@ bool IRQManager::addADCScanEndB(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
101103 /* set the displacement to the "programmable" part of the table */
102104 irq_ptr += FIXED_IRQ_NUM;
103105 bool rv = true ;
104-
105- if (adc->cfg .scan_end_b_irq == FSP_INVALID_VECTOR) {
106+ if (last_interrupt_index >= PROG_IRQ_NUM){
107+ rv = false ;
108+ }
109+ else if (adc->cfg .scan_end_b_irq == FSP_INVALID_VECTOR) {
106110 if (set_adc_end_b_link_event (last_interrupt_index, adc->cfg .unit )) {
107111 adc->cfg .scan_end_b_ipl = TIMER_PRIORITY;
108112 adc->cfg .scan_end_b_irq = (IRQn_Type)last_interrupt_index;
@@ -125,8 +129,10 @@ bool IRQManager::addADCWinCmpA(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
125129 /* set the displacement to the "programmable" part of the table */
126130 irq_ptr += FIXED_IRQ_NUM;
127131 bool rv = true ;
128-
129- if ( ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_a_irq == FSP_INVALID_VECTOR) {
132+ if (last_interrupt_index >= PROG_IRQ_NUM){
133+ rv = false ;
134+ }
135+ else if ( ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_a_irq == FSP_INVALID_VECTOR) {
130136 if (set_adc_win_a_link_event (last_interrupt_index, adc->cfg .unit )) {
131137 ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_a_ipl = TIMER_PRIORITY;
132138 ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_a_irq = (IRQn_Type)last_interrupt_index;
@@ -150,8 +156,10 @@ bool IRQManager::addADCWinCmpB(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
150156 /* set the displacement to the "programmable" part of the table */
151157 irq_ptr += FIXED_IRQ_NUM;
152158 bool rv = true ;
153-
154- if (((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_b_irq == FSP_INVALID_VECTOR) {
159+ if (last_interrupt_index >= PROG_IRQ_NUM){
160+ rv = false ;
161+ }
162+ else if (((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_b_irq == FSP_INVALID_VECTOR) {
155163 if (set_adc_win_b_link_event (last_interrupt_index, adc->cfg .unit )) {
156164 ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_b_ipl = TIMER_PRIORITY;
157165 ((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_b_irq = (IRQn_Type)last_interrupt_index;
@@ -177,8 +185,10 @@ bool IRQManager::addTimerOverflow(TimerIrqCfg_t &cfg, Irq_f fnc /* = nullptr */)
177185 /* set the displacement to the "programmable" part of the table */
178186 irq_ptr += FIXED_IRQ_NUM;
179187 bool rv = true ;
180-
181- if (cfg.base_cfg ->cycle_end_irq == FSP_INVALID_VECTOR) {
188+ if (last_interrupt_index >= PROG_IRQ_NUM){
189+ rv = false ;
190+ }
191+ else if (cfg.base_cfg ->cycle_end_irq == FSP_INVALID_VECTOR) {
182192 if (cfg.gpt_ext_cfg != nullptr ) {
183193 if (set_gpt_over_link_event (last_interrupt_index, cfg.base_cfg ->channel )) {
184194 cfg.base_cfg ->cycle_end_ipl = TIMER_PRIORITY;
@@ -224,7 +234,7 @@ bool IRQManager::addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullptr*/)
224234 irq_ptr += FIXED_IRQ_NUM;
225235 bool rv = true ;
226236
227- if (cfg.agt_ext_cfg != nullptr ) {
237+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
228238 /* not supported for AGT */
229239 rv = false ;
230240 }
@@ -258,7 +268,7 @@ bool IRQManager::addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
258268 irq_ptr += FIXED_IRQ_NUM;
259269 bool rv = true ;
260270
261- if (cfg.agt_ext_cfg != nullptr ) {
271+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
262272 /* not supported for AGT */
263273 rv = false ;
264274 }
@@ -292,7 +302,7 @@ bool IRQManager::addTimerCompareCaptureB(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
292302 irq_ptr += FIXED_IRQ_NUM;
293303 bool rv = true ;
294304
295- if (cfg.agt_ext_cfg != nullptr ) {
305+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
296306 /* not supported for AGT */
297307 rv = false ;
298308 }
@@ -326,8 +336,10 @@ bool IRQManager::addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc /* = nullptr */) {
326336 /* set the displacement to the "programmable" part of the table */
327337 irq_ptr += FIXED_IRQ_NUM;
328338 bool rv = true ;
329-
330- if (cfg.irq == FSP_INVALID_VECTOR) {
339+ if (last_interrupt_index >= PROG_IRQ_NUM){
340+ rv = false ;
341+ }
342+ else if (cfg.irq == FSP_INVALID_VECTOR) {
331343 /* to check correctness of the channel */
332344 if (set_dma_link_event (last_interrupt_index, cfg.channel )) {
333345 cfg.ipl = DMA_PRIORITY;
@@ -357,6 +369,11 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
357369 irq_ptr += FIXED_IRQ_NUM;
358370 bool rv = true ;
359371
372+ if (last_interrupt_index >= PROG_IRQ_NUM){
373+ rv = false ;
374+ goto end_config;
375+ }
376+
360377 __disable_irq ();
361378 /* **********************************************************************
362379 USB
@@ -493,7 +510,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
493510 ********************************************************************** */
494511 else if (p == IRQ_SCI_UART && cfg != NULL ) {
495512 uart_cfg_t *p_cfg = (uart_cfg_t *)cfg;
513+
496514 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+ }
497519 /* TX interrupt */
498520 p_cfg->txi_ipl = UART_SCI_PRIORITY;
499521 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -579,13 +601,18 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
579601
580602#if WIRE_HOWMANY > 0
581603 /* I2C true NOT SCI */
582- else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
604+ else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
605+
583606 I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
584607 i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
585608 i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
586609 mcfg->ipl = I2C_MASTER_PRIORITY;
587610
588611 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+ }
589616 /* TX interrupt */
590617 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
591618 scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -626,11 +653,15 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
626653 R_BSP_IrqEnable (mcfg->eri_irq );
627654 }
628655 /* I2C SCI MASTER (only) */
629- else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
656+ else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
630657 I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
631658 i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
632659 mcfg->ipl = I2C_MASTER_PRIORITY;
633- 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+ }
634665 /* TX interrupt */
635666 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
636667 *(irq_ptr + last_interrupt_index) = (uint32_t )sci_i2c_txi_isr;
@@ -674,8 +705,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
674705 i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
675706 scfg->ipl = I2C_SLAVE_PRIORITY;
676707 scfg->eri_ipl = I2C_SLAVE_PRIORITY;
677-
678- 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+ }
679714 /* TX interrupt */
680715 mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
681716 scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -732,12 +767,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
732767 /* **********************************************************************
733768 SPI MASTER
734769 ********************************************************************** */
735- else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
770+ else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
736771 spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->ctrl ;
737772 spi_cfg_t * p_cfg = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->cfg ;
738773 uint8_t const hw_channel = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->hw_channel ;
739774
740775 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+ }
741780 /* TX interrupt */
742781 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
743782 p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -780,12 +819,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
780819 /* **********************************************************************
781820 SCI SPI MASTER
782821 ********************************************************************** */
783- else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
822+ else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
784823 sci_spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->ctrl ;
785824 spi_cfg_t * p_cfg = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->cfg ;
786825 uint8_t const hw_channel = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->hw_channel ;
787826
788827 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+ }
789832 /* TX interrupt */
790833 p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
791834 p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -829,12 +872,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
829872 /* **********************************************************************
830873 CAN
831874 ********************************************************************** */
832- else if (p == IRQ_CAN && cfg != NULL ) {
875+ else if (p == IRQ_CAN && cfg != NULL ) {
833876 can_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
834877 can_cfg_t * p_cfg = reinterpret_cast <CanIrqReq_t *>(cfg)->cfg ;
835878 p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
836879
837880 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+ }
838885 /* Error interrupt */
839886 p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
840887 *(irq_ptr + last_interrupt_index) = (uint32_t )can_error_isr;
@@ -889,6 +936,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
889936 p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
890937
891938 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+ }
892943 /* Error interrupt */
893944 p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
894945 *(irq_ptr + last_interrupt_index) = (uint32_t )canfd_error_isr;
@@ -924,7 +975,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
924975 sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
925976 /* SDCARD_ACCESS */
926977 if (sd_cfg->access_irq == FSP_INVALID_VECTOR) {
927-
978+ if (last_interrupt_index + SD_INTERRUPT_COUNT > PROG_IRQ_NUM){
979+ rv = false ;
980+ goto end_config;
981+ }
928982 sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
929983 sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
930984 *(irq_ptr + last_interrupt_index) = (uint32_t )sdhimmc_accs_isr;
0 commit comments