@@ -510,7 +510,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
510
510
********************************************************************** */
511
511
else if (p == IRQ_SCI_UART && cfg != NULL ) {
512
512
uart_cfg_t *p_cfg = (uart_cfg_t *)cfg;
513
+
513
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
+ }
514
519
/* TX interrupt */
515
520
p_cfg->txi_ipl = UART_SCI_PRIORITY;
516
521
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -596,13 +601,18 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
596
601
597
602
#if WIRE_HOWMANY > 0
598
603
/* I2C true NOT SCI */
599
- else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
604
+ else if (p == IRQ_I2C_MASTER && cfg != NULL ) {
605
+
600
606
I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
601
607
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
602
608
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
603
609
mcfg->ipl = I2C_MASTER_PRIORITY;
604
610
605
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
+ }
606
616
/* TX interrupt */
607
617
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
608
618
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -643,11 +653,15 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
643
653
R_BSP_IrqEnable (mcfg->eri_irq );
644
654
}
645
655
/* I2C SCI MASTER (only) */
646
- else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
656
+ else if (p == IRQ_SCI_I2C_MASTER && cfg != NULL ) {
647
657
I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
648
658
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg ;
649
659
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
+ }
651
665
/* TX interrupt */
652
666
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
653
667
*(irq_ptr + last_interrupt_index) = (uint32_t )sci_i2c_txi_isr;
@@ -691,8 +705,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
691
705
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg ;
692
706
scfg->ipl = I2C_SLAVE_PRIORITY;
693
707
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
+ }
696
714
/* TX interrupt */
697
715
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
698
716
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
@@ -749,12 +767,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
749
767
/* **********************************************************************
750
768
SPI MASTER
751
769
********************************************************************** */
752
- else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
770
+ else if (p == IRQ_SPI_MASTER && cfg != NULL ) {
753
771
spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->ctrl ;
754
772
spi_cfg_t * p_cfg = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->cfg ;
755
773
uint8_t const hw_channel = reinterpret_cast <SpiMasterIrqReq_t *>(cfg)->hw_channel ;
756
774
757
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
+ }
758
780
/* TX interrupt */
759
781
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
760
782
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -797,12 +819,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
797
819
/* **********************************************************************
798
820
SCI SPI MASTER
799
821
********************************************************************** */
800
- else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
822
+ else if (p == IRQ_SCI_SPI_MASTER && cfg != NULL ) {
801
823
sci_spi_instance_ctrl_t * p_ctrl = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->ctrl ;
802
824
spi_cfg_t * p_cfg = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->cfg ;
803
825
uint8_t const hw_channel = reinterpret_cast <SciSpiMasterIrqReq_t *>(cfg)->hw_channel ;
804
826
805
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
+ }
806
832
/* TX interrupt */
807
833
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
808
834
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
@@ -846,12 +872,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
846
872
/* **********************************************************************
847
873
CAN
848
874
********************************************************************** */
849
- else if (p == IRQ_CAN && cfg != NULL ) {
875
+ else if (p == IRQ_CAN && cfg != NULL ) {
850
876
can_instance_ctrl_t * p_ctrl = reinterpret_cast <CanIrqReq_t *>(cfg)->ctrl ;
851
877
can_cfg_t * p_cfg = reinterpret_cast <CanIrqReq_t *>(cfg)->cfg ;
852
878
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
853
879
854
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
+ }
855
885
/* Error interrupt */
856
886
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
857
887
*(irq_ptr + last_interrupt_index) = (uint32_t )can_error_isr;
@@ -906,6 +936,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
906
936
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */
907
937
908
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
+ }
909
943
/* Error interrupt */
910
944
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
911
945
*(irq_ptr + last_interrupt_index) = (uint32_t )canfd_error_isr;
@@ -941,7 +975,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
941
975
sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
942
976
/* SDCARD_ACCESS */
943
977
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
+ }
945
982
sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
946
983
sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
947
984
*(irq_ptr + last_interrupt_index) = (uint32_t )sdhimmc_accs_isr;
0 commit comments