Skip to content

bounds check for last_interrupt_index #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
peripherals with more than one interrupt
  • Loading branch information
delta-G committed May 22, 2024
commit 89e22a26d6e548e1f817907f1892aaab445f6c3c
55 changes: 46 additions & 9 deletions cores/arduino/IRQManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
********************************************************************** */
else if(p == IRQ_SCI_UART && cfg != NULL) {
uart_cfg_t *p_cfg = (uart_cfg_t *)cfg;

if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + UART_INTERRUPT_COUNT > PROG_IRQ_NUM){
rv = false;
goto end_config;
}
/* TX interrupt */
p_cfg->txi_ipl = UART_SCI_PRIORITY;
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
Expand Down Expand Up @@ -596,13 +601,18 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {

#if WIRE_HOWMANY > 0
/* I2C true NOT SCI */
else if(p == IRQ_I2C_MASTER && cfg != NULL) {
else if(p == IRQ_I2C_MASTER && cfg != NULL) {

I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg;
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg;
mcfg->ipl = I2C_MASTER_PRIORITY;

if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + WIRE_MASTER_INTERRUPT_COUNT >= PROG_IRQ_NUM){
rv = false;
goto end_config;
}
/* TX interrupt */
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
Expand Down Expand Up @@ -643,11 +653,15 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
R_BSP_IrqEnable (mcfg->eri_irq);
}
/* I2C SCI MASTER (only) */
else if(p == IRQ_SCI_I2C_MASTER && cfg != NULL) {
else if(p == IRQ_SCI_I2C_MASTER && cfg != NULL) {
I2CIrqReq_t *p_cfg = (I2CIrqReq_t *)cfg;
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->mcfg;
mcfg->ipl = I2C_MASTER_PRIORITY;
if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + WIRE_SCI_MASTER_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* TX interrupt */
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)sci_i2c_txi_isr;
Expand Down Expand Up @@ -691,8 +705,12 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
i2c_slave_cfg_t *scfg = (i2c_slave_cfg_t *)p_cfg->scfg;
scfg->ipl = I2C_SLAVE_PRIORITY;
scfg->eri_ipl = I2C_SLAVE_PRIORITY;

if (scfg->txi_irq == FSP_INVALID_VECTOR) {

if (scfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + WIRE_SLAVE_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* TX interrupt */
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
scfg->txi_irq = (IRQn_Type)last_interrupt_index;
Expand Down Expand Up @@ -749,12 +767,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
/* **********************************************************************
SPI MASTER
********************************************************************** */
else if(p == IRQ_SPI_MASTER && cfg != NULL) {
else if(p == IRQ_SPI_MASTER && cfg != NULL) {
spi_instance_ctrl_t * p_ctrl = reinterpret_cast<SpiMasterIrqReq_t *>(cfg)->ctrl;
spi_cfg_t * p_cfg = reinterpret_cast<SpiMasterIrqReq_t *>(cfg)->cfg;
uint8_t const hw_channel = reinterpret_cast<SpiMasterIrqReq_t *>(cfg)->hw_channel;

if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + SPI_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* TX interrupt */
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
Expand Down Expand Up @@ -797,12 +819,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
/* **********************************************************************
SCI SPI MASTER
********************************************************************** */
else if(p == IRQ_SCI_SPI_MASTER && cfg != NULL) {
else if(p == IRQ_SCI_SPI_MASTER && cfg != NULL) {
sci_spi_instance_ctrl_t * p_ctrl = reinterpret_cast<SciSpiMasterIrqReq_t *>(cfg)->ctrl;
spi_cfg_t * p_cfg = reinterpret_cast<SciSpiMasterIrqReq_t *>(cfg)->cfg;
uint8_t const hw_channel = reinterpret_cast<SciSpiMasterIrqReq_t *>(cfg)->hw_channel;

if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + SPI_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* TX interrupt */
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
p_cfg->txi_ipl = SPI_MASTER_PRIORITY;
Expand Down Expand Up @@ -846,12 +872,16 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
/* **********************************************************************
CAN
********************************************************************** */
else if(p == IRQ_CAN && cfg != NULL) {
else if(p == IRQ_CAN && cfg != NULL) {
can_instance_ctrl_t * p_ctrl = reinterpret_cast<CanIrqReq_t *>(cfg)->ctrl;
can_cfg_t * p_cfg = reinterpret_cast<CanIrqReq_t *>(cfg)->cfg;
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */

if (p_cfg->error_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + CAN_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* Error interrupt */
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)can_error_isr;
Expand Down Expand Up @@ -906,6 +936,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
p_cfg->ipl = CAN_PRIORITY; /* All interrupts share the same priority. */

if (p_cfg->error_irq == FSP_INVALID_VECTOR) {
if (last_interrupt_index + CANFD_INTERRUPT_COUNT >= PROG_IRQ_NUM) {
rv = false;
goto end_config;
}
/* Error interrupt */
p_cfg->error_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)canfd_error_isr;
Expand Down Expand Up @@ -941,7 +975,10 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
sdmmc_cfg_t *sd_cfg = (sdmmc_cfg_t *)cfg;
/* SDCARD_ACCESS */
if(sd_cfg->access_irq == FSP_INVALID_VECTOR) {

if (last_interrupt_index + SD_INTERRUPT_COUNT >= PROG_IRQ_NUM){
rv = false;
goto end_config;
}
sd_cfg->access_irq = (IRQn_Type)last_interrupt_index;
sd_cfg->access_ipl = SDCARD_ACCESS_PRIORITY;
*(irq_ptr + last_interrupt_index) = (uint32_t)sdhimmc_accs_isr;
Expand Down