hal: nordic: Move nrfx IRQ related stuff from SPI shim to nrfx_glue
The simple function that helps to integrate nrfx IRQ handlers with the IRQ_CONNECT macro can be used in shims for various nrfx drivers, not only the SPI one. Similarly, the macro for getting the IRQ number from the peripheral base address needs to be widely available. It should be even moved to <nrfx_common.h> in some next nrfx update. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
parent
88b66b58b1
commit
ea1d14e529
4 changed files with 47 additions and 14 deletions
|
@ -270,24 +270,12 @@ static int init_spi(struct device *dev, const nrfx_spi_config_t *config)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void spi_isr(void *irq_handler)
|
||||
{
|
||||
((nrfx_irq_handler_t)irq_handler)();
|
||||
}
|
||||
|
||||
/* In Nordic SoCs the IRQ number assigned to a peripheral is equal to the ID
|
||||
* of the block of 0x1000 bytes in the peripheral address space assigned to
|
||||
* this peripheral. See the chapter "Peripheral interface" (sections "Peripheral
|
||||
* ID" and "Interrupts") in the product specification of a given SoC.
|
||||
*/
|
||||
#define NRF_SPI_IRQ_NUMBER(idx) (uint8_t)((uint32_t)NRF_SPI##idx >> 12u)
|
||||
|
||||
#define SPI_NRFX_SPI_DEVICE(idx) \
|
||||
static int spi_##idx##_init(struct device *dev) \
|
||||
{ \
|
||||
IRQ_CONNECT(NRF_SPI_IRQ_NUMBER(idx), \
|
||||
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPI##idx), \
|
||||
CONFIG_SPI_##idx##_IRQ_PRI, \
|
||||
spi_isr, nrfx_spi_##idx##_irq_handler, 0); \
|
||||
nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \
|
||||
const nrfx_spi_config_t config = { \
|
||||
.sck_pin = CONFIG_SPI_##idx##_NRF_SCK_PIN, \
|
||||
.mosi_pin = CONFIG_SPI_##idx##_NRF_MOSI_PIN, \
|
||||
|
|
|
@ -11,6 +11,8 @@ if(CONFIG_HAS_NRFX)
|
|||
zephyr_include_directories(nrfx/mdk)
|
||||
zephyr_include_directories(.)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_HAS_NRFX nrfx_glue.c)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_NRFX_PRS nrfx/drivers/prs/nrfx_prs.c)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_NRFX_ADC nrfx/drivers/src/nrfx_adc.c)
|
||||
|
|
12
ext/hal/nordic/nrfx_glue.c
Normal file
12
ext/hal/nordic/nrfx_glue.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
void nrfx_isr(void *irq_handler)
|
||||
{
|
||||
((nrfx_irq_handler_t)irq_handler)();
|
||||
}
|
|
@ -176,6 +176,37 @@ extern "C" {
|
|||
*/
|
||||
#define NRFX_TIMERS_USED 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Macro for getting the interrupt number assigned to a specific
|
||||
* peripheral.
|
||||
*
|
||||
* In Nordic SoCs the IRQ number assigned to a peripheral is equal to the ID
|
||||
* of this peripheral, and there is a direct relationship between this ID and
|
||||
* the peripheral base address, i.e. the address of a fixed block of 0x1000
|
||||
* bytes of address space assigned to this peripheral.
|
||||
* See the chapter "Peripheral interface" (sections "Peripheral ID" and
|
||||
* "Interrupts") in the product specification of a given SoC.
|
||||
*
|
||||
* @param[in] base_addr Peripheral base address.
|
||||
*
|
||||
* @return Interrupt number associated with the specified peripheral.
|
||||
*/
|
||||
/* TODO - this macro should become a part of <nrfx_common.h> */
|
||||
#define NRFX_IRQ_NUMBER_GET(base_addr) (uint8_t)((uint32_t)(base_addr) >> 12)
|
||||
|
||||
/**
|
||||
* @brief Function helping to integrate nrfx IRQ handlers with IRQ_CONNECT.
|
||||
*
|
||||
* This function simply calls the nrfx IRQ handler supplied as the parameter.
|
||||
* It is intended to be used in the following way:
|
||||
* IRQ_CONNECT(IRQ_NUM, IRQ_PRI, nrfx_isr, nrfx_..._irq_handler, 0);
|
||||
*
|
||||
* @param[in] irq_handler Pointer to the nrfx IRQ handler to be called.
|
||||
*/
|
||||
void nrfx_isr(void *irq_handler);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue