|
| 1 | +#include "IRQManager.h" |
| 2 | +#include "bsp_api.h" |
| 3 | + |
| 4 | +#define FIXED_IRQ_NUM 16 |
| 5 | +#define PROG_IRQ_NUM 32 |
| 6 | + |
| 7 | +#define UART_SCI2_REQ_NUM 4 |
| 8 | +#define UART_SCI2_PRIORITY 12 |
| 9 | + |
| 10 | +IRQManager::IRQManager() : last_interrupt_index{-1} { |
| 11 | + |
| 12 | +} |
| 13 | + |
| 14 | +IRQManager::~IRQManager() { |
| 15 | + |
| 16 | +} |
| 17 | + |
| 18 | +IRQManager& IRQManager::getInstance() { |
| 19 | + static IRQManager instance; |
| 20 | + return instance; |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +bool IRQManager::addPeripheral(Peripheral_t p, uart_cfg_t &cfg) { |
| 25 | + /* getting the address of the current location of the irq vector table */ |
| 26 | + volatile uint32_t *irq_ptr = (volatile uint32_t *)SCB->VTOR; |
| 27 | + /* set the displacement to the "programmable" part of the table */ |
| 28 | + irq_ptr += FIXED_IRQ_NUM; |
| 29 | + |
| 30 | + |
| 31 | + if(p == UART_SCI2) { |
| 32 | + if( (last_interrupt_index + UART_SCI2_REQ_NUM) < PROG_IRQ_NUM ) { |
| 33 | + /* TX interrupt */ |
| 34 | + last_interrupt_index = 26; |
| 35 | + cfg.txi_ipl = UART_SCI2_PRIORITY; |
| 36 | + cfg.txi_irq = (IRQn_Type)last_interrupt_index; |
| 37 | + *(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_txi_isr; |
| 38 | + R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TXI); |
| 39 | + |
| 40 | + /* TX-ERROR interrupt */ |
| 41 | + last_interrupt_index++; |
| 42 | + cfg.tei_ipl = UART_SCI2_PRIORITY; |
| 43 | + cfg.tei_irq = (IRQn_Type)last_interrupt_index; |
| 44 | + *(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_tei_isr; |
| 45 | + R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_TEI); |
| 46 | + |
| 47 | + /* RX interrupt */ |
| 48 | + last_interrupt_index++; |
| 49 | + cfg.rxi_ipl = UART_SCI2_PRIORITY; |
| 50 | + cfg.rxi_irq = (IRQn_Type)last_interrupt_index; |
| 51 | + *(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_rxi_isr; |
| 52 | + R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_RXI); |
| 53 | + |
| 54 | + /* RX-ERROR interrupt */ |
| 55 | + last_interrupt_index++; |
| 56 | + cfg.eri_ipl = UART_SCI2_PRIORITY; |
| 57 | + cfg.eri_irq = (IRQn_Type)last_interrupt_index; |
| 58 | + *(irq_ptr + last_interrupt_index) = (uint32_t)sci_uart_eri_isr; |
| 59 | + R_ICU->IELSR[last_interrupt_index] = BSP_PRV_IELS_ENUM(EVENT_SCI2_ERI); |
| 60 | + } |
| 61 | + else { |
| 62 | + return false; |
| 63 | + } |
| 64 | + } |
| 65 | + else { |
| 66 | + return false; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +/* Do not build these data structures if no interrupts are currently allocated because IAR will have build errors. */ |
| 71 | + |
| 72 | + |
0 commit comments