Skip to content
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

I2C hot switch master <-> slave #182

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea
compile_commands.json
.clangd
.cache/
cores/arduino/mydebug.cpp
libraries/Storage/.development
cores/arduino/mydebug.cpp.donotuse
Expand Down
51 changes: 46 additions & 5 deletions cores/arduino/IRQManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
#define CANFD_PRIORITY 12
#define FIRST_INT_SLOT_FREE 0

IRQManager::IRQManager() : last_interrupt_index{0} {

IRQManager::IRQManager() : last_interrupt_index{0} ,
rcfg_I2C_interrupt_index_txi(-1),
rcfg_I2C_interrupt_index_rxi(-1),
rcfg_I2C_interrupt_index_tei(-1),
rcfg_I2C_interrupt_index_eri(-1) {
}

IRQManager::~IRQManager() {
Expand Down Expand Up @@ -562,35 +565,54 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
i2c_master_cfg_t *mcfg = (i2c_master_cfg_t *)p_cfg->cfg;
uint8_t hw_channel = p_cfg->hw_channel;
mcfg->ipl = I2C_MASTER_PRIORITY;
if (mcfg->txi_irq == FSP_INVALID_VECTOR) {
if (rcfg_I2C_interrupt_index_txi == -1) {
/* TX interrupt */
mcfg->txi_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_master_txi_isr;
set_iic_tx_link_event(last_interrupt_index, hw_channel);
R_BSP_IrqCfg((IRQn_Type)last_interrupt_index, I2C_MASTER_PRIORITY, mcfg);
rcfg_I2C_interrupt_index_txi = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_txi) = (uint32_t)iic_master_txi_isr;
}

if (rcfg_I2C_interrupt_index_rxi == -1) {
/* RX interrupt */
mcfg->rxi_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_master_rxi_isr;
set_iic_rx_link_event(last_interrupt_index, hw_channel);
R_BSP_IrqCfg((IRQn_Type)last_interrupt_index, I2C_MASTER_PRIORITY, mcfg);
rcfg_I2C_interrupt_index_rxi = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_rxi) = (uint32_t)iic_master_rxi_isr;
}

if (rcfg_I2C_interrupt_index_tei == -1) {
/* TX ERROR interrupt */
mcfg->tei_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_master_tei_isr;
set_iic_tei_link_event(last_interrupt_index, hw_channel);
R_BSP_IrqCfg((IRQn_Type)last_interrupt_index, I2C_MASTER_PRIORITY, mcfg);
rcfg_I2C_interrupt_index_tei = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_tei) = (uint32_t)iic_master_tei_isr;
}

if (rcfg_I2C_interrupt_index_eri == -1) {
/* RX ERROR interrupt */
mcfg->eri_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_master_eri_isr;
set_iic_eri_link_event(last_interrupt_index, hw_channel);
R_BSP_IrqCfg((IRQn_Type)last_interrupt_index, I2C_MASTER_PRIORITY, mcfg);
rcfg_I2C_interrupt_index_eri = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_eri) = (uint32_t)iic_master_eri_isr;
}

R_BSP_IrqEnable (mcfg->txi_irq);
R_BSP_IrqEnable (mcfg->rxi_irq);
R_BSP_IrqEnable (mcfg->tei_irq);
Expand Down Expand Up @@ -644,31 +666,50 @@ bool IRQManager::addPeripheral(Peripheral_t p, void *cfg) {
i2c_slave_cfg_t *p_cfg = (i2c_slave_cfg_t *)cfg;
p_cfg->ipl = I2C_SLAVE_PRIORITY;
p_cfg->eri_ipl = I2C_SLAVE_PRIORITY;
if (p_cfg->txi_irq == FSP_INVALID_VECTOR) {
if (rcfg_I2C_interrupt_index_txi == -1) {
/* TX interrupt */
p_cfg->txi_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_slave_txi_isr;
set_iic_tx_link_event(last_interrupt_index, p_cfg->channel);
rcfg_I2C_interrupt_index_txi = last_interrupt_index;
last_interrupt_index++;

} else {
*(irq_ptr + rcfg_I2C_interrupt_index_txi) = (uint32_t)iic_slave_txi_isr;
}

if (rcfg_I2C_interrupt_index_rxi == -1) {
/* RX interrupt */
p_cfg->rxi_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_slave_rxi_isr;
set_iic_rx_link_event(last_interrupt_index, p_cfg->channel);
rcfg_I2C_interrupt_index_rxi = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_rxi) = (uint32_t)iic_slave_rxi_isr;
}

if (rcfg_I2C_interrupt_index_tei == -1) {
/* TEI interrupt */
p_cfg->tei_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_slave_tei_isr;
set_iic_tei_link_event(last_interrupt_index, p_cfg->channel);
rcfg_I2C_interrupt_index_tei = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_tei) = (uint32_t)iic_slave_tei_isr;
}

if (rcfg_I2C_interrupt_index_eri == -1) {
/* ERI interrupt */
p_cfg->eri_irq = (IRQn_Type)last_interrupt_index;
*(irq_ptr + last_interrupt_index) = (uint32_t)iic_slave_eri_isr;
set_iic_eri_link_event(last_interrupt_index, p_cfg->channel);
rcfg_I2C_interrupt_index_eri = last_interrupt_index;
last_interrupt_index++;
} else {
*(irq_ptr + rcfg_I2C_interrupt_index_eri) = (uint32_t)iic_slave_eri_isr;
}

R_BSP_IrqEnable (p_cfg->txi_irq);
R_BSP_IrqEnable (p_cfg->rxi_irq);
R_BSP_IrqEnable (p_cfg->tei_irq);
Expand Down
4 changes: 4 additions & 0 deletions cores/arduino/IRQManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ class IRQManager {
~IRQManager();

private:
int rcfg_I2C_interrupt_index_txi;
int rcfg_I2C_interrupt_index_rxi;
int rcfg_I2C_interrupt_index_tei;
int rcfg_I2C_interrupt_index_eri;
size_t last_interrupt_index;
bool set_adc_end_link_event(int li, int ch);
bool set_adc_end_b_link_event(int li, int ch);
Expand Down
Loading
Loading