More SPI code, DMA fixes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14210 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
43d0ad4075
commit
1e4eaf089e
|
@ -62,6 +62,10 @@
|
|||
*/
|
||||
#define RP_SPI_USE_SPI0 TRUE
|
||||
#define RP_SPI_USE_SPI1 TRUE
|
||||
#define RP_SPI_SPI0_RX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY
|
||||
#define RP_SPI_SPI0_TX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY
|
||||
#define RP_SPI_SPI1_RX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY
|
||||
#define RP_SPI_SPI1_TX_DMA_CHANNEL RP_DMA_CHANNEL_ID_ANY
|
||||
#define RP_SPI_SPI0_DMA_PRIORITY 1
|
||||
#define RP_SPI_SPI1_DMA_PRIORITY 1
|
||||
|
||||
|
|
|
@ -257,13 +257,13 @@ const rp_dma_channel_t *dmaChannelAllocI(uint32_t id,
|
|||
|
||||
osalDbgCheckClassI();
|
||||
|
||||
if (id < RP_DMA_STREAM_ID_ANY) {
|
||||
if (id < RP_DMA_CHANNEL_ID_ANY) {
|
||||
startid = id;
|
||||
endid = id;
|
||||
}
|
||||
else if (id == RP_DMA_STREAM_ID_ANY) {
|
||||
else if (id == RP_DMA_CHANNEL_ID_ANY) {
|
||||
startid = 0U;
|
||||
endid = RP_DMA_STREAM_ID_ANY - 1U;
|
||||
endid = RP_DMA_CHANNEL_ID_ANY - 1U;
|
||||
}
|
||||
else {
|
||||
osalDbgCheck(false);
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
/**
|
||||
* @brief Any channel selector.
|
||||
*/
|
||||
#define RP_DMA_STREAM_ID_ANY RP_DMA_CHANNELS
|
||||
#define RP_DMA_CHANNEL_ID_ANY RP_DMA_CHANNELS
|
||||
|
||||
/**
|
||||
* @brief Returns a pointer to a @p rp_dma_channel_t structure.
|
||||
|
@ -67,7 +67,7 @@
|
|||
* @return A pointer to the @p rp_dma_channel_t constant structure
|
||||
* associated to the DMA channel.
|
||||
*/
|
||||
#define RP_DMA_CHANNEL(id) (&__rp_dma_channels[id])
|
||||
#define RP_DMA_CHANNEL(id) (&__rp_dma_channels[id])
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
|
|
|
@ -56,6 +56,30 @@ SPIDriver SPID1;
|
|||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Shared end-of-rx service routine.
|
||||
*
|
||||
* @param[in] spip pointer to the @p SPIDriver object
|
||||
* @param[in] ct content of the CTRL_TRIG register
|
||||
*/
|
||||
static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t ct) {
|
||||
|
||||
(void)spip;
|
||||
(void)ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shared end-of-tx service routine.
|
||||
*
|
||||
* @param[in] spip pointer to the @p SPIDriver object
|
||||
* @param[in] ct content of the CTRL_TRIG register
|
||||
*/
|
||||
static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t ct) {
|
||||
|
||||
(void)spip;
|
||||
(void)ct;
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
@ -106,11 +130,45 @@ void spi_lld_start(SPIDriver *spip) {
|
|||
|
||||
if (spip->state == SPI_STOP) {
|
||||
/* Enables the peripheral.*/
|
||||
#if RP_SPI_USE_SPI1 == TRUE
|
||||
if (&SPID1 == spip) {
|
||||
|
||||
if (false) {
|
||||
}
|
||||
#if RP_SPI_USE_SPI0 == TRUE
|
||||
if (&SPID0 == spip) {
|
||||
spip->dmarx = dmaChannelAllocI(RP_SPI_SPI0_RX_DMA_CHANNEL,
|
||||
RP_IRQ_SPI0_PRIORITY,
|
||||
(rp_dmaisr_t)spi_lld_serve_rx_interrupt,
|
||||
(void *)spip);
|
||||
osalDbgAssert(spip->dmarx != NULL, "unable to allocate stream");
|
||||
spip->dmatx = dmaChannelAllocI(RP_SPI_SPI0_TX_DMA_CHANNEL,
|
||||
RP_IRQ_SPI0_PRIORITY,
|
||||
(rp_dmaisr_t)spi_lld_serve_tx_interrupt,
|
||||
(void *)spip);
|
||||
osalDbgAssert(spip->dmatx != NULL, "unable to allocate stream");
|
||||
dmaChannelEnableInterruptX(spip->dmarx);
|
||||
dmaChannelEnableInterruptX(spip->dmatx);
|
||||
hal_lld_peripheral_unreset(RESETS_ALLREG_SPI0);
|
||||
}
|
||||
#endif
|
||||
#if RP_SPI_USE_SPI1 == TRUE
|
||||
if (&SPID1 == spip) {
|
||||
spip->dmarx = dmaChannelAllocI(RP_SPI_SPI1_RX_DMA_CHANNEL,
|
||||
RP_IRQ_SPI1_PRIORITY,
|
||||
(rp_dmaisr_t)spi_lld_serve_rx_interrupt,
|
||||
(void *)spip);
|
||||
osalDbgAssert(spip->dmarx != NULL, "unable to allocate stream");
|
||||
spip->dmatx = dmaChannelAllocI(RP_SPI_SPI1_TX_DMA_CHANNEL,
|
||||
RP_IRQ_SPI1_PRIORITY,
|
||||
(rp_dmaisr_t)spi_lld_serve_tx_interrupt,
|
||||
(void *)spip);
|
||||
osalDbgAssert(spip->dmatx != NULL, "unable to allocate stream");
|
||||
dmaChannelEnableInterruptX(spip->dmarx);
|
||||
dmaChannelEnableInterruptX(spip->dmatx);
|
||||
hal_lld_peripheral_unreset(RESETS_ALLREG_SPI1);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
osalDbgAssert(false, "invalid SPI instance");
|
||||
}
|
||||
}
|
||||
/* Configures the peripheral.*/
|
||||
|
||||
|
|
|
@ -40,59 +40,6 @@
|
|||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name RP configuration options
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief SPI0 driver enable switch.
|
||||
* @details If set to @p TRUE the support for SPI1 is included.
|
||||
* @note The default is @p FALSE.
|
||||
*/
|
||||
#if !defined(RP_SPI_USE_SPI0) || defined(__DOXYGEN__)
|
||||
#define RP_SPI_USE_SPI0 FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPI1 driver enable switch.
|
||||
* @details If set to @p TRUE the support for SPI1 is included.
|
||||
* @note The default is @p FALSE.
|
||||
*/
|
||||
#if !defined(RP_SPI_USE_SPI1) || defined(__DOXYGEN__)
|
||||
#define RP_SPI_USE_SPI1 FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPI0 interrupt priority level setting.
|
||||
*/
|
||||
#if !defined(RP_IRQ_SPI0_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_IRQ_SPI0_PRIORITY 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPI1 interrupt priority level setting.
|
||||
*/
|
||||
#if !defined(RP_IRQ_SPI1_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_IRQ_SPI1_PRIORITY 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPI0 DMA priority (0..1|lowest..highest).
|
||||
* @note The priority level is used for both the TX and RX DMA streams.
|
||||
*/
|
||||
#if !defined(RP_SPI_SPI0_DMA_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_SPI_SPI0_DMA_PRIORITY 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SPI1 DMA priority (0..1|lowest..highest).
|
||||
* @note The priority level is used for both the TX and RX DMA streams.
|
||||
*/
|
||||
#if !defined(RP_SPI_SPI1_DMA_PRIORITY) || defined(__DOXYGEN__)
|
||||
#define RP_SPI_SPI1_DMA_PRIORITY 1
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
@ -106,6 +53,47 @@
|
|||
#error "RP_HAS_SPI1 not defined in registry"
|
||||
#endif
|
||||
|
||||
/* Mcuconf.h checks.*/
|
||||
#if !defined(RP_SPI_USE_SPI0)
|
||||
#error "RP_SPI_USE_SPI0 not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_USE_SPI1)
|
||||
#error "RP_SPI_USE_SPI1 not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_IRQ_SPI0_PRIORITY)
|
||||
#error "RP_IRQ_SPI0_PRIORITY not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_IRQ_SPI1_PRIORITY)
|
||||
#error "RP_IRQ_SPI1_PRIORITY not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI0_RX_DMA_CHANNEL)
|
||||
#error "RP_SPI_SPI0_RX_DMA_CHANNEL not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI0_TX_DMA_CHANNEL)
|
||||
#error "RP_SPI_SPI0_TX_DMA_CHANNEL not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI1_RX_DMA_CHANNEL)
|
||||
#error "RP_SPI_SPI0_RX_DMA_CHANNEL not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI1_TX_DMA_CHANNEL)
|
||||
#error "RP_SPI_SPI0_TX_DMA_CHANNEL not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI0_DMA_PRIORITY)
|
||||
#error "RP_SPI_SPI0_DMA_PRIORITY not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
#if !defined(RP_SPI_SPI1_DMA_PRIORITY)
|
||||
#error "RP_SPI_SPI1_DMA_PRIORITY not defined in mcuconf.h"
|
||||
#endif
|
||||
|
||||
/* Device selection checks.*/
|
||||
#if RP_SPI_USE_SPI0 && !RP_HAS_SPI0
|
||||
#error "SPI0 not present in the selected device"
|
||||
|
|
Loading…
Reference in New Issue