aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/spi.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-26 16:02:29 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-26 16:02:29 +0000
commita1db002da5d4bd3fdc0c7fcc0f2aa466de803d4f (patch)
treee9ff84603a24140f7afc46b6735ed120b75fb2e1 /os/io/spi.c
parent34f29ab36c7d465d397304811945a226234b9db6 (diff)
downloadChibiOS-a1db002da5d4bd3fdc0c7fcc0f2aa466de803d4f.tar.gz
ChibiOS-a1db002da5d4bd3fdc0c7fcc0f2aa466de803d4f.tar.bz2
ChibiOS-a1db002da5d4bd3fdc0c7fcc0f2aa466de803d4f.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1256 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/spi.c')
-rw-r--r--os/io/spi.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/os/io/spi.c b/os/io/spi.c
index 7c08fe413..be34c469d 100644
--- a/os/io/spi.c
+++ b/os/io/spi.c
@@ -59,6 +59,7 @@ void spiObjectInit(SPIDriver *spip) {
*/
void spiSetup(SPIDriver *spip, const SPIConfig *config) {
+ chDbgCheck((spip != NULL) && (config != NULL), "spiSetup");
chDbgAssert(spip->spd_state == SPI_IDLE,
"spiSetup(), #1",
"not idle");
@@ -74,6 +75,8 @@ void spiSetup(SPIDriver *spip, const SPIConfig *config) {
*/
void spiSelect(SPIDriver *spip) {
+ chDbgCheck(spip != NULL, "spiSelect");
+
chSysLock();
chDbgAssert(spip->spd_state == SPI_IDLE,
@@ -93,6 +96,8 @@ void spiSelect(SPIDriver *spip) {
*/
void spiUnselect(SPIDriver *spip) {
+ chDbgCheck(spip != NULL, "spiUnselect");
+
chSysLock();
chDbgAssert(spip->spd_state == SPI_ACTIVE,
@@ -121,13 +126,63 @@ void spiUnselect(SPIDriver *spip) {
* data sizes below or equal to 8 bits else it is organized as
* an uint16_t array.
*/
-void spiExchange(SPIDriver *spip, size_t n, void *rxbuf, void *txbuf) {
+msg_t spiExchange(SPIDriver *spip, size_t n, void *rxbuf, void *txbuf) {
+ 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, rxbuf, txbuf);
+ return spi_lld_exchange(spip, n, rxbuf, txbuf);
+}
+
+/**
+ * @brief Sends data ever the SPI bus.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param n number of words to send
+ * @param txbuf the pointer to the transmit buffer
+ * @return The operation status is returned.
+ * @retval RDY_OK operation complete.
+ * @retval RDY_RESET hardware failure.
+ *
+ * @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.
+ */
+msg_t spiSend(SPIDriver *spip, size_t n, void *txbuf) {
+
+ chDbgCheck((spip != NULL) && (n > 0) && (txbuf != NULL),
+ "spiSend");
+ chDbgAssert(spip->spd_state == SPI_ACTIVE,
+ "spiSend(), #1",
+ "not active");
+
+ return spi_lld_send(spip, n, txbuf);
+}
+
+/**
+ * @brief Receives data from the SPI bus.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @param n number of words to receive
+ * @param rxbuf the pointer to the receive buffer
+ * @return The operation status is returned.
+ * @retval RDY_OK operation complete.
+ * @retval RDY_RESET hardware failure.
+ *
+ * @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.
+ */
+msg_t 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");
+
+ return spi_lld_receive(spip, n, rxbuf);
}
#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
@@ -143,6 +198,8 @@ void spiExchange(SPIDriver *spip, size_t n, void *rxbuf, void *txbuf) {
*/
void spiAcquireBus(SPIDriver *spip) {
+ chDbgCheck(spip != NULL, "spiAcquireBus");
+
#if CH_USE_MUTEXES
chMtxLock(&spip->spd_mutex);
#elif CH_USE_SEMAPHORES
@@ -160,6 +217,8 @@ void spiAcquireBus(SPIDriver *spip) {
*/
void spiReleaseBus(SPIDriver *spip) {
+ chDbgCheck(spip != NULL, "spiReleaseBus");
+
#if CH_USE_MUTEXES
(void)spip;
chMtxUnlock();