samd/samd_isr: Change the way a Sercom ISR is registered and called.
Code size diff: +12 Bytes BSS diff: -12 Bytes RAM usage: +16 Bytes Speed increase: a few clock cycles per call Style improvement: ++
This commit is contained in:
parent
009c51c13f
commit
3625388d8c
|
@ -188,7 +188,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
|
|||
i2c->I2CM.BAUD.reg = get_apb_freq() / (2 * self->freq) - 5 - (get_apb_freq() / 1000000) * RISETIME_NS / 2000;
|
||||
|
||||
// Enable interrupts
|
||||
sercom_register_irq(self->id, SERCOM_IRQ_TYPE_SPI);
|
||||
sercom_register_irq(self->id, &common_i2c_irq_handler);
|
||||
#if defined(MCU_SAMD21)
|
||||
NVIC_EnableIRQ(SERCOM0_IRQn + self->id);
|
||||
#elif defined(MCU_SAMD51)
|
||||
|
|
|
@ -218,7 +218,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj
|
|||
#elif defined(MCU_SAMD51)
|
||||
NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id + 2);
|
||||
#endif
|
||||
sercom_register_irq(self->id, SERCOM_IRQ_TYPE_SPI);
|
||||
sercom_register_irq(self->id, &common_spi_irq_handler);
|
||||
}
|
||||
|
||||
sercom_enable(spi, 1);
|
||||
|
|
|
@ -281,7 +281,7 @@ STATIC mp_obj_t machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args
|
|||
#elif defined(MCU_SAMD51)
|
||||
NVIC_EnableIRQ(SERCOM0_0_IRQn + 4 * self->id + 2);
|
||||
#endif
|
||||
sercom_register_irq(self->id, SERCOM_IRQ_TYPE_UART);
|
||||
sercom_register_irq(self->id, &common_uart_irq_handler);
|
||||
|
||||
sercom_enable(uart, 1);
|
||||
}
|
||||
|
|
|
@ -108,21 +108,17 @@ void PendSV_Handler(void) {
|
|||
}
|
||||
|
||||
|
||||
static uint8_t sercom_irq_type[SERCOM_INST_NUM] = {};
|
||||
void (*sercom_irq_handler_table[SERCOM_INST_NUM])(int num) = {};
|
||||
|
||||
void (*sercom_irq_handler_table[])(int num) = {
|
||||
common_uart_irq_handler,
|
||||
common_spi_irq_handler,
|
||||
common_i2c_irq_handler
|
||||
};
|
||||
|
||||
void sercom_register_irq(int sercom_id, int mode) {
|
||||
sercom_irq_type[sercom_id] = mode;
|
||||
void sercom_register_irq(int sercom_id, void (*sercom_irq_handler)) {
|
||||
if (sercom_id < SERCOM_INST_NUM) {
|
||||
sercom_irq_handler_table[sercom_id] = sercom_irq_handler;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void common_sercom_irq_handler(int sercom_id) {
|
||||
if (sercom_irq_handler_table[sercom_irq_type[sercom_id]]) {
|
||||
sercom_irq_handler_table[sercom_irq_type[sercom_id]](sercom_id);
|
||||
if (sercom_irq_handler_table[sercom_id]) {
|
||||
sercom_irq_handler_table[sercom_id](sercom_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,11 +39,8 @@ void USB_1_Handler_wrapper(void);
|
|||
void USB_2_Handler_wrapper(void);
|
||||
void USB_3_Handler_wrapper(void);
|
||||
|
||||
void common_uart_irq_handler(int uart_nr);
|
||||
void common_spi_irq_handler(int spi_nr);
|
||||
void common_i2c_irq_handler(int i2c_nr);
|
||||
void sercom_enable(Sercom *spi, int state);
|
||||
void sercom_register_irq(int sercom_id, int mode);
|
||||
void sercom_register_irq(int sercom_id, void (*sercom_irq_handler));
|
||||
|
||||
#define SERCOM_IRQ_TYPE_UART (0)
|
||||
#define SERCOM_IRQ_TYPE_SPI (1)
|
||||
|
|
Loading…
Reference in New Issue