From 43f9fd4180030081daae9122bd57a521ec9c58e1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 30 Oct 2009 15:45:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1258 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/spi.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'os/io/spi.c') diff --git a/os/io/spi.c b/os/io/spi.c index be34c469d..5cf51e76e 100644 --- a/os/io/spi.c +++ b/os/io/spi.c @@ -42,7 +42,7 @@ void spiInit(void) { */ void spiObjectInit(SPIDriver *spip) { - spip->spd_state = SPI_IDLE; + spip->spd_state = SPI_STOP; #if CH_USE_MUTEXES chMtxInit(&spip->spd_mutex); #elif CH_USE_SEMAPHORES @@ -52,20 +52,37 @@ void spiObjectInit(SPIDriver *spip) { } /** - * @brief Configures the SPI bus. + * @brief Configures and activates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object * @param config pointer to the @p SPIConfig object */ -void spiSetup(SPIDriver *spip, const SPIConfig *config) { +void spiStart(SPIDriver *spip, const SPIConfig *config) { - chDbgCheck((spip != NULL) && (config != NULL), "spiSetup"); - chDbgAssert(spip->spd_state == SPI_IDLE, - "spiSetup(), #1", - "not idle"); + chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStart(), #1", + "invalid state"); spip->spd_config = config; - spi_lld_setup(spip); + spi_lld_start(spip); + spip->spd_state = SPI_READY; +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiStop(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiStop"); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStop(), #1", + "invalid state"); + + spi_lld_stop(spip); + spip->spd_state = SPI_STOP; } /** @@ -77,19 +94,16 @@ void spiSelect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiSelect"); - chSysLock(); - - chDbgAssert(spip->spd_state == SPI_IDLE, + chDbgAssert(spip->spd_state == SPI_READY, "spiSelect(), #1", "not idle"); spi_lld_select(spip); spip->spd_state = SPI_ACTIVE; - chSysUnlock(); } /** - * @brief De-asserts the slave select signal. + * @brief Deasserts the slave select signal. * @details The previously selected peripheral is unselected. * * @param[in] spip pointer to the @p SPIDriver object @@ -98,15 +112,12 @@ void spiUnselect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiUnselect"); - chSysLock(); - chDbgAssert(spip->spd_state == SPI_ACTIVE, "spiUnselect(), #1", "not locked"); spi_lld_unselect(spip); - spip->spd_state = SPI_IDLE; - chSysUnlock(); + spip->spd_state = SPI_READY; } /** -- cgit v1.2.3