aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/LPC214x
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/LPC214x
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/LPC214x')
-rw-r--r--os/hal/platforms/LPC214x/spi_lld.c31
-rw-r--r--os/hal/platforms/LPC214x/spi_lld.h5
2 files changed, 26 insertions, 10 deletions
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
@@ -117,10 +117,6 @@ typedef struct {
*/
uint16_t spc_cr0;
/**
- * @brief SSP CR1 initialization data.
- */
- uint16_t spc_cr1;
- /**
* @brief SSP CPSR initialization data.
*/
uint32_t spc_cpsr;
@@ -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