Skip to content

Commit

Permalink
cpu/nrfxx: use shared serial IRQ
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Laduranty <[email protected]>
  • Loading branch information
dylad committed Jul 7, 2023
1 parent b011060 commit 529ed19
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
2 changes: 0 additions & 2 deletions boards/nrf5340dk-app/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ static const uart_conf_t uart_config[] = {
},
};

#define UART_0_ISR (isr_serial0) /**< SERIAL0_IRQn */

#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART configuration NUMOF */
/** @} */

Expand Down
3 changes: 0 additions & 3 deletions boards/nrf9160dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ static const uart_conf_t uart_config[] = {
},
};

#define UART_0_ISR (isr_uarte0_spim0_spis0_twim0_twis0) /**< UART0_IRQ */
#define UART_1_ISR (isr_uarte1_spim1_spis1_twim1_twis1) /**< UART1_IRQ */

#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART confgiguration NUMOF */
/** @} */

Expand Down
1 change: 1 addition & 0 deletions cpu/nrf53/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
USEMODULE += nrf53_vectors
USEMODULE += nrf_shared_serial_irq

include $(RIOTCPU)/nrf5x_common/Makefile.dep
include $(RIOTCPU)/cortexm_common/Makefile.dep
3 changes: 3 additions & 0 deletions cpu/nrf5x_common/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
MODULE = cpu_common
DIRS = periph

ifneq (,$(filter nrf_shared_serial_irq,$(USEMODULE)))
DIRS += shared_irq
endif
# build one of the radio drivers, if enabled
ifneq (,$(filter nrfble,$(USEMODULE)))
DIRS += radio/nrfble
Expand Down
2 changes: 1 addition & 1 deletion cpu/nrf5x_common/periph/i2c_nrf52_nrf9160.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void i2c_init(i2c_t dev)
/* configure shared periphal speed */
_setup_shared_peripheral(dev);

spi_twi_irq_register_i2c(bus(dev), i2c_isr_handler, (void *)(uintptr_t)dev);
shared_irq_register_i2c(bus(dev), i2c_isr_handler, (void *)(uintptr_t)dev);

/* We expect that the device was being acquired before
* the i2c_init_master() function is called, so it should be enabled when
Expand Down
2 changes: 1 addition & 1 deletion cpu/nrf5x_common/periph/spi_nrf52_nrf9160.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void spi_init_pins(spi_t bus)

/* select pins for the SPI device */
_setup_workaround_for_ftpan_58(bus);
spi_twi_irq_register_spi(dev(bus), spi_isr_handler, (void *)(uintptr_t)bus);
shared_irq_register_spi(dev(bus), spi_isr_handler, (void *)(uintptr_t)bus);
}

void spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
Expand Down
18 changes: 18 additions & 0 deletions cpu/nrf5x_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ static tsrb_t uart_tx_rb[UART_NUMOF];
static uint8_t uart_tx_rb_buf[UART_NUMOF][UART_TXBUF_SIZE];
#endif

/**
* @brief Shared IRQ Callback for UART on nRF53/nRF9160
*/
void uart_isr_handler(void *arg);

static inline NRF_UARTE_Type *dev(uart_t uart)
{
return uart_config[uart].dev;
Expand Down Expand Up @@ -239,7 +244,11 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
}

if (rx_cb || IS_USED(MODULE_PERIPH_UART_NONBLOCKING)) {
#if defined(CPU_NRF53) || defined(CPU_NRF9160)
shared_irq_register_uart(dev(uart), uart_isr_handler, (void *)(uintptr_t)uart);
#else
NVIC_EnableIRQ(UART_IRQN);
#endif
}
return UART_OK;
}
Expand Down Expand Up @@ -489,6 +498,14 @@ static inline void irq_handler(uart_t uart)

#endif /* !CPU_MODEL_NRF52832XXAA && !CPU_FAM_NRF51 */

#if defined(CPU_NRF53) || defined(CPU_NRF9160)
void uart_isr_handler(void *arg)
{
uart_t uart = (uart_t)(uintptr_t)arg;

irq_handler(uart);
}
#else
#ifdef UART_0_ISR
void UART_0_ISR(void)
{
Expand All @@ -502,3 +519,4 @@ void UART_1_ISR(void)
irq_handler(UART_DEV(1));
}
#endif
#endif /* def CPU_NRF53 || CPU_NRF9160 */
1 change: 1 addition & 0 deletions cpu/nrf9160/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
USEMODULE += nrf9160_vectors
USEMODULE += nrf_shared_serial_irq

ifneq (,$(filter periph_spi,$(USEMODULE)))
USEMODULE += periph_spi_gpio_mode
Expand Down

0 comments on commit 529ed19

Please sign in to comment.