From a884e58e2cea877f804cb643d4d1e0909bd1fa49 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 30 Oct 2010 11:18:28 +0000 Subject: Added a polled exchange function to the SPI driver model, implemented on LPCxxxx SPI drivers. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2302 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/LPC214x/spi_lld.c | 31 +++++++++++++++++++++++++------ os/hal/platforms/LPC214x/spi_lld.h | 5 +---- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'os/hal/platforms/LPC214x') diff --git a/os/hal/platforms/LPC214x/spi_lld.c b/os/hal/platforms/LPC214x/spi_lld.c index 7c3287298..6df0106b2 100644 --- a/os/hal/platforms/LPC214x/spi_lld.c +++ b/os/hal/platforms/LPC214x/spi_lld.c @@ -99,7 +99,7 @@ static void serve_interrupt(SPIDriver *spip) { (void)ssp->SSP_DR; if (--spip->spd_rxcnt == 0) { chDbgAssert(spip->spd_txcnt == 0, - "chSemResetI(), #1", "counter out of synch"); + "spi_serve_interrupt(), #1", "counter out of synch"); /* Stops the IRQ sources.*/ ssp->SSP_IMSC = 0; /* Portable SPI ISR code defined in the high level driver, note, it is @@ -178,7 +178,7 @@ void spi_lld_start(SPIDriver *spip) { spip->spd_ssp->SSP_ICR = ICR_RT | ICR_ROR; spip->spd_ssp->SSP_CR0 = spip->spd_config->spc_cr0; spip->spd_ssp->SSP_CPSR = spip->spd_config->spc_cpsr; - spip->spd_ssp->SSP_CR1 = spip->spd_config->spc_cr1 | CR1_SSE; + spip->spd_ssp->SSP_CR1 = CR1_SSE; } /** @@ -191,16 +191,15 @@ void spi_lld_start(SPIDriver *spip) { void spi_lld_stop(SPIDriver *spip) { if (spip->spd_state != SPI_STOP) { + spip->spd_ssp->SSP_CR1 = 0; + spip->spd_ssp->SSP_CR0 = 0; + spip->spd_ssp->SSP_CPSR = 0; #if LPC214x_SPI_USE_SSP if (&SPID1 == spip) { PCONP = (PCONP & PCALL) & ~PCSPI1; VICIntEnClear = INTMASK(SOURCE_SPI1); } #endif - spip->spd_ssp->SSP_CR1 = 0; - spip->spd_ssp->SSP_CR0 = 0; - spip->spd_ssp->SSP_CPSR = 0; - PCONP &= ~PCSPI1; } } @@ -318,6 +317,26 @@ void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) { spip->spd_ssp->SSP_IMSC = IMSC_ROR | IMSC_RT | IMSC_TX | IMSC_RX; } +/** + * @brief Exchanges one frame using a polled wait. + * @details This synchronous function exchanges one frame using a polled + * synchronization method. This function is useful when exchanging + * small amount of data on high speed channels, usually in this + * situation is much more efficient just wait for completion using + * polling than suspending the thread waiting for an interrupt. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] frame the data frame to send over the SPI bus + * @return The received data frame from the SPI bus. + */ +uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) { + + spip->spd_ssp->SSP_DR = (uint32_t)frame; + while ((spip->spd_ssp->SSP_SR & SR_RNE) == 0) + ; + return (uint16_t)spip->spd_ssp->SSP_DR; +} + #endif /* CH_HAL_USE_SPI */ /** @} */ diff --git a/os/hal/platforms/LPC214x/spi_lld.h b/os/hal/platforms/LPC214x/spi_lld.h index eafa23f88..a4b16f76a 100644 --- a/os/hal/platforms/LPC214x/spi_lld.h +++ b/os/hal/platforms/LPC214x/spi_lld.h @@ -116,10 +116,6 @@ typedef struct { * @brief SSP CR0 initialization data. */ uint16_t spc_cr0; - /** - * @brief SSP CR1 initialization data. - */ - uint16_t spc_cr1; /** * @brief SSP CPSR initialization data. */ @@ -205,6 +201,7 @@ extern "C" { const void *txbuf, void *rxbuf); void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf); void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf); + uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame); #ifdef __cplusplus } #endif -- cgit v1.2.3