drivers: spi_mcux_lpspi: Consolidate IRQ handle
Small change to consolidate the amount of lines of code in the spi_mcux_isr by making a macro for the argument and removing a line of code that was commented out. Also move the ISR to be the first function in the file which is common in many other drivers, instead of randomly in the middle of the file. And move the isr callback to be next to the isr. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
parent
e21bf37f13
commit
595e16caf6
1 changed files with 32 additions and 34 deletions
|
@ -36,6 +36,9 @@ LOG_MODULE_REGISTER(spi_mcux_lpspi, CONFIG_SPI_LOG_LEVEL);
|
||||||
#define DEV_CFG(_dev) ((const struct spi_mcux_config *)(_dev)->config)
|
#define DEV_CFG(_dev) ((const struct spi_mcux_config *)(_dev)->config)
|
||||||
#define DEV_DATA(_dev) ((struct spi_mcux_data *)(_dev)->data)
|
#define DEV_DATA(_dev) ((struct spi_mcux_data *)(_dev)->data)
|
||||||
|
|
||||||
|
/* Argument to MCUX SDK IRQ handler */
|
||||||
|
#define LPSPI_IRQ_HANDLE_ARG COND_CODE_1(CONFIG_NXP_LP_FLEXCOMM, (LPSPI_GetInstance(base)), (base))
|
||||||
|
|
||||||
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
|
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
|
||||||
#include <zephyr/drivers/dma.h>
|
#include <zephyr/drivers/dma.h>
|
||||||
|
|
||||||
|
@ -85,6 +88,7 @@ struct spi_mcux_data {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int spi_mcux_transfer_next_packet(const struct device *dev);
|
||||||
#ifdef CONFIG_SPI_RTIO
|
#ifdef CONFIG_SPI_RTIO
|
||||||
static void spi_mcux_iodev_complete(const struct device *dev, int status);
|
static void spi_mcux_iodev_complete(const struct device *dev, int status);
|
||||||
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
|
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
|
||||||
|
@ -92,6 +96,33 @@ static inline int transceive_rtio(const struct device *dev, const struct spi_con
|
||||||
const struct spi_buf_set *rx_bufs);
|
const struct spi_buf_set *rx_bufs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void spi_mcux_isr(const struct device *dev)
|
||||||
|
{
|
||||||
|
struct spi_mcux_data *data = dev->data;
|
||||||
|
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
|
||||||
|
|
||||||
|
LPSPI_MasterTransferHandleIRQ(LPSPI_IRQ_HANDLE_ARG, &data->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spi_mcux_master_callback(LPSPI_Type *base, lpspi_master_handle_t *handle,
|
||||||
|
status_t status, void *userData)
|
||||||
|
{
|
||||||
|
struct spi_mcux_data *data = userData;
|
||||||
|
|
||||||
|
#ifdef CONFIG_SPI_RTIO
|
||||||
|
struct spi_rtio *rtio_ctx = data->rtio_ctx;
|
||||||
|
|
||||||
|
if (rtio_ctx->txn_head != NULL) {
|
||||||
|
spi_mcux_iodev_complete(data->dev, status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
spi_context_update_tx(&data->ctx, 1, data->transfer_len);
|
||||||
|
spi_context_update_rx(&data->ctx, 1, data->transfer_len);
|
||||||
|
|
||||||
|
spi_mcux_transfer_next_packet(data->dev);
|
||||||
|
}
|
||||||
|
|
||||||
static int spi_mcux_transfer_next_packet(const struct device *dev)
|
static int spi_mcux_transfer_next_packet(const struct device *dev)
|
||||||
{
|
{
|
||||||
/* const struct spi_mcux_config *config = dev->config; */
|
/* const struct spi_mcux_config *config = dev->config; */
|
||||||
|
@ -155,38 +186,6 @@ static int spi_mcux_transfer_next_packet(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_mcux_isr(const struct device *dev)
|
|
||||||
{
|
|
||||||
/* const struct spi_mcux_config *config = dev->config; */
|
|
||||||
struct spi_mcux_data *data = dev->data;
|
|
||||||
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
|
|
||||||
|
|
||||||
#if CONFIG_NXP_LP_FLEXCOMM
|
|
||||||
LPSPI_MasterTransferHandleIRQ(LPSPI_GetInstance(base), &data->handle);
|
|
||||||
#else
|
|
||||||
LPSPI_MasterTransferHandleIRQ(base, &data->handle);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spi_mcux_master_transfer_callback(LPSPI_Type *base, lpspi_master_handle_t *handle,
|
|
||||||
status_t status, void *userData)
|
|
||||||
{
|
|
||||||
struct spi_mcux_data *data = userData;
|
|
||||||
|
|
||||||
#ifdef CONFIG_SPI_RTIO
|
|
||||||
struct spi_rtio *rtio_ctx = data->rtio_ctx;
|
|
||||||
|
|
||||||
if (rtio_ctx->txn_head != NULL) {
|
|
||||||
spi_mcux_iodev_complete(data->dev, status);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
spi_context_update_tx(&data->ctx, 1, data->transfer_len);
|
|
||||||
spi_context_update_rx(&data->ctx, 1, data->transfer_len);
|
|
||||||
|
|
||||||
spi_mcux_transfer_next_packet(data->dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cfg)
|
static int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cfg)
|
||||||
{
|
{
|
||||||
const struct spi_mcux_config *config = dev->config;
|
const struct spi_mcux_config *config = dev->config;
|
||||||
|
@ -264,8 +263,7 @@ static int spi_mcux_configure(const struct device *dev, const struct spi_config
|
||||||
base->CR |= LPSPI_CR_DBGEN_MASK;
|
base->CR |= LPSPI_CR_DBGEN_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_transfer_callback,
|
LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_callback, data);
|
||||||
data);
|
|
||||||
|
|
||||||
LPSPI_SetDummyData(base, 0);
|
LPSPI_SetDummyData(base, 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue