aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/LPC11xx
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-30 11:18:28 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-30 11:18:28 +0000
commita884e58e2cea877f804cb643d4d1e0909bd1fa49 (patch)
tree5a0e292f8b7ae213756e92d4710711fbd57db296 /os/hal/platforms/LPC11xx
parent0cef5f4877397e508bdf5706ef8fada52cdb9d49 (diff)
downloadChibiOS-a884e58e2cea877f804cb643d4d1e0909bd1fa49.tar.gz
ChibiOS-a884e58e2cea877f804cb643d4d1e0909bd1fa49.tar.bz2
ChibiOS-a884e58e2cea877f804cb643d4d1e0909bd1fa49.zip
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
Diffstat (limited to 'os/hal/platforms/LPC11xx')
-rw-r--r--os/hal/platforms/LPC11xx/spi_lld.c28
-rw-r--r--os/hal/platforms/LPC11xx/spi_lld.h1
2 files changed, 24 insertions, 5 deletions
diff --git a/os/hal/platforms/LPC11xx/spi_lld.c b/os/hal/platforms/LPC11xx/spi_lld.c
index becf691a3..8b0081b5e 100644
--- a/os/hal/platforms/LPC11xx/spi_lld.c
+++ b/os/hal/platforms/LPC11xx/spi_lld.c
@@ -234,13 +234,15 @@ void spi_lld_start(SPIDriver *spip) {
void spi_lld_stop(SPIDriver *spip) {
if (spip->spd_state != SPI_STOP) {
+ spip->spd_ssp->CR1 = 0;
+ spip->spd_ssp->CR0 = 0;
+ spip->spd_ssp->CPSR = 0;
#if LPC11xx_SPI_USE_SSP0
if (&SPID1 == spip) {
LPC_SYSCON->PRESETCTRL &= ~1;
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 11);
LPC_SYSCON->SSP0CLKDIV = 0;
NVICDisableVector(SSP0_IRQn);
- return;
}
#endif
#if LPC11xx_SPI_USE_SSP1
@@ -249,12 +251,8 @@ void spi_lld_stop(SPIDriver *spip) {
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 18);
LPC_SYSCON->SSP1CLKDIV = 0;
NVICDisableVector(SSP1_IRQn);
- return;
}
#endif
- spip->spd_ssp->CR1 = 0;
- spip->spd_ssp->CR0 = 0;
- spip->spd_ssp->CPSR = 0;
}
}
@@ -372,6 +370,26 @@ void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
spip->spd_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->DR = (uint32_t)frame;
+ while ((spip->spd_ssp->SR & SR_RNE) == 0)
+ ;
+ return (uint16_t)spip->spd_ssp->DR;
+}
+
#endif /* CH_HAL_USE_SPI */
/** @} */
diff --git a/os/hal/platforms/LPC11xx/spi_lld.h b/os/hal/platforms/LPC11xx/spi_lld.h
index 021099097..b3f38056f 100644
--- a/os/hal/platforms/LPC11xx/spi_lld.h
+++ b/os/hal/platforms/LPC11xx/spi_lld.h
@@ -334,6 +334,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