From 16178e1c45a76544d34ce63db37932838353637c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 28 Nov 2009 12:25:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1333 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 os/hal/src/spi.c (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c new file mode 100644 index 000000000..8b8ea6f32 --- /dev/null +++ b/os/hal/src/spi.c @@ -0,0 +1,262 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file spi.c + * @brief SPI Driver code. + * @addtogroup SPI + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SPI + +/** + * @brief SPI Driver initialization. + */ +void spiInit(void) { + + spi_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p SPIDriver structure. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiObjectInit(SPIDriver *spip) { + + spip->spd_state = SPI_STOP; +#if CH_USE_MUTEXES + chMtxInit(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&spip->spd_semaphore, 1); +#endif + spip->spd_config = NULL; +} + +/** + * @brief Configures and activates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] config pointer to the @p SPIConfig object + */ +void spiStart(SPIDriver *spip, const SPIConfig *config) { + + chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStart(), #1", + "invalid state"); + spip->spd_config = config; + spi_lld_start(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiStop(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiStop"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStop(), #1", + "invalid state"); + spi_lld_stop(spip); + spip->spd_state = SPI_STOP; + chSysUnlock(); +} + +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiSelect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiSelect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiSelect(), #1", + "not idle"); + spi_lld_select(spip); + spip->spd_state = SPI_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deasserts the slave select signal. + * @details The previously selected peripheral is unselected. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiUnselect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiUnselect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiUnselect(), #1", + "not locked"); + spi_lld_unselect(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Ignores data on the SPI bus. + * @details This function transmits a series of idle words on the SPI bus and + * ignores the received data. This function can be invoked even + * when a slave select signal has not been yet asserted. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + */ +void spiIgnore(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), + "spiIgnore(), #1", + "not active"); + + spi_lld_ignore(spip, n); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This function performs a simultaneous transmit/receive operation. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be exchanged + * @param[in] txbuf the pointer to the transmit buffer + * @param[out] rxbuf the pointer to the receive buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchange"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiExchange(), #1", + "not active"); + + spi_lld_exchange(spip, n, txbuf, rxbuf); +} + +/** + * @brief Sends data ever the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSend"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiSend(), #1", + "not active"); + + spi_lld_send(spip, n, txbuf); +} + +/** + * @brief Receives data from the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceive"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiReceive(), #1", + "not active"); + + spi_lld_receive(spip, n, rxbuf); +} + +#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the SPI bus. + * @details This function tries to gain ownership to the SPI bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiAcquireBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&spip->spd_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiReleaseBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiReleaseBus"); + +#if CH_USE_MUTEXES + (void)spip; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&spip->spd_semaphore); +#endif +} +#endif /*SPI_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_SPI */ + +/** @} */ -- cgit v1.2.3 From 0d0e4d619185ad86270ca5c0212c314f7f4529d5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:25:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1342 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 262 ------------------------------------------------------- 1 file changed, 262 deletions(-) delete mode 100644 os/hal/src/spi.c (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c deleted file mode 100644 index 8b8ea6f32..000000000 --- a/os/hal/src/spi.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file spi.c - * @brief SPI Driver code. - * @addtogroup SPI - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if CH_HAL_USE_SPI - -/** - * @brief SPI Driver initialization. - */ -void spiInit(void) { - - spi_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p SPIDriver structure. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiObjectInit(SPIDriver *spip) { - - spip->spd_state = SPI_STOP; -#if CH_USE_MUTEXES - chMtxInit(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES - chSemInit(&spip->spd_semaphore, 1); -#endif - spip->spd_config = NULL; -} - -/** - * @brief Configures and activates the SPI peripheral. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] config pointer to the @p SPIConfig object - */ -void spiStart(SPIDriver *spip, const SPIConfig *config) { - - chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStart(), #1", - "invalid state"); - spip->spd_config = config; - spi_lld_start(spip); - spip->spd_state = SPI_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the SPI peripheral. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiStop(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiStop"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStop(), #1", - "invalid state"); - spi_lld_stop(spip); - spip->spd_state = SPI_STOP; - chSysUnlock(); -} - -/** - * @brief Asserts the slave select signal and prepares for transfers. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiSelect(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiSelect"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), - "spiSelect(), #1", - "not idle"); - spi_lld_select(spip); - spip->spd_state = SPI_ACTIVE; - chSysUnlock(); -} - -/** - * @brief Deasserts the slave select signal. - * @details The previously selected peripheral is unselected. - * - * @param[in] spip pointer to the @p SPIDriver object - */ -void spiUnselect(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiUnselect"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), - "spiUnselect(), #1", - "not locked"); - spi_lld_unselect(spip); - spip->spd_state = SPI_READY; - chSysUnlock(); -} - -/** - * @brief Ignores data on the SPI bus. - * @details This function transmits a series of idle words on the SPI bus and - * ignores the received data. This function can be invoked even - * when a slave select signal has not been yet asserted. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be ignored - */ -void spiIgnore(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); - chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), - "spiIgnore(), #1", - "not active"); - - spi_lld_ignore(spip, n); -} - -/** - * @brief Exchanges data on the SPI bus. - * @details This function performs a simultaneous transmit/receive operation. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be exchanged - * @param[in] txbuf the pointer to the transmit buffer - * @param[out] rxbuf the pointer to the receive buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. - */ -void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchange"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiExchange(), #1", - "not active"); - - spi_lld_exchange(spip, n, txbuf, rxbuf); -} - -/** - * @brief Sends data ever the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. - */ -void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiSend(), #1", - "not active"); - - spi_lld_send(spip, n, txbuf); -} - -/** - * @brief Receives data from the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to receive - * @param[out] rxbuf the pointer to the receive buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. - */ -void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { - - chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceive"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, - "spiReceive(), #1", - "not active"); - - spi_lld_receive(spip, n, rxbuf); -} - -#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the SPI bus. - * @details This function tries to gain ownership to the SPI bus, if the bus - * is already being used then the invoking thread is queued. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void spiAcquireBus(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&spip->spd_semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the SPI bus. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void spiReleaseBus(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiReleaseBus"); - -#if CH_USE_MUTEXES - (void)spip; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&spip->spd_semaphore); -#endif -} -#endif /*SPI_USE_MUTUAL_EXCLUSION */ - -#endif /* CH_HAL_USE_SPI */ - -/** @} */ -- cgit v1.2.3 From d4c616e6eeb0587ca450c75b1086efa77ac690e5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 08:50:13 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1351 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 os/hal/src/spi.c (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c new file mode 100644 index 000000000..8b8ea6f32 --- /dev/null +++ b/os/hal/src/spi.c @@ -0,0 +1,262 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file spi.c + * @brief SPI Driver code. + * @addtogroup SPI + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_SPI + +/** + * @brief SPI Driver initialization. + */ +void spiInit(void) { + + spi_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p SPIDriver structure. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiObjectInit(SPIDriver *spip) { + + spip->spd_state = SPI_STOP; +#if CH_USE_MUTEXES + chMtxInit(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&spip->spd_semaphore, 1); +#endif + spip->spd_config = NULL; +} + +/** + * @brief Configures and activates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] config pointer to the @p SPIConfig object + */ +void spiStart(SPIDriver *spip, const SPIConfig *config) { + + chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStart(), #1", + "invalid state"); + spip->spd_config = config; + spi_lld_start(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiStop(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiStop"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + "spiStop(), #1", + "invalid state"); + spi_lld_stop(spip); + spip->spd_state = SPI_STOP; + chSysUnlock(); +} + +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiSelect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiSelect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiSelect(), #1", + "not idle"); + spi_lld_select(spip); + spip->spd_state = SPI_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Deasserts the slave select signal. + * @details The previously selected peripheral is unselected. + * + * @param[in] spip pointer to the @p SPIDriver object + */ +void spiUnselect(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiUnselect"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_ACTIVE), + "spiUnselect(), #1", + "not locked"); + spi_lld_unselect(spip); + spip->spd_state = SPI_READY; + chSysUnlock(); +} + +/** + * @brief Ignores data on the SPI bus. + * @details This function transmits a series of idle words on the SPI bus and + * ignores the received data. This function can be invoked even + * when a slave select signal has not been yet asserted. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + */ +void spiIgnore(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), + "spiIgnore(), #1", + "not active"); + + spi_lld_ignore(spip, n); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This function performs a simultaneous transmit/receive operation. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be exchanged + * @param[in] txbuf the pointer to the transmit buffer + * @param[out] rxbuf the pointer to the receive buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchange"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiExchange(), #1", + "not active"); + + spi_lld_exchange(spip, n, txbuf, rxbuf); +} + +/** + * @brief Sends data ever the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSend"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiSend(), #1", + "not active"); + + spi_lld_send(spip, n, txbuf); +} + +/** + * @brief Receives data from the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @note The buffers are organized as uint8_t arrays for data sizes below or + * equal to 8 bits else it is organized as uint16_t arrays. + */ +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceive"); + chDbgAssert(spip->spd_state == SPI_ACTIVE, + "spiReceive(), #1", + "not active"); + + spi_lld_receive(spip, n, rxbuf); +} + +#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the SPI bus. + * @details This function tries to gain ownership to the SPI bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiAcquireBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&spip->spd_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&spip->spd_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the SPI bus. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void spiReleaseBus(SPIDriver *spip) { + + chDbgCheck(spip != NULL, "spiReleaseBus"); + +#if CH_USE_MUTEXES + (void)spip; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&spip->spd_semaphore); +#endif +} +#endif /*SPI_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_SPI */ + +/** @} */ -- cgit v1.2.3 From f90ae4d17df24cd6477f2557bc86ef9433e93414 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Nov 2009 10:37:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1354 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 8b8ea6f32..08113a000 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -27,7 +27,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SPI +#if CH_HAL_USE_SPI || defined(__DOXYGEN__) /** * @brief SPI Driver initialization. -- cgit v1.2.3 From fe24da9fcca4967e58b25a2698c46717995de0ad Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Dec 2009 11:12:05 +0000 Subject: Reorganized sections in HAL files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1473 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 08113a000..36bde9a3a 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -29,6 +29,22 @@ #if CH_HAL_USE_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + /** * @brief SPI Driver initialization. */ @@ -255,7 +271,7 @@ void spiReleaseBus(SPIDriver *spip) { chSemSignal(&spip->spd_semaphore); #endif } -#endif /*SPI_USE_MUTUAL_EXCLUSION */ +#endif /* SPI_USE_MUTUAL_EXCLUSION */ #endif /* CH_HAL_USE_SPI */ -- cgit v1.2.3 From e3c7dc319ff582f9eb4a593950ac7bedb1d38b77 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 16:17:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1571 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 36bde9a3a..611a454a7 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -18,8 +18,9 @@ */ /** - * @file spi.c - * @brief SPI Driver code. + * @file spi.c + * @brief SPI Driver code. + * * @addtogroup SPI * @{ */ @@ -46,7 +47,7 @@ /*===========================================================================*/ /** - * @brief SPI Driver initialization. + * @brief SPI Driver initialization. */ void spiInit(void) { @@ -54,7 +55,7 @@ void spiInit(void) { } /** - * @brief Initializes the standard part of a @p SPIDriver structure. + * @brief Initializes the standard part of a @p SPIDriver structure. * * @param[in] spip pointer to the @p SPIDriver object */ @@ -70,7 +71,7 @@ void spiObjectInit(SPIDriver *spip) { } /** - * @brief Configures and activates the SPI peripheral. + * @brief Configures and activates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] config pointer to the @p SPIConfig object @@ -108,7 +109,7 @@ void spiStop(SPIDriver *spip) { } /** - * @brief Asserts the slave select signal and prepares for transfers. + * @brief Asserts the slave select signal and prepares for transfers. * * @param[in] spip pointer to the @p SPIDriver object */ @@ -127,7 +128,7 @@ void spiSelect(SPIDriver *spip) { } /** - * @brief Deasserts 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 @@ -147,7 +148,7 @@ void spiUnselect(SPIDriver *spip) { } /** - * @brief Ignores data on the SPI bus. + * @brief Ignores data on the SPI bus. * @details This function transmits a series of idle words on the SPI bus and * ignores the received data. This function can be invoked even * when a slave select signal has not been yet asserted. @@ -166,16 +167,15 @@ void spiIgnore(SPIDriver *spip, size_t n) { } /** - * @brief Exchanges data on the SPI bus. + * @brief Exchanges data on the SPI bus. * @details This function performs a simultaneous transmit/receive operation. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be exchanged * @param[in] txbuf the pointer to the transmit buffer * @param[out] rxbuf the pointer to the receive buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. */ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { @@ -189,14 +189,13 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { } /** - * @brief Sends data ever the SPI bus. + * @brief Sends data ever the SPI bus. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to send * @param[in] txbuf the pointer to the transmit buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { @@ -210,14 +209,13 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { } /** - * @brief Receives data from the SPI bus. + * @brief Receives data from the SPI bus. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer - * - * @note The buffers are organized as uint8_t arrays for data sizes below or - * equal to 8 bits else it is organized as uint16_t arrays. */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { @@ -232,14 +230,14 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the SPI bus. + * @brief Gains exclusive access to the SPI bus. * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. * * @param[in] spip pointer to the @p SPIDriver object * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. */ void spiAcquireBus(SPIDriver *spip) { @@ -253,12 +251,11 @@ void spiAcquireBus(SPIDriver *spip) { } /** - * @brief Releases exclusive access to the SPI bus. + * @brief Releases exclusive access to the SPI bus. + * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. * * @param[in] spip pointer to the @p SPIDriver object - * - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. */ void spiReleaseBus(SPIDriver *spip) { -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 611a454a7..29e69a283 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -110,7 +110,7 @@ void spiStop(SPIDriver *spip) { /** * @brief Asserts the slave select signal and prepares for transfers. - * + * * @param[in] spip pointer to the @p SPIDriver object */ void spiSelect(SPIDriver *spip) { @@ -130,7 +130,7 @@ void spiSelect(SPIDriver *spip) { /** * @brief Deasserts the slave select signal. * @details The previously selected peripheral is unselected. - * + * * @param[in] spip pointer to the @p SPIDriver object */ void spiUnselect(SPIDriver *spip) { @@ -152,7 +152,7 @@ void spiUnselect(SPIDriver *spip) { * @details This function transmits a series of idle words on the SPI bus and * ignores the received data. This function can be invoked even * when a slave select signal has not been yet asserted. - * + * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored */ @@ -171,9 +171,9 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @details This function performs a simultaneous transmit/receive operation. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. - * + * * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be exchanged + * @param[in] n number of words to be exchanged * @param[in] txbuf the pointer to the transmit buffer * @param[out] rxbuf the pointer to the receive buffer */ -- cgit v1.2.3 From 2891f7d645c4be187ac96ee4011207531d25c34a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 4 Oct 2010 17:16:18 +0000 Subject: Documentation improvements, fixed a small error in the STM32 serial driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2234 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 29e69a283..85cb941e6 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -48,6 +48,8 @@ /** * @brief SPI Driver initialization. + * + * @init */ void spiInit(void) { @@ -58,6 +60,8 @@ void spiInit(void) { * @brief Initializes the standard part of a @p SPIDriver structure. * * @param[in] spip pointer to the @p SPIDriver object + * + * @init */ void spiObjectInit(SPIDriver *spip) { @@ -75,6 +79,8 @@ void spiObjectInit(SPIDriver *spip) { * * @param[in] spip pointer to the @p SPIDriver object * @param[in] config pointer to the @p SPIConfig object + * + * @api */ void spiStart(SPIDriver *spip, const SPIConfig *config) { @@ -94,6 +100,8 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { * @brief Deactivates the SPI peripheral. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiStop(SPIDriver *spip) { @@ -112,6 +120,8 @@ void spiStop(SPIDriver *spip) { * @brief Asserts the slave select signal and prepares for transfers. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiSelect(SPIDriver *spip) { @@ -132,6 +142,8 @@ void spiSelect(SPIDriver *spip) { * @details The previously selected peripheral is unselected. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiUnselect(SPIDriver *spip) { @@ -155,6 +167,8 @@ void spiUnselect(SPIDriver *spip) { * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored + * + * @api */ void spiIgnore(SPIDriver *spip, size_t n) { @@ -176,6 +190,8 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @param[in] n number of words to be exchanged * @param[in] txbuf the pointer to the transmit buffer * @param[out] rxbuf the pointer to the receive buffer + * + * @api */ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { @@ -196,6 +212,8 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to send * @param[in] txbuf the pointer to the transmit buffer + * + * @api */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { @@ -216,6 +234,8 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer + * + * @api */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { @@ -233,11 +253,12 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { * @brief Gains exclusive access to the SPI bus. * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] spip pointer to the @p SPIDriver object * + * @api */ void spiAcquireBus(SPIDriver *spip) { @@ -252,10 +273,12 @@ void spiAcquireBus(SPIDriver *spip) { /** * @brief Releases exclusive access to the SPI bus. - * @note This function is only available when the @p SPI_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p SPI_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] spip pointer to the @p SPIDriver object + * + * @api */ void spiReleaseBus(SPIDriver *spip) { -- cgit v1.2.3 From 70ab312f0f88f24cf1e4f33218cff877c6c0b3c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Oct 2010 15:14:49 +0000 Subject: New SPI driver model (callback based), not complete yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2242 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 96 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 24 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 85cb941e6..cd5857aa9 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -129,11 +129,10 @@ void spiSelect(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), + (spip->spd_state == SPI_SELECTED), "spiSelect(), #1", "not idle"); - spi_lld_select(spip); - spip->spd_state = SPI_ACTIVE; + spiSelectI(spip); chSysUnlock(); } @@ -151,19 +150,48 @@ void spiUnselect(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_ACTIVE), + (spip->spd_state == SPI_SELECTED), "spiUnselect(), #1", "not locked"); - spi_lld_unselect(spip); - spip->spd_state = SPI_READY; + spiUnselectI(spip); + chSysUnlock(); +} + +/** + * @brief Emits a train of clock pulses on the SPI bus. + * @details This asynchronous function starts the emission of a train of + * clock pulses without asserting any slave, while this is not + * usually required by the SPI protocol it is required by + * initialization procedure of MMC/SD cards in SPI mode. + * @post At the end of the operation the configured callback is invoked. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be clocked. The number of pulses + * is equal to the number of words multiplied to the + * configured word size in bits. + * + * @api + */ +void spiSynchronize(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSynchronize(), #1", + "not ready"); + + spiSynchronizeI(spip, n); chSysUnlock(); } /** * @brief Ignores data on the SPI bus. - * @details This function transmits a series of idle words on the SPI bus and - * ignores the received data. This function can be invoked even - * when a slave select signal has not been yet asserted. + * @details This asynchronous function starts the transmission of a series of + * idle words on the SPI bus and ignores the received data. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored @@ -173,16 +201,22 @@ void spiUnselect(SPIDriver *spip) { void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); - chDbgAssert((spip->spd_state == SPI_READY) || (spip->spd_state == SPI_ACTIVE), - "spiIgnore(), #1", - "not active"); - spi_lld_ignore(spip, n); + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiIgnore(), #1", + "not selected"); + spiIgnoreI(spip, n); + chSysUnlock(); } /** * @brief Exchanges data on the SPI bus. - * @details This function performs a simultaneous transmit/receive operation. + * @details This asynchronous function starts a simultaneous transmit/receive + * operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -197,15 +231,21 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), "spiExchange"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiExchange(), #1", "not active"); - - spi_lld_exchange(spip, n, txbuf, rxbuf); + spiExchangeI(spip, n, txbuf, rxbuf); + chSysUnlock(); } /** - * @brief Sends data ever the SPI bus. + * @brief Sends data over the SPI bus. + * @details This asynchronous function starts a transmit operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -219,15 +259,21 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), "spiSend"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiSend(), #1", "not active"); - - spi_lld_send(spip, n, txbuf); + spiSendI(spip, n, txbuf); + chSysUnlock(); } /** * @brief Receives data from the SPI bus. + * @details This asynchronous function starts a receive operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @post At the end of the operation the configured callback is invoked. * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -241,11 +287,13 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), "spiReceive"); - chDbgAssert(spip->spd_state == SPI_ACTIVE, + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, "spiReceive(), #1", "not active"); - - spi_lld_receive(spip, n, rxbuf); + spiReceiveI(spip, n, rxbuf); + chSysUnlock(); } #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From 1c9c40543009ecd95b56362e6564d26a2755b92a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Oct 2010 16:28:34 +0000 Subject: Fixed bug 3084764. More enhancements to the SPI driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2244 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index cd5857aa9..75589c736 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -66,11 +66,16 @@ void spiInit(void) { void spiObjectInit(SPIDriver *spip) { spip->spd_state = SPI_STOP; +#if SPI_USE_WAIT + spip->spd_thread = NULL; +#endif /* SPI_USE_WAIT */ +#if SPI_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES chMtxInit(&spip->spd_mutex); -#elif CH_USE_SEMAPHORES +#else chSemInit(&spip->spd_semaphore, 1); #endif +#endif /* SPI_USE_MUTUAL_EXCLUSION */ spip->spd_config = NULL; } @@ -296,6 +301,64 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chSysUnlock(); } +#if SPI_USE_WAIT || defined(__DOXYGEN__) +/** + * @brief Awakens the thread waiting for operation completion, if any. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @notapi + */ +void _spi_wakeup(SPIDriver *spip) { + + if (spip->spd_thread != NULL) { + Thread *tp = spip->spd_thread; + spip->spd_thread = NULL; + tp->p_u.rdymsg = RDY_RESET; + chSchReadyI(tp); + } +} + +/** + * @brief Wait for operation completion. + * @details This function waits for the driver to complete the current + * operation, if an operation is not running when the function is + * invoked then it immediately returns. + * @note No more than one thread can wait on a SPI driver using + * this function. + * + * @param[in] spip pointer to the @p SPIDriver object + * @return The wait status. + * @retval RDY_OK There was not operation running when the function + * has been invoked. + * @retval RDY_RESET The operation completed. + */ +msg_t spiWait(SPIDriver *spip) { + msg_t msg; + + chDbgCheck(spip != NULL, "spiWait"); + + chSysLock(); + chDbgAssert((spip->spd_state == SPI_READY) || + (spip->spd_state == SPI_SELECTED) || + (spip->spd_state == SPI_ACTIVE) || + (spip->spd_state == SPI_SYNC), + "spiUnselect(), #1", + "invalid state"); + chDbgAssert(spip->spd_thread == NULL, "spiWait(), #3", "already waiting"); + if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) { + spip->spd_thread = chThdSelf(); + chSchGoSleepS(spip->spd_thread, THD_STATE_SUSPENDED); + msg = chThdSelf()->p_u.rdymsg; + } + else + msg = RDY_OK; + chSysUnlock(); + return msg; +} + +#endif /* SPI_USE_WAIT */ + #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the SPI bus. -- cgit v1.2.3 From 7c2a8e13d969029fb675e67c57349c1deaa09284 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Oct 2010 11:48:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2246 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 220 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 177 insertions(+), 43 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 75589c736..414eb61db 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -77,6 +77,10 @@ void spiObjectInit(SPIDriver *spip) { #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ spip->spd_config = NULL; + /* Optional, user-defined initializer.*/ +#if defined(SPI_DRIVER_EXT_INIT_HOOK) + SPI_DRIVER_EXT_INIT_HOOK(spip); +#endif } /** @@ -165,9 +169,10 @@ void spiUnselect(SPIDriver *spip) { /** * @brief Emits a train of clock pulses on the SPI bus. * @details This asynchronous function starts the emission of a train of - * clock pulses without asserting any slave, while this is not - * usually required by the SPI protocol it is required by - * initialization procedure of MMC/SD cards in SPI mode. + * clock pulses without asserting any slave. + * @note This functionality is not usually required by the SPI protocol + * but it is required by initialization procedure of MMC/SD cards + * in SPI mode. * @post At the end of the operation the configured callback is invoked. * * @param[in] spip pointer to the @p SPIDriver object @@ -179,13 +184,12 @@ void spiUnselect(SPIDriver *spip) { */ void spiSynchronize(SPIDriver *spip, size_t n) { - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgCheck((spip != NULL) && (n > 0), "spiSynchronize"); chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, "spiSynchronize(), #1", "not ready"); - spiSynchronizeI(spip, n); chSysUnlock(); } @@ -240,7 +244,7 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiExchange(), #1", - "not active"); + "not selected"); spiExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -268,7 +272,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiSend(), #1", - "not active"); + "not selected"); spiSendI(spip, n, txbuf); chSysUnlock(); } @@ -296,45 +300,28 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chSysLock(); chDbgAssert(spip->spd_state == SPI_SELECTED, "spiReceive(), #1", - "not active"); + "not selected"); spiReceiveI(spip, n, rxbuf); chSysUnlock(); } #if SPI_USE_WAIT || defined(__DOXYGEN__) /** - * @brief Awakens the thread waiting for operation completion, if any. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @notapi - */ -void _spi_wakeup(SPIDriver *spip) { - - if (spip->spd_thread != NULL) { - Thread *tp = spip->spd_thread; - spip->spd_thread = NULL; - tp->p_u.rdymsg = RDY_RESET; - chSchReadyI(tp); - } -} - -/** - * @brief Wait for operation completion. + * @brief Waits for operation completion. * @details This function waits for the driver to complete the current * operation, if an operation is not running when the function is * invoked then it immediately returns. + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post On exit the SPI driver is ready to accept more commands. * @note No more than one thread can wait on a SPI driver using * this function. - * + * * @param[in] spip pointer to the @p SPIDriver object - * @return The wait status. - * @retval RDY_OK There was not operation running when the function - * has been invoked. - * @retval RDY_RESET The operation completed. + * + * @api */ -msg_t spiWait(SPIDriver *spip) { - msg_t msg; +void spiWait(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiWait"); @@ -343,20 +330,167 @@ msg_t spiWait(SPIDriver *spip) { (spip->spd_state == SPI_SELECTED) || (spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC), - "spiUnselect(), #1", + "spiWait(), #1", "invalid state"); - chDbgAssert(spip->spd_thread == NULL, "spiWait(), #3", "already waiting"); - if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) { - spip->spd_thread = chThdSelf(); - chSchGoSleepS(spip->spd_thread, THD_STATE_SUSPENDED); - msg = chThdSelf()->p_u.rdymsg; - } - else - msg = RDY_OK; + if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Emits a train of clock pulses on the SPI bus. + * @details This synchronous function performs the emission of a train of + * clock pulses without asserting any slave. + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @note This functionality is not usually required by the SPI protocol + * but it is required by initialization procedure of MMC/SD cards + * in SPI mode. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be clocked. The number of pulses + * is equal to the number of words multiplied to the + * configured word size in bits. + * + * @api + */ +void spiSynchronizeWait(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiSynchronizeWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSynchronizeWait(), #1", + "not ready"); + spiSynchronizeI(spip, n); + spiWaitS(spip); chSysUnlock(); - return msg; } +/** + * @brief Ignores data on the SPI bus. + * @details This synchronous function performs the transmission of a series of + * idle words on the SPI bus and ignores the received data. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + * + * @api + */ +void spiIgnoreWait(SPIDriver *spip, size_t n) { + + chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiIgnoreWait(), #1", + "not selected"); + spiIgnoreI(spip, n); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This synchronous function performs a simultaneous transmit/receive + * operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be exchanged + * @param[in] txbuf the pointer to the transmit buffer + * @param[out] rxbuf the pointer to the receive buffer + * + * @api + */ +void spiExchangeWait(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), + "spiExchangeWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiExchangeWait(), #1", + "not selected"); + spiExchangeI(spip, n, txbuf, rxbuf); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Sends data over the SPI bus. + * @details This synchronous function performs a transmit operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + * @api + */ +void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), + "spiSendWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiSendWait(), #1", + "not selected"); + spiSendI(spip, n, txbuf); + spiWaitS(spip); + chSysUnlock(); +} + +/** + * @brief Receives data from the SPI bus. + * @details This synchronous function performs a receive operation. + * @pre A slave must have been selected using @p spiSelect() or + * @p spiSelectI(). + * @pre In order to use this function the option @p SPI_USE_WAIT must be + * enabled. + * @post At the end of the operation the configured callback is invoked. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * + * @api + */ +void spiReceiveWait(SPIDriver *spip, size_t n, void *rxbuf) { + + chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), + "spiReceiveWait"); + + chSysLock(); + chDbgAssert(spip->spd_state == SPI_SELECTED, + "spiReceiveWait(), #1", + "not selected"); + spiReceiveI(spip, n, rxbuf); + spiWaitS(spip); + chSysUnlock(); +} #endif /* SPI_USE_WAIT */ #if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From 935e2fb27f56a3b81d4161d65e116e9da4fe441c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 12 Oct 2010 15:19:15 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2250 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 234 ++++++++++++++++--------------------------------------- 1 file changed, 67 insertions(+), 167 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 414eb61db..fe7b729bd 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -66,6 +66,7 @@ void spiInit(void) { void spiObjectInit(SPIDriver *spip) { spip->spd_state = SPI_STOP; + spip->spd_config = NULL; #if SPI_USE_WAIT spip->spd_thread = NULL; #endif /* SPI_USE_WAIT */ @@ -76,8 +77,6 @@ void spiObjectInit(SPIDriver *spip) { chSemInit(&spip->spd_semaphore, 1); #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ - spip->spd_config = NULL; - /* Optional, user-defined initializer.*/ #if defined(SPI_DRIVER_EXT_INIT_HOOK) SPI_DRIVER_EXT_INIT_HOOK(spip); #endif @@ -97,8 +96,7 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStart(), #1", - "invalid state"); + "spiStart(), #1", "invalid state"); spip->spd_config = config; spi_lld_start(spip); spip->spd_state = SPI_READY; @@ -118,8 +116,7 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), - "spiStop(), #1", - "invalid state"); + "spiStop(), #1", "invalid state"); spi_lld_stop(spip); spip->spd_state = SPI_STOP; chSysUnlock(); @@ -137,10 +134,8 @@ void spiSelect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiSelect"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED), - "spiSelect(), #1", - "not idle"); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSelect(), #1", "not ready"); spiSelectI(spip); chSysUnlock(); } @@ -157,40 +152,10 @@ void spiUnselect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiUnselect"); - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED), - "spiUnselect(), #1", - "not locked"); - spiUnselectI(spip); - chSysUnlock(); -} - -/** - * @brief Emits a train of clock pulses on the SPI bus. - * @details This asynchronous function starts the emission of a train of - * clock pulses without asserting any slave. - * @note This functionality is not usually required by the SPI protocol - * but it is required by initialization procedure of MMC/SD cards - * in SPI mode. - * @post At the end of the operation the configured callback is invoked. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be clocked. The number of pulses - * is equal to the number of words multiplied to the - * configured word size in bits. - * - * @api - */ -void spiSynchronize(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiSynchronize"); - chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, - "spiSynchronize(), #1", - "not ready"); - spiSynchronizeI(spip, n); + "spiUnselect(), #1", "not ready"); + spiUnselectI(spip); chSysUnlock(); } @@ -207,15 +172,14 @@ void spiSynchronize(SPIDriver *spip, size_t n) { * * @api */ -void spiIgnore(SPIDriver *spip, size_t n) { +void spiStartIgnore(SPIDriver *spip, size_t n) { - chDbgCheck((spip != NULL) && (n > 0), "spiIgnore"); + chDbgCheck((spip != NULL) && (n > 0), "spiStartIgnore"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiIgnore(), #1", - "not selected"); - spiIgnoreI(spip, n); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartIgnore(), #1", "not ready"); + spiStartIgnoreI(spip, n); chSysUnlock(); } @@ -236,16 +200,16 @@ void spiIgnore(SPIDriver *spip, size_t n) { * * @api */ -void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { +void spiStartExchange(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchange"); + "spiStartExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiExchange(), #1", - "not selected"); - spiExchangeI(spip, n, txbuf, rxbuf); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartExchange(), #1", "not ready"); + spiStartExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -264,16 +228,15 @@ void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { * * @api */ -void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { +void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); + "spiStartSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiSend(), #1", - "not selected"); - spiSendI(spip, n, txbuf); + chDbgAssert(spip->spd_state == SPI_READY, + "spiStartSend(), #1", "not ready"); + spiStartSendI(spip, n, txbuf); chSysUnlock(); } @@ -292,107 +255,44 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * * @api */ -void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { +void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceive"); - - chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiReceive(), #1", - "not selected"); - spiReceiveI(spip, n, rxbuf); - chSysUnlock(); -} - -#if SPI_USE_WAIT || defined(__DOXYGEN__) -/** - * @brief Waits for operation completion. - * @details This function waits for the driver to complete the current - * operation, if an operation is not running when the function is - * invoked then it immediately returns. - * @pre In order to use this function the option @p SPI_USE_WAIT must be - * enabled. - * @post On exit the SPI driver is ready to accept more commands. - * @note No more than one thread can wait on a SPI driver using - * this function. - * - * @param[in] spip pointer to the @p SPIDriver object - * - * @api - */ -void spiWait(SPIDriver *spip) { - - chDbgCheck(spip != NULL, "spiWait"); - - chSysLock(); - chDbgAssert((spip->spd_state == SPI_READY) || - (spip->spd_state == SPI_SELECTED) || - (spip->spd_state == SPI_ACTIVE) || - (spip->spd_state == SPI_SYNC), - "spiWait(), #1", - "invalid state"); - if ((spip->spd_state == SPI_ACTIVE) || (spip->spd_state == SPI_SYNC)) - spiWaitS(spip); - chSysUnlock(); -} - -/** - * @brief Emits a train of clock pulses on the SPI bus. - * @details This synchronous function performs the emission of a train of - * clock pulses without asserting any slave. - * @pre In order to use this function the option @p SPI_USE_WAIT must be - * enabled. - * @post At the end of the operation the configured callback is invoked. - * @note This functionality is not usually required by the SPI protocol - * but it is required by initialization procedure of MMC/SD cards - * in SPI mode. - * - * @param[in] spip pointer to the @p SPIDriver object - * @param[in] n number of words to be clocked. The number of pulses - * is equal to the number of words multiplied to the - * configured word size in bits. - * - * @api - */ -void spiSynchronizeWait(SPIDriver *spip, size_t n) { - - chDbgCheck((spip != NULL) && (n > 0), "spiSynchronizeWait"); + "spiStartReceive"); chSysLock(); chDbgAssert(spip->spd_state == SPI_READY, - "spiSynchronizeWait(), #1", - "not ready"); - spiSynchronizeI(spip, n); - spiWaitS(spip); + "spiStartReceive(), #1", "not ready"); + spiStartReceiveI(spip, n, rxbuf); chSysUnlock(); } +#if SPI_USE_WAIT || defined(__DOXYGEN__) /** * @brief Ignores data on the SPI bus. * @details This synchronous function performs the transmission of a series of * idle words on the SPI bus and ignores the received data. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @p NULL). * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored * * @api */ -void spiIgnoreWait(SPIDriver *spip, size_t n) { +void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiIgnoreWait(), #1", - "not selected"); - spiIgnoreI(spip, n); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiIgnore(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiIgnore(), #2", "has callback"); + spiStartIgnoreI(spip, n); + _spi_wait(spip); chSysUnlock(); } @@ -400,11 +300,10 @@ void spiIgnoreWait(SPIDriver *spip, size_t n) { * @brief Exchanges data on the SPI bus. * @details This synchronous function performs a simultaneous transmit/receive * operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -415,29 +314,29 @@ void spiIgnoreWait(SPIDriver *spip, size_t n) { * * @api */ -void spiExchangeWait(SPIDriver *spip, size_t n, +void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), - "spiExchangeWait"); + "spiExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiExchangeWait(), #1", - "not selected"); - spiExchangeI(spip, n, txbuf, rxbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiExchange(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiExchange(), #2", "has callback"); + spiStartExchangeI(spip, n, txbuf, rxbuf); + _spi_wait(spip); chSysUnlock(); } /** * @brief Sends data over the SPI bus. * @details This synchronous function performs a transmit operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -447,28 +346,28 @@ void spiExchangeWait(SPIDriver *spip, size_t n, * * @api */ -void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { +void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSendWait"); + "spiSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiSendWait(), #1", - "not selected"); - spiSendI(spip, n, txbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiSend(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiSend(), #2", "has callback"); + spiStartSendI(spip, n, txbuf); + _spi_wait(spip); chSysUnlock(); } /** * @brief Receives data from the SPI bus. * @details This synchronous function performs a receive operation. - * @pre A slave must have been selected using @p spiSelect() or - * @p spiSelectI(). * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. - * @post At the end of the operation the configured callback is invoked. + * @pre In order to use this function the driver must have been configured + * without callbacks (@p spc_endcb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -478,17 +377,18 @@ void spiSendWait(SPIDriver *spip, size_t n, const void *txbuf) { * * @api */ -void spiReceiveWait(SPIDriver *spip, size_t n, void *rxbuf) { +void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), - "spiReceiveWait"); + "spiReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_SELECTED, - "spiReceiveWait(), #1", - "not selected"); - spiReceiveI(spip, n, rxbuf); - spiWaitS(spip); + chDbgAssert(spip->spd_state == SPI_READY, + "spiReceive(), #1", "not ready"); + chDbgAssert(spip->spd_config->spc_endcb == NULL, + "spiReceive(), #2", "has callback"); + spiStartReceiveI(spip, n, rxbuf); + _spi_wait(spip); chSysUnlock(); } #endif /* SPI_USE_WAIT */ -- cgit v1.2.3 From 4fab7c06d1b0c9e61f6106b5b2a5c2c0b5694c34 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 13 Oct 2010 11:45:07 +0000 Subject: ADC, SPI, PWM driver enhancements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index fe7b729bd..be5cf9452 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -105,6 +105,8 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { /** * @brief Deactivates the SPI peripheral. + * @note Deactivating the peripheral also enforces a release of the slave + * select line. * * @param[in] spip pointer to the @p SPIDriver object * @@ -117,6 +119,7 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), "spiStop(), #1", "invalid state"); + spi_lld_unselect(spip); spi_lld_stop(spip); spip->spd_state = SPI_STOP; chSysUnlock(); -- cgit v1.2.3 From d8be44136c1e6d02ee105ac0791f9e6732551fec Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 1 Nov 2010 17:29:56 +0000 Subject: Fixed bug 3100946, renamed HAL switches removing the CH_ part. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2326 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index be5cf9452..4d9749962 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_SPI || defined(__DOXYGEN__) +#if HAL_USE_SPI || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -441,6 +441,6 @@ void spiReleaseBus(SPIDriver *spip) { } #endif /* SPI_USE_MUTUAL_EXCLUSION */ -#endif /* CH_HAL_USE_SPI */ +#endif /* HAL_USE_SPI */ /** @} */ -- cgit v1.2.3 From c852dcb3c960198f49c5fdd8619a6d5d581d9136 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 25 Nov 2010 18:32:45 +0000 Subject: Improved ADC and SPI driver models. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2426 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 4d9749962..d1102cc6e 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -295,7 +295,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiIgnore(), #2", "has callback"); spiStartIgnoreI(spip, n); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -329,7 +329,7 @@ void spiExchange(SPIDriver *spip, size_t n, chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiExchange(), #2", "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -360,7 +360,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiSend(), #2", "has callback"); spiStartSendI(spip, n, txbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -391,7 +391,7 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } #endif /* SPI_USE_WAIT */ -- cgit v1.2.3 From 7aa43aee7029b232c558174bcbdf90e8fbebd57b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Dec 2010 08:31:56 +0000 Subject: Documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2490 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index d1102cc6e..966db3de5 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -48,6 +48,8 @@ /** * @brief SPI Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ -- cgit v1.2.3 From 24cb881726f09c6bccba471b40bde76dc27036c7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 4 Jan 2011 15:08:29 +0000 Subject: Documentation related fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2580 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 966db3de5..e99126b9e 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -61,7 +61,7 @@ void spiInit(void) { /** * @brief Initializes the standard part of a @p SPIDriver structure. * - * @param[in] spip pointer to the @p SPIDriver object + * @param[out] spip pointer to the @p SPIDriver object * * @init */ -- cgit v1.2.3 From 18fb8f676f0f650d83f69bc29ab45b04b73e86c1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Mar 2011 10:09:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2808 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 77 +++++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 45 deletions(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index e99126b9e..686006e0d 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -67,16 +67,16 @@ void spiInit(void) { */ void spiObjectInit(SPIDriver *spip) { - spip->spd_state = SPI_STOP; - spip->spd_config = NULL; + spip->state = SPI_STOP; + spip->config = NULL; #if SPI_USE_WAIT - spip->spd_thread = NULL; + spip->thread = NULL; #endif /* SPI_USE_WAIT */ #if SPI_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES - chMtxInit(&spip->spd_mutex); + chMtxInit(&spip->mutex); #else - chSemInit(&spip->spd_semaphore, 1); + chSemInit(&spip->semaphore, 1); #endif #endif /* SPI_USE_MUTUAL_EXCLUSION */ #if defined(SPI_DRIVER_EXT_INIT_HOOK) @@ -97,11 +97,11 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) { chDbgCheck((spip != NULL) && (config != NULL), "spiStart"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStart(), #1", "invalid state"); - spip->spd_config = config; + spip->config = config; spi_lld_start(spip); - spip->spd_state = SPI_READY; + spip->state = SPI_READY; chSysUnlock(); } @@ -119,11 +119,11 @@ void spiStop(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiStop"); chSysLock(); - chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY), + chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStop(), #1", "invalid state"); spi_lld_unselect(spip); spi_lld_stop(spip); - spip->spd_state = SPI_STOP; + spip->state = SPI_STOP; chSysUnlock(); } @@ -139,8 +139,7 @@ void spiSelect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiSelect"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiSelect(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiSelect(), #1", "not ready"); spiSelectI(spip); chSysUnlock(); } @@ -158,8 +157,7 @@ void spiUnselect(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiUnselect"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiUnselect(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiUnselect(), #1", "not ready"); spiUnselectI(spip); chSysUnlock(); } @@ -182,8 +180,7 @@ void spiStartIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiStartIgnore"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartIgnore(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartIgnore(), #1", "not ready"); spiStartIgnoreI(spip, n); chSysUnlock(); } @@ -212,8 +209,7 @@ void spiStartExchange(SPIDriver *spip, size_t n, "spiStartExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartExchange(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartExchange(), #1", "not ready"); spiStartExchangeI(spip, n, txbuf, rxbuf); chSysUnlock(); } @@ -239,8 +235,7 @@ void spiStartSend(SPIDriver *spip, size_t n, const void *txbuf) { "spiStartSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartSend(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartSend(), #1", "not ready"); spiStartSendI(spip, n, txbuf); chSysUnlock(); } @@ -266,8 +261,7 @@ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { "spiStartReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiStartReceive(), #1", "not ready"); + chDbgAssert(spip->state == SPI_READY, "spiStartReceive(), #1", "not ready"); spiStartReceiveI(spip, n, rxbuf); chSysUnlock(); } @@ -280,7 +274,7 @@ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. * @pre In order to use this function the driver must have been configured - * without callbacks (@p spc_endcb = @p NULL). + * without callbacks (@p end_cb = @p NULL). * * @param[in] spip pointer to the @p SPIDriver object * @param[in] n number of words to be ignored @@ -292,10 +286,8 @@ void spiIgnore(SPIDriver *spip, size_t n) { chDbgCheck((spip != NULL) && (n > 0), "spiIgnoreWait"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiIgnore(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, - "spiIgnore(), #2", "has callback"); + chDbgAssert(spip->state == SPI_READY, "spiIgnore(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiIgnore(), #2", "has callback"); spiStartIgnoreI(spip, n); _spi_wait_s(spip); chSysUnlock(); @@ -308,7 +300,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. * @pre In order to use this function the driver must have been configured - * without callbacks (@p spc_endcb = @p NULL). + * without callbacks (@p end_cb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -326,9 +318,8 @@ void spiExchange(SPIDriver *spip, size_t n, "spiExchange"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiExchange(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, + chDbgAssert(spip->state == SPI_READY, "spiExchange(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiExchange(), #2", "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); _spi_wait_s(spip); @@ -341,7 +332,7 @@ void spiExchange(SPIDriver *spip, size_t n, * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. * @pre In order to use this function the driver must have been configured - * without callbacks (@p spc_endcb = @p NULL). + * without callbacks (@p end_cb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -353,14 +344,11 @@ void spiExchange(SPIDriver *spip, size_t n, */ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { - chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), - "spiSend"); + chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL), "spiSend"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiSend(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, - "spiSend(), #2", "has callback"); + chDbgAssert(spip->state == SPI_READY, "spiSend(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiSend(), #2", "has callback"); spiStartSendI(spip, n, txbuf); _spi_wait_s(spip); chSysUnlock(); @@ -372,7 +360,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { * @pre In order to use this function the option @p SPI_USE_WAIT must be * enabled. * @pre In order to use this function the driver must have been configured - * without callbacks (@p spc_endcb = @p NULL). + * without callbacks (@p end_cb = @p NULL). * @note The buffers are organized as uint8_t arrays for data sizes below * or equal to 8 bits else it is organized as uint16_t arrays. * @@ -388,9 +376,8 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { "spiReceive"); chSysLock(); - chDbgAssert(spip->spd_state == SPI_READY, - "spiReceive(), #1", "not ready"); - chDbgAssert(spip->spd_config->spc_endcb == NULL, + chDbgAssert(spip->state == SPI_READY, "spiReceive(), #1", "not ready"); + chDbgAssert(spip->config->end_cb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); _spi_wait_s(spip); @@ -415,9 +402,9 @@ void spiAcquireBus(SPIDriver *spip) { chDbgCheck(spip != NULL, "spiAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&spip->spd_mutex); + chMtxLock(&spip->mutex); #elif CH_USE_SEMAPHORES - chSemWait(&spip->spd_semaphore); + chSemWait(&spip->semaphore); #endif } @@ -438,7 +425,7 @@ void spiReleaseBus(SPIDriver *spip) { (void)spip; chMtxUnlock(); #elif CH_USE_SEMAPHORES - chSemSignal(&spip->spd_semaphore); + chSemSignal(&spip->semaphore); #endif } #endif /* SPI_USE_MUTUAL_EXCLUSION */ -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 686006e0d..aaf0115eb 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From fe0093f795b6c88db8f12e2f7e45e11355fc3340 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 26 Aug 2011 13:47:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index aaf0115eb..b91b44507 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -31,6 +31,10 @@ #if HAL_USE_SPI || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index b91b44507..3817143c8 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 5649879b0ae63a5623a41bfcc43705002de36cd3 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 12 Nov 2012 10:21:48 +0000 Subject: White space formatting. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4818 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 3817143c8..d1d97f2e9 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -317,7 +317,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { * @api */ void spiExchange(SPIDriver *spip, size_t n, - const void *txbuf, void *rxbuf) { + const void *txbuf, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL) && (txbuf != NULL), "spiExchange"); -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index d1d97f2e9..807db3f3b 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 01f971ba1d63d8568789adf51cde22fb35f69e73 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Feb 2013 16:23:19 +0000 Subject: Adjusted C file templates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5339 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 807db3f3b..b4eccb0af 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -40,7 +40,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ -- cgit v1.2.3 From e9edd478029209ba06f09a380590e4ae3e844985 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 28 May 2013 14:12:55 +0000 Subject: SPC5xx DSPI driver working on SPC563Mxx. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5766 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/spi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src/spi.c') diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index b4eccb0af..2dc0cc6ee 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -126,7 +126,6 @@ void spiStop(SPIDriver *spip) { chSysLock(); chDbgAssert((spip->state == SPI_STOP) || (spip->state == SPI_READY), "spiStop(), #1", "invalid state"); - spi_lld_unselect(spip); spi_lld_stop(spip); spip->state = SPI_STOP; chSysUnlock(); -- cgit v1.2.3