aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/include/spi.h
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-10 15:14:49 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-10 15:14:49 +0000
commit70ab312f0f88f24cf1e4f33218cff877c6c0b3c2 (patch)
treee35baf84be66fc5285c41f68b0c519a0b6ac0db9 /os/hal/include/spi.h
parent80cf0731d8321843868b38074e19569d3ca31d99 (diff)
downloadChibiOS-70ab312f0f88f24cf1e4f33218cff877c6c0b3c2.tar.gz
ChibiOS-70ab312f0f88f24cf1e4f33218cff877c6c0b3c2.tar.bz2
ChibiOS-70ab312f0f88f24cf1e4f33218cff877c6c0b3c2.zip
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
Diffstat (limited to 'os/hal/include/spi.h')
-rw-r--r--os/hal/include/spi.h130
1 files changed, 129 insertions, 1 deletions
diff --git a/os/hal/include/spi.h b/os/hal/include/spi.h
index 7ff92a04d..b09e33089 100644
--- a/os/hal/include/spi.h
+++ b/os/hal/include/spi.h
@@ -64,7 +64,9 @@ typedef enum {
SPI_UNINIT = 0, /**< @brief Not initialized. */
SPI_STOP = 1, /**< @brief Stopped. */
SPI_READY = 2, /**< @brief Ready. */
- SPI_ACTIVE = 3 /**< @brief Slave selected. */
+ SPI_SYNC= 3, /**< @brief Synchronizing. */
+ SPI_SELECTED = 4, /**< @brief Slave selected. */
+ SPI_ACTIVE = 5 /**< @brief Exchanging data. */
} spistate_t;
#include "spi_lld.h"
@@ -73,6 +75,131 @@ typedef enum {
/* Driver macros. */
/*===========================================================================*/
+/**
+ * @brief Asserts the slave select signal and prepares for transfers.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @api
+ */
+#define spiSelectI(spip) { \
+ (spip)->spd_state = SPI_SELECTED; \
+ spi_lld_select(spip); \
+}
+
+/**
+ * @brief Deasserts the slave select signal.
+ * @details The previously selected peripheral is unselected.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ *
+ * @api
+ */
+#define spiUnselectI(spip) { \
+ (spip)->spd_state = SPI_READY; \
+ spi_lld_unselect(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.
+ * @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
+ */
+#define spiSynchronizeI(spip, n) { \
+ (spip)->spd_state = SPI_SYNC; \
+ spi_lld_ignore(spip, n); \
+}
+
+/**
+ * @brief Ignores data on the SPI bus.
+ * @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
+ *
+ * @api
+ */
+#define spiIgnoreI(spip, n) { \
+ (spip)->spd_state = SPI_ACTIVE; \
+ spi_lld_ignore(spip, n); \
+}
+
+/**
+ * @brief Exchanges data on the SPI bus.
+ * @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.
+ *
+ * @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
+ */
+#define spiExchangeI(spip, n, txbuf, rxbuf) { \
+ (spip)->spd_state = SPI_ACTIVE; \
+ spi_lld_exchange(spip, n, txbuf, rxbuf); \
+}
+
+/**
+ * @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.
+ *
+ * @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
+ */
+#define spiSendI(spip, n, txbuf) { \
+ (spip)->spd_state = SPI_ACTIVE; \
+ spi_lld_send(spip, n, txbuf); \
+}
+
+/**
+ * @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.
+ *
+ * @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
+ */
+#define spiReceiveI(spip, n, rxbuf) { \
+ (spip)->spd_state = SPI_ACTIVE; \
+ spi_lld_receive(spip, n, rxbuf); \
+}
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -86,6 +213,7 @@ extern "C" {
void spiStop(SPIDriver *spip);
void spiSelect(SPIDriver *spip);
void spiUnselect(SPIDriver *spip);
+ void spiSynchronize(SPIDriver *spip, size_t n);
void spiIgnore(SPIDriver *spip, size_t n);
void spiExchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf);
void spiSend(SPIDriver *spip, size_t n, const void *txbuf);