From e5c320a0d1a00915f88b379f27e981b89a787e33 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 18 Mar 2012 20:30:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4050 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/i2s.h | 12 +++++++++++ os/hal/platforms/STM32/i2s_lld.c | 45 ++++++++++++++++++++++++++++++++++++++-- os/hal/platforms/STM32/i2s_lld.h | 1 + os/hal/src/i2s.c | 21 ++++++++++++++++++- 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/os/hal/include/i2s.h b/os/hal/include/i2s.h index ee2fabf6e..241bb5ec7 100644 --- a/os/hal/include/i2s.h +++ b/os/hal/include/i2s.h @@ -85,6 +85,18 @@ typedef struct I2SDriver I2SDriver; (i2sp)->state = I2S_ACTIVE; \ } +/** + * @brief Starts a I2S data exchange in continuous mode. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @iclass + */ +#define i2sStartExchangeContinuousI(i2sp) { \ + i2s_lld_start_exchange_continuous(i2sp); \ + (i2sp)->state = I2S_ACTIVE; \ +} + /** * @brief Stops the ongoing data exchange. * @details The ongoing data exchange, if any, is stopped, if the driver diff --git a/os/hal/platforms/STM32/i2s_lld.c b/os/hal/platforms/STM32/i2s_lld.c index 8a0ec368d..692988385 100644 --- a/os/hal/platforms/STM32/i2s_lld.c +++ b/os/hal/platforms/STM32/i2s_lld.c @@ -62,6 +62,15 @@ */ void i2s_lld_init(void) { +#if STM32_I2S_USE_I2S2 + spiObjectInit(&I2SD2); + I2SD2.spi = SPI2; +#endif + +#if STM32_I2S_USE_I2S3 + spiObjectInit(&I2SD3); + I2SD3.spi = SPI3; +#endif } /** @@ -73,8 +82,30 @@ void i2s_lld_init(void) { */ void i2s_lld_start(I2SDriver *i2sp) { + /* If in stopped state then enables the SPI and DMA clocks.*/ if (i2sp->state == I2S_STOP) { - /* Clock activation.*/ +#if STM32_SPI_USE_SPI2 + if (&SPID2 == spip) { + bool_t b; + b = dmaStreamAllocate(spip->dma, + STM32_I2S_I2S2_IRQ_PRIORITY, + (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, + (void *)spip); + chDbgAssert(!b, "spi_lld_start(), #1", "stream already allocated"); + rccEnableSPI2(FALSE); + } +#endif +#if STM32_SPI_USE_SPI3 + if (&SPID3 == spip) { + bool_t b; + b = dmaStreamAllocate(spip->dma, + STM32_I2S_I2S3_IRQ_PRIORITY, + (stm32_dmaisr_t)i2s_lld_serve_rx_interrupt, + (void *)spip); + chDbgAssert(!b, "spi_lld_start(), #2", "stream already allocated"); + rccEnableSPI3(FALSE); + } +#endif } /* Configuration.*/ } @@ -94,7 +125,6 @@ void i2s_lld_stop(I2SDriver *i2sp) { } } - /** * @brief Starts a I2S data exchange. * @@ -106,6 +136,17 @@ void i2s_lld_start_exchange(I2SDriver *i2sp) { } +/** + * @brief Starts a I2S data exchange in continuous mode. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @notapi + */ +void i2s_lld_start_exchange_continuous(I2SDriver *i2sp) { + +} + /** * @brief Stops the ongoing data exchange. * @details The ongoing data exchange, if any, is stopped, if the driver diff --git a/os/hal/platforms/STM32/i2s_lld.h b/os/hal/platforms/STM32/i2s_lld.h index a2870419d..c56ab8ccb 100644 --- a/os/hal/platforms/STM32/i2s_lld.h +++ b/os/hal/platforms/STM32/i2s_lld.h @@ -311,6 +311,7 @@ extern "C" { void i2s_lld_start(I2SDriver *i2sp); void i2s_lld_stop(I2SDriver *i2sp); void i2s_lld_start_exchange(I2SDriver *i2sp); + void i2s_lld_start_exchange_continuous(I2SDriver *i2sp); void i2s_lld_stop_exchange(I2SDriver *i2sp); #ifdef __cplusplus } diff --git a/os/hal/src/i2s.c b/os/hal/src/i2s.c index e0c547847..99e4246ad 100644 --- a/os/hal/src/i2s.c +++ b/os/hal/src/i2s.c @@ -128,11 +128,30 @@ void i2sStartExchange(I2SDriver *i2sp) { chDbgCheck(i2sp != NULL "i2sStartExchange"); chSysLock(); - chDbgAssert(i2sp->state == I2S_READY, "i2sStartExchange(), #1", "not ready"); + chDbgAssert(i2sp->state == I2S_READY, + "i2sStartExchange(), #1", "not ready"); i2sStartExchangeI(i2sp); chSysUnlock(); } +/** + * @brief Starts a I2S data exchange in continuous mode. + * + * @param[in] i2sp pointer to the @p I2SDriver object + * + * @api + */ +void i2sStartExchangeContinuous(I2SDriver *i2sp) { + + chDbgCheck(i2sp != NULL "i2sStartExchangeContinuous"); + + chSysLock(); + chDbgAssert(i2sp->state == I2S_READY, + "i2sStartExchangeContinuous(), #1", "not ready"); + i2sStartExchangeContinuousI(i2sp); + chSysUnlock(); +} + /** * @brief Stops the ongoing data exchange. * @details The ongoing data exchange, if any, is stopped, if the driver -- cgit v1.2.3