summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-10-15 14:19:46 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-10-15 14:19:46 +0000
commitde69e9a67bddcb0f59cce0ca1c0d7277c854261c (patch)
treeb9501dee2adf701e8ab808f4178d7eef69cbbace /nuttx/include
parentbe95ad8513dc7c1c192ea259cdf9c0a88b526b58 (diff)
downloadpx4-nuttx-de69e9a67bddcb0f59cce0ca1c0d7277c854261c.tar.gz
px4-nuttx-de69e9a67bddcb0f59cce0ca1c0d7277c854261c.tar.bz2
px4-nuttx-de69e9a67bddcb0f59cce0ca1c0d7277c854261c.zip
Add simple SPI-based MMC/SD block driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1043 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/nuttx/mmcsd.h89
-rw-r--r--nuttx/include/nuttx/spi.h105
2 files changed, 153 insertions, 41 deletions
diff --git a/nuttx/include/nuttx/mmcsd.h b/nuttx/include/nuttx/mmcsd.h
new file mode 100644
index 000000000..ea41290c0
--- /dev/null
+++ b/nuttx/include/nuttx/mmcsd.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+ * include/nuttx/mmcsd.h
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __NUTTX_MMCSD_H
+#define __NUTTX_MMCSD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: mmcsd_spislotinitialize
+ *
+ * Description:
+ * Initialize one slot for operation using the SPI MMC/SD interface
+ *
+ * Input Parameters:
+ * minor - The MMC/SD minor device number. The MMC/SD device will be
+ * registered as /dev/mmcsdN where N is the minor number
+ * slotno - The slot number to use. This is only meaningful for architectures
+ * that support multiple MMC/SD slots. This value must be in the range
+ * {0, ..., CONFIG_MMCSD_NSLOTS}.
+ * spi - And instance of an SPI interface obtained by called
+ * up_spiinitialize() with the appropriate port number (see spi.h)
+ *
+ ****************************************************************************/
+
+EXTERN int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+#endif /* __NUTTX_MMCSD_H */
diff --git a/nuttx/include/nuttx/spi.h b/nuttx/include/nuttx/spi.h
index fbcee72e8..3fe9131c4 100644
--- a/nuttx/include/nuttx/spi.h
+++ b/nuttx/include/nuttx/spi.h
@@ -50,10 +50,10 @@
/* Access macros */
/****************************************************************************
- * Name:SPI_SELECT
+ * Name: SPI_SELECT
*
* Description:
- * Enable/disable the SPI chip select
+ * Enable/disable the SPI chip select. Required.
*
* Input Parameters:
* select: TRUE: chip selected, FALSE: chip de-selected
@@ -63,13 +63,13 @@
*
****************************************************************************/
-#define SPI_SELECT(s,b) ((s)->select(b))
+#define SPI_SELECT(d,b) ((d)->ops->select(d,b))
/****************************************************************************
* Name: SPI_SETFREQUENCY
*
* Description:
- * Set the SPI frequency.
+ * Set the SPI frequency. Required.
*
* Input Parameters:
* frequency: The SPI frequency requested
@@ -79,13 +79,13 @@
*
****************************************************************************/
-#define SPI_SETFREQUENCY(s,f) ((s)->setfrequency(f))
+#define SPI_SETFREQUENCY(d,f) ((d)->ops->setfrequency(d,f))
/****************************************************************************
* Name: SPI_STATUS
*
* Description:
- * Get SPI/MMC status
+ * Get SPI/MMC status. Optional.
*
* Input Parameters:
* None
@@ -95,13 +95,21 @@
*
****************************************************************************/
-#define SPI_STATUS(s) ((s)->status())
+#define SPI_STATUS(d) \
+ ((d)->ops->status ? (d)->ops->status(d) : SPI_STATUS_PRESENT)
+
+/* SPI status bits -- Some dedicated for SPI MMC/SD support and may have no
+ * relationship to SPI other than needed by the SPI MMC/SD interface
+ */
+
+#define SPI_STATUS_PRESENT 0x01 /* Bit 0=1: MMC/SD card present */
+#define SPI_STATUS_WRPROTECTED 0x02 /* Bit 1=1: MMC/SD card write protected */
/****************************************************************************
* Name: SPI_SNDBYTE
*
* Description:
- * Send one byte on SPI
+ * Send one byte on SPI. Required.
*
* Input Parameters:
* ch - the byte to send
@@ -111,77 +119,92 @@
*
****************************************************************************/
-#define SPI_SNDBYTE(s,ch) ((s)->sndbyte(ch))
+#define SPI_SNDBYTE(d,ch) ((d)->ops->sndbyte(d,ch))
/****************************************************************************
- * Name: SPI_WAITREADY
+ * Name: SPI_SNDBLOCK
*
* Description:
- * Wait for SPI to be ready
+ * Send a block of data on SPI. Required.
*
- * Input Parameters: None
+ * Input Parameters:
+ * buffer - A pointer to the buffer of data to be sent
+ * buflen - the length of data to send from the buffer
*
* Returned Value:
- * OK if no error occured; a negated errno otherwise.
+ * None
*
****************************************************************************/
-#define SPI_WAITREADY(s) ((s)->waitready())
+#define SPI_SNDBLOCK(d,b,l) ((d)->ops->sndblock(d,b,l))
/****************************************************************************
- * Name: SPI_SNDBLOCK
+ * Name: SPI_RECVBLOCK
*
* Description:
- * Send a block of data on SPI
+ * Revice a block of data from SPI. Required.
*
* Input Parameters:
- * data - A pointer to the buffer of data to be sent
- * datlen - the length of data to send from the buffer
+ * buffer - A pointer to the buffer in which to recieve data
+ * buflen - the length of data that can be received in the buffer
*
* Returned Value:
* None
*
****************************************************************************/
-#define SPI_SNDBLOCK(s,d,l) ((s)->sndblock(d,l))
+#define SPI_RECVBLOCK(d,b,l) ((d)->ops->recvblock(d,b,l))
/****************************************************************************
- * Name: SPI_RECVBLOCK
+ * Name: SPI_REGISTERCALLBACK
*
* Description:
- * Revice a block of data from SPI
+ * Register a callback that that will be invoked on any media status
+ * change (i.e, anything that would be reported differently by SPI_STATUS).
+ * Optional
*
* Input Parameters:
- * data - A pointer to the buffer in which to recieve data
- * datlen - the length of data that can be received in the buffer
+ * callback - The funtion to call on the media change
+ * arg - A caller provided value to return with the callback
*
* Returned Value:
- * None
+ * 0 on success; negated errno on failure.
*
****************************************************************************/
-#define SPI_RECVBLOCK(s,d,l) ((s)->recvblock(d,l))
-
-/* SPI status bits -- Some dedicated for SPI MMC support and may have not
- * relationship to SPI other than needed by the SPI MMC interface
- */
-
-#define SPI_STATUS_PRESENT 0x01 /* MMC card present */
-#define SPI_STATUS_WRPROTECTED 0x02 /* MMC card write protected */
+#define SPI_REGISTERCALLBACK(d,c,a) \
+ ((d)->ops->registercallback ? (d)->ops->registercallback(d,c,a) : -ENOSYS)
/****************************************************************************
* Public Types
****************************************************************************/
+/* The type of the media change callback function */
+
+typedef void (*mediachange_t)(void *arg);
+
+/* The SPI vtable */
+
+struct spi_dev_s;
struct spi_ops_s
{
- void (*select)(boolean select);
- uint32 (*setfrequency)(uint32 frequency);
- ubyte (*status)(void);
- void (*sndbyte)(ubyte ch);
- int (*waitready)(void);
- void (*sndblock)(FAR const ubyte *data, int datlen);
- void (*recvblock)(FAR ubyte *data, int datlen);
+ void (*select)(FAR struct spi_dev_s *dev, boolean selected);
+ uint32 (*setfrequency)(FAR struct spi_dev_s *dev, uint32 frequency);
+ ubyte (*status)(FAR struct spi_dev_s *dev);
+ ubyte (*sndbyte)(FAR struct spi_dev_s *dev, ubyte ch);
+ void (*sndblock)(FAR struct spi_dev_s *dev, FAR const ubyte *buffer, size_t buflen);
+ void (*recvblock)(FAR struct spi_dev_s *dev, FAR ubyte *buffer, size_t buflen);
+ int (*registercallback)(FAR struct spi_dev_s *dev, mediachange_t callback, void *arg);
+};
+
+/* SPI private data. This structure only defines the initial fields of the
+ * structure visible to the SPI client. The specific implementation may
+ * add additional, device specific fields
+ */
+
+struct spi_dev_s
+{
+ struct spi_ops_s *ops;
};
/****************************************************************************
@@ -206,11 +229,11 @@ extern "C" {
* Port number (for hardware that has mutiple SPI interfaces)
*
* Returned Value:
- * Valid vtable pointer on succcess; a NULL on failure
+ * Valid SPI device structre reference on succcess; a NULL on failure
*
****************************************************************************/
-EXTERN FAR const struct spi_ops_s *up_spiinitialize(int port);
+EXTERN FAR struct spi_dev_s *up_spiinitialize(int port);
#undef EXTERN
#if defined(__cplusplus)