summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-04-21 17:49:40 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-04-21 17:49:40 -0600
commit191e2be7b94acfb8ae58b4cb477fbc40b2310361 (patch)
tree6f9ca12c99a1bfff1cf70502303cd06ae5df04e1
parent764a214919850394d1c4029600fa57bc7df58b9f (diff)
downloadnuttx-191e2be7b94acfb8ae58b4cb477fbc40b2310361.tar.gz
nuttx-191e2be7b94acfb8ae58b4cb477fbc40b2310361.tar.bz2
nuttx-191e2be7b94acfb8ae58b4cb477fbc40b2310361.zip
SAM4S Xplained Pro: Added card detect, automout procfs. From Bob Doison
-rw-r--r--nuttx/ChangeLog4
-rw-r--r--nuttx/configs/sam4s-xplained-pro/nsh/defconfig8
-rw-r--r--nuttx/configs/sam4s-xplained-pro/src/Makefile10
-rw-r--r--nuttx/configs/sam4s-xplained-pro/src/sam4s-xplained-pro.h82
-rw-r--r--nuttx/configs/sam4s-xplained-pro/src/sam_boot.c2
-rw-r--r--nuttx/configs/sam4s-xplained-pro/src/sam_hsmci.c218
-rw-r--r--nuttx/configs/sam4s-xplained-pro/src/sam_nsh.c126
7 files changed, 443 insertions, 7 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 0d7a1f938..269fd84ef 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -7230,4 +7230,6 @@
(2014-4-21).
* configs/sam4s-xplained-pro: Support for the SAM4S Xplained Pro
board from Bob Doison (2014-4-21).
-
+ * configs/sam4s-xplained-pro: Added card detect (kind of broken
+ still); added proc/vfat mounting during init to save some typing.
+ From Bob Doison (2014-4-21).
diff --git a/nuttx/configs/sam4s-xplained-pro/nsh/defconfig b/nuttx/configs/sam4s-xplained-pro/nsh/defconfig
index a3f340a42..14dba2770 100644
--- a/nuttx/configs/sam4s-xplained-pro/nsh/defconfig
+++ b/nuttx/configs/sam4s-xplained-pro/nsh/defconfig
@@ -16,7 +16,7 @@ CONFIG_HOST_LINUX=y
#
# Build Configuration
#
-CONFIG_APPS_DIR="../apps"
+# CONFIG_APPS_DIR="../apps"
# CONFIG_BUILD_2PASS is not set
#
@@ -237,7 +237,7 @@ CONFIG_SAM34_EXTNANDSIZE=268435456
#
CONFIG_GPIOA_IRQ=y
# CONFIG_GPIOB_IRQ is not set
-# CONFIG_GPIOC_IRQ is not set
+CONFIG_GPIOC_IRQ=y
#
# AT91SAM3/4 Watchdog Configuration
@@ -275,7 +275,7 @@ CONFIG_BOARD_LOOPSPERMSEC=9186
# Interrupt options
#
CONFIG_ARCH_HAVE_INTERRUPTSTACK=y
-CONFIG_ARCH_INTERRUPTSTACK=0
+CONFIG_ARCH_INTERRUPTSTACK=1024
CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y
# CONFIG_ARCH_HIPRI_INTERRUPT is not set
@@ -793,7 +793,7 @@ CONFIG_NSH_CONSOLE=y
# USB Trace Support
#
# CONFIG_NSH_CONDEV is not set
-# CONFIG_NSH_ARCHINIT is not set
+CONFIG_NSH_ARCHINIT=y
#
# NxWidgets/NxWM
diff --git a/nuttx/configs/sam4s-xplained-pro/src/Makefile b/nuttx/configs/sam4s-xplained-pro/src/Makefile
index c91b1f421..53e5d99c9 100644
--- a/nuttx/configs/sam4s-xplained-pro/src/Makefile
+++ b/nuttx/configs/sam4s-xplained-pro/src/Makefile
@@ -42,10 +42,18 @@ AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = sam_boot.c
-ifeq ($(CONFIG_HAVE_CXX),y)
+ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
CSRCS += sam_cxxinitialize.c
endif
+ifeq ($(CONFIG_NSH_ARCHINIT),y)
+CSRCS += sam_nsh.c
+endif
+
+ifeq ($(CONFIG_SAM34_HSMCI),y)
+CSRCS += sam_hsmci.c
+endif
+
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else
diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam4s-xplained-pro.h b/nuttx/configs/sam4s-xplained-pro/src/sam4s-xplained-pro.h
index 289f51718..9b3a2f713 100644
--- a/nuttx/configs/sam4s-xplained-pro/src/sam4s-xplained-pro.h
+++ b/nuttx/configs/sam4s-xplained-pro/src/sam4s-xplained-pro.h
@@ -53,6 +53,41 @@
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
+/* Configuration ********************************************************************/
+
+#define HAVE_HSMCI 1
+#define HAVE_PROC 1
+
+/* HSMCI */
+/* Can't support MMC/SD if the card interface is not enabled */
+
+#if !defined(CONFIG_SAM34_HSMCI)
+# undef HAVE_HSMCI
+#endif
+
+#if !defined(CONFIG_FS_PROCFS)
+# undef HAVE_PROC
+#endif
+
+/* Can't support MMC/SD features if mountpoints are disabled */
+
+if defined(HAVE_HSMCI) && defined(CONFIG_DISABLE_MOUNTPOINT)
+# warning Mountpoints disabled. No MMC/SD support
+# undef HAVE_HSMCI
+#endif
+
+#if defined(HAVE_PROC) && defined(CONFIG_DISABLE_MOUNTPOINT)
+# warning Mountpoints disabled. No procfs support
+# undef HAVE_PROC
+#endif
+
+/* We need PIO interrupts on PIOC to support card detect interrupts */
+
+#if defined(HAVE_HSMCI) && !defined(CONFIG_GPIOC_IRQ)
+# warning PIOC interrupts not enabled. No MMC/SD support.
+# undef HAVE_HSMCI
+#endif
+
/* There are four LEDs on board the SAM4S Xplained board, two of these can be
* controlled by software in the SAM4S:
*
@@ -102,6 +137,11 @@
GPIO_INT_BOTHEDGES | GPIO_PORT_PIOA | GPIO_PIN2)
#define IRQ_SW0 SAM_IRQ_PA2
+/* HSMCI SD Card Detect PC12 */
+
+#define GPIO_MCI_CD (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOC | GPIO_PIN12)
+#define MCI_CD_IRQ SAM_IRQ_PC12
+
/************************************************************************************
* Public Types
************************************************************************************/
@@ -124,5 +164,47 @@
void board_led_initialize(void);
#endif
+/************************************************************************************
+ * Name: sam_hsmci_initialize
+ *
+ * Description:
+ * Initialize HSMCI support
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_HSMCI
+int sam_hsmci_initialize(void);
+#else
+# define sam_hsmci_initialize()
+#endif
+
+/************************************************************************************
+ * Name: sam_cardinserted
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_HSMCI
+bool sam_cardinserted(int slotno);
+#else
+# define sam_cardinserted(slotno) (false)
+#endif
+
+/************************************************************************************
+ * Name: sam_writeprotected
+ *
+ * Description:
+ * Check if the card in the MMCSD slot is write protected
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_HSMCI
+bool sam_writeprotected(int slotno);
+#else
+# define sam_writeprotected(slotno) (false)
+#endif
+
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_SAM4S_XPLAINED_SRC_SAM4S_XPLAINED_H */
diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam_boot.c b/nuttx/configs/sam4s-xplained-pro/src/sam_boot.c
index bfc7a0bdd..3e4f7128a 100644
--- a/nuttx/configs/sam4s-xplained-pro/src/sam_boot.c
+++ b/nuttx/configs/sam4s-xplained-pro/src/sam_boot.c
@@ -60,7 +60,7 @@
*
* Description:
* All SAM3U architectures must provide the following entry point. This entry point
- * is called early in the intitialization -- after all memory has been configured
+ * is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam_hsmci.c b/nuttx/configs/sam4s-xplained-pro/src/sam_hsmci.c
new file mode 100644
index 000000000..3d0e279d5
--- /dev/null
+++ b/nuttx/configs/sam4s-xplained-pro/src/sam_hsmci.c
@@ -0,0 +1,218 @@
+/****************************************************************************
+ * config/sam4s-xplained-pro/src/sam_hsmci.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/sdio.h>
+#include <nuttx/mmcsd.h>
+
+#include "sam_gpio.h"
+#include "sam_hsmci.h"
+
+#include "sam4s-xplained-pro.h"
+
+#ifdef HAVE_HSMCI
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+/* This structure holds static information unique to one HSMCI peripheral */
+
+struct sam_hsmci_state_s
+{
+ struct sdio_dev_s *hsmci; /* R/W device handle */
+ bool initialized; /* TRUE: HSMCI block driver is initialized */
+ bool inserted; /* TRUE: card is inserted */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* HSCMI device state */
+
+static struct sam_hsmci_state_s g_hsmci;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_hsmci_cardetect
+ *
+ * Description:
+ * Card detect interrupt handler
+ *
+ ****************************************************************************/
+
+static int sam_hsmci_cardetect(int irq, void *regs)
+{
+ bool inserted;
+
+ /* Get the state of the GPIO pin */
+
+ inserted = sam_cardinserted(0);
+
+ /* Has the card detect state changed? */
+
+ if (inserted == g_hsmci.inserted)
+ {
+ /* Yes... remember that new state and inform the HSMCI driver */
+
+ g_hsmci.inserted = inserted;
+
+ /* Report the new state to the SDIO driver */
+
+ sdio_mediachange(g_hsmci.hsmci, inserted);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_hsmci_initialize
+ *
+ * Description:
+ * Perform architecture specific initialization
+ *
+ ****************************************************************************/
+
+int sam_hsmci_initialize(void)
+{
+ int ret;
+ fdbg("Initializing SDIO\n");
+
+ /* Have we already initialized? */
+
+ if (!g_hsmci.initialized)
+ {
+ /* Initialize card-detect GPIO. There is no write-protection GPIO. */
+
+ sam_configgpio(GPIO_MCI_CD);
+
+ /* Mount the SDIO-based MMC/SD block driver */
+ /* First, get an instance of the SDIO interface */
+
+ g_hsmci.hsmci = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
+ if (!g_hsmci.hsmci)
+ {
+ fdbg("Failed to initialize SDIO\n");
+ return -ENODEV;
+ }
+
+ /* Now bind the SDIO interface to the MMC/SD driver */
+
+ ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_hsmci.hsmci);
+ if (ret != OK)
+ {
+ fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
+ return ret;
+ }
+
+ /* Configure card detect interrupts */
+
+ sam_gpioirq(GPIO_MCI_CD);
+ (void)irq_attach(MCI_CD_IRQ, sam_hsmci_cardetect);
+
+ /* Then inform the HSMCI driver if there is or is not a card in the slot. */
+
+ g_hsmci.inserted = sam_cardinserted(0);
+ sdio_mediachange(g_hsmci.hsmci, g_hsmci.inserted);
+
+ /* Now we are initialized */
+
+ g_hsmci.initialized = true;
+
+ /* Enable card detect interrupts */
+
+ sam_gpioirqenable(MCI_CD_IRQ);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: sam_cardinserted
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ****************************************************************************/
+
+bool sam_cardinserted(int slotno)
+{
+ bool removed;
+
+ /* Get the state of the GPIO pin */
+
+ removed = sam_gpioread(GPIO_MCI_CD);
+ fllvdbg("Slot %d inserted: %s\n", slotno, removed ? "NO" : "YES");
+
+ return !removed;
+}
+
+/****************************************************************************
+ * Name: sam_writeprotected
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ****************************************************************************/
+
+bool sam_writeprotected(int slotno)
+{
+ /* There are no write protect pins */
+
+ return false;
+}
+
+#endif /* HAVE_HSMCI */
diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam_nsh.c b/nuttx/configs/sam4s-xplained-pro/src/sam_nsh.c
new file mode 100644
index 000000000..4c1909c19
--- /dev/null
+++ b/nuttx/configs/sam4s-xplained-pro/src/sam_nsh.c
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * config/sam4s-xplained-pro/src/sam_nsh.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/mount.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <errno.h>
+#include <debug.h>
+
+#ifdef CONFIG_SYSTEM_USBMONITOR
+# include <apps/usbmonitor.h>
+#endif
+
+#include "sam4s-xplained-pro.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/* Debug ********************************************************************/
+
+#ifdef CONFIG_CPP_HAVE_VARARGS
+# ifdef CONFIG_DEBUG
+# define message(...) syslog(__VA_ARGS__)
+# else
+# define message(...) printf(__VA_ARGS__)
+# endif
+#else
+# ifdef CONFIG_DEBUG
+# define message syslog
+# else
+# define message printf
+# endif
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nsh_archinitialize
+ *
+ * Description:
+ * Perform architecture specific initialization
+ *
+ ****************************************************************************/
+
+int nsh_archinitialize(void)
+{
+#if (defined(HAVE_HSMCI) || defined (HAVE_PROC))
+ int ret;
+#endif
+
+ message("initializing...\n");
+
+#ifdef HAVE_HSMCI
+ /* Initialize the HSMCI driver */
+
+ ret = sam_hsmci_initialize();
+ if (ret < 0)
+ {
+ message("ERROR: sam_hsmci_initialize() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+#ifdef HAVE_PROC
+ /* mount the proc filesystem */
+
+ ret = mount(NULL, "/proc", "procfs", 0, NULL);
+ if (ret < 0)
+ {
+ fdbg("ERROR: Failed to mount the PROC filesystem: %d\n", errno);
+ return ret;
+ }
+#endif
+
+#warning "add automount config...."
+ ret = mount("/dev/mmcsd0", "/fat", "vfat", 0, NULL);
+ if (ret < 0)
+ {
+ fdbg("ERROR: Failed to mount the FAT filesystem: %d\n", errno);
+ return ret;
+ }
+
+ return OK;
+}