@@ -67,8 +67,10 @@ bool IRQManager::addADCScanEnd(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
67
67
/* set the displacement to the "programmable" part of the table */
68
68
irq_ptr += FIXED_IRQ_NUM;
69
69
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) {
72
74
if (set_adc_end_link_event (last_interrupt_index, adc->cfg .unit )) {
73
75
adc->cfg .scan_end_ipl = TIMER_PRIORITY;
74
76
adc->cfg .scan_end_irq = (IRQn_Type)last_interrupt_index;
@@ -101,8 +103,10 @@ bool IRQManager::addADCScanEndB(ADC_Container *adc, Irq_f fnc /*= nullptr*/) {
101
103
/* set the displacement to the "programmable" part of the table */
102
104
irq_ptr += FIXED_IRQ_NUM;
103
105
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) {
106
110
if (set_adc_end_b_link_event (last_interrupt_index, adc->cfg .unit )) {
107
111
adc->cfg .scan_end_b_ipl = TIMER_PRIORITY;
108
112
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*/) {
125
129
/* set the displacement to the "programmable" part of the table */
126
130
irq_ptr += FIXED_IRQ_NUM;
127
131
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) {
130
136
if (set_adc_win_a_link_event (last_interrupt_index, adc->cfg .unit )) {
131
137
((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_a_ipl = TIMER_PRIORITY;
132
138
((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*/) {
150
156
/* set the displacement to the "programmable" part of the table */
151
157
irq_ptr += FIXED_IRQ_NUM;
152
158
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) {
155
163
if (set_adc_win_b_link_event (last_interrupt_index, adc->cfg .unit )) {
156
164
((adc_extended_cfg_t *)(adc->cfg .p_extend ))->window_b_ipl = TIMER_PRIORITY;
157
165
((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 */)
177
185
/* set the displacement to the "programmable" part of the table */
178
186
irq_ptr += FIXED_IRQ_NUM;
179
187
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) {
182
192
if (cfg.gpt_ext_cfg != nullptr ) {
183
193
if (set_gpt_over_link_event (last_interrupt_index, cfg.base_cfg ->channel )) {
184
194
cfg.base_cfg ->cycle_end_ipl = TIMER_PRIORITY;
@@ -224,7 +234,7 @@ bool IRQManager::addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullptr*/)
224
234
irq_ptr += FIXED_IRQ_NUM;
225
235
bool rv = true ;
226
236
227
- if (cfg.agt_ext_cfg != nullptr ) {
237
+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
228
238
/* not supported for AGT */
229
239
rv = false ;
230
240
}
@@ -258,7 +268,7 @@ bool IRQManager::addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
258
268
irq_ptr += FIXED_IRQ_NUM;
259
269
bool rv = true ;
260
270
261
- if (cfg.agt_ext_cfg != nullptr ) {
271
+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
262
272
/* not supported for AGT */
263
273
rv = false ;
264
274
}
@@ -292,7 +302,7 @@ bool IRQManager::addTimerCompareCaptureB(TimerIrqCfg_t &cfg, Irq_f fnc /*= nullp
292
302
irq_ptr += FIXED_IRQ_NUM;
293
303
bool rv = true ;
294
304
295
- if (cfg.agt_ext_cfg != nullptr ) {
305
+ if (( cfg.agt_ext_cfg != nullptr ) || (last_interrupt_index >= PROG_IRQ_NUM) ) {
296
306
/* not supported for AGT */
297
307
rv = false ;
298
308
}
@@ -326,8 +336,10 @@ bool IRQManager::addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc /* = nullptr */) {
326
336
/* set the displacement to the "programmable" part of the table */
327
337
irq_ptr += FIXED_IRQ_NUM;
328
338
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) {
331
343
/* to check correctness of the channel */
332
344
if (set_dma_link_event (last_interrupt_index, cfg.channel )) {
333
345
cfg.ipl = DMA_PRIORITY;
@@ -357,6 +369,11 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
357
369
irq_ptr += FIXED_IRQ_NUM;
358
370
bool rv = true ;
359
371
372
+ if (last_interrupt_index >= PROG_IRQ_NUM){
373
+ rv = false ;
374
+ goto end_config;
375
+ }
376
+
360
377
__disable_irq ();
361
378
/* **********************************************************************
362
379
USB
@@ -493,7 +510,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
493
510
********************************************************************** */
494
511
else if (p == IRQ_SCI_UART && cfg != NULL ) {
495
512
uart_cfg_t *p_cfg = (uart_cfg_t *)cfg;
513
+
496
514
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
+ }
497
519
/* TX interrupt */
498
520
p_cfg->txi_ipl = UART_SCI_PRIORITY;
499
521
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -579,13 +601,18 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
579
601
580
602
#if WIRE_HOWMANY > 0
581
603
/* I2C true NOT SCI */
582
- else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
604
+ else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
605
+
583
606
I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
584
607
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
585
608
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
586
609
mcfg->ipl = I2C_MASTER_PRIORITY;
587
610
588
611
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
+ }
589
616
/* TX interrupt */
590
617
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
591
618
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -626,11 +653,15 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
626
653
R_BSP_IrqEnable (mcfg->eri_irq );
627
654
}
628
655
/* I2C SCI MASTER (only) */
629
- else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
656
+ else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
630
657
I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
631
658
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
632
659
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
+ }
634
665
/* TX interrupt */
635
666
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
636
667
*(irq_ptr + last_interrupt_index) = (uint32_t )sci_i2c_txi_isr;
@@ -674,8 +705,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
674
705
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
675
706
scfg->ipl = I2C_SLAVE_PRIORITY;
676
707
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
+ }
679
714
/* TX interrupt */
680
715
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
681
716
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -732,12 +767,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
732
767
/* **********************************************************************
733
768
SPI MASTER
734
769
********************************************************************** */
735
- else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
770
+ else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
736
771
spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->ctrl ;
737
772
spi_cfg_t * p_cfg = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->cfg ;
738
773
uint8_t const hw_channel = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->hw_channel ;
739
774
740
775
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
+ }
741
780
/* TX interrupt */
742
781
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
743
782
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -780,12 +819,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
780
819
/* **********************************************************************
781
820
SCI SPI MASTER
782
821
********************************************************************** */
783
- else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
822
+ else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
784
823
sci_spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->ctrl ;
785
824
spi_cfg_t * p_cfg = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->cfg ;
786
825
uint8_t const hw_channel = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->hw_channel ;
787
826
788
827
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
+ }
789
832
/* TX interrupt */
790
833
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
791
834
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -829,12 +872,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
829
872
/* **********************************************************************
830
873
CAN
831
874
********************************************************************** */
832
- else if (p == IRQ_CAN && cfg != NULL ) {
875
+ else if (p == IRQ_CAN && cfg != NULL ) {
833
876
can_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
834
877
can_cfg_t * p_cfg = reinterpret_cast <CanIrqReq_t *>(cfg)->cfg ;
835
878
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
836
879
837
880
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
+ }
838
885
/* Error interrupt */
839
886
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
840
887
*(irq_ptr + last_interrupt_index) = (uint32_t )can_error_isr;
@@ -889,6 +936,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
889
936
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
890
937
891
938
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
+ }
892
943
/* Error interrupt */
893
944
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
894
945
*(irq_ptr + last_interrupt_index) = (uint32_t )canfd_error_isr;
@@ -924,7 +975,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
924
975
sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
925
976
/* SDCARD_ACCESS */
926
977
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
+ }
928
982
sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
929
983
sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
930
984
*(irq_ptr + last_interrupt_index) = (uint32_t )sdhimmc_accs_isr;
0 commit comments