From d84fcb39c0ef2675298227c08b45f16be13a78cb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Jun 2013 10:56:42 -0600 Subject: Oops.. files that I forgot to add in the last commit --- nuttx/configs/sam4l-xplained/src/sam_mmcsd.c | 126 +++++++++++++++++++++++++++ nuttx/configs/sam4l-xplained/src/sam_nsh.c | 120 +++++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 nuttx/configs/sam4l-xplained/src/sam_mmcsd.c create mode 100644 nuttx/configs/sam4l-xplained/src/sam_nsh.c diff --git a/nuttx/configs/sam4l-xplained/src/sam_mmcsd.c b/nuttx/configs/sam4l-xplained/src/sam_mmcsd.c new file mode 100644 index 000000000..e922b8f9c --- /dev/null +++ b/nuttx/configs/sam4l-xplained/src/sam_mmcsd.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * config/shenzhou/src/sam_mmcsd.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include +#include + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +#ifdef CONFIG_DISABLE_MOUNTPOINT +# error Mountpoints are disabled (CONFIG_DISABLE_MOUNTPOINT=y) +#endif + +#ifndef CONFIG_SAM34_SPI +# error SPI support is required (CONFIG_SAM34_SPI) +#endif + +#ifndef CONFIG_MMCSD +# error MMC/SD support is required (CONFIG_MMCSD) +#endif + +#define SAM34_MMCSDSPIPORTNO 0 /* Port is SPI (there is only one port) */ +#define SAM34_MMCSDSLOTNO 0 /* There is only one slot */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_sdinitialize + * + * Description: + * Initialize the SPI-based SD card. Requires + * - CONFIG_SAM4L_XPLAINED_IOMODULE=y, + * - CONFIG_DISABLE_MOUNTPOINT=n, + * - CONFIG_MMCSD=y, and + * - CONFIG_SAM34_SPI=y + * + *****************************************************************************/ + +int sam_sdinitialize(int minor) +{ +#ifdef HAVE_MMCSD + FAR struct spi_dev_s *spi; + int ret; + + /* Get the SPI port */ + + fvdbg("Initializing SPI port %d\n", SAM34_MMCSDSPIPORTNO); + + spi = up_spiinitialize(SAM34_MMCSDSPIPORTNO); + if (!spi) + { + fdbg("Failed to initialize SPI port %d\n", SAM34_MMCSDSPIPORTNO); + return -ENODEV; + } + + fvdbg("Successfully initialized SPI port %d\n", SAM34_MMCSDSPIPORTNO); + + /* Bind the SPI port to the slot */ + + fvdbg("Binding SPI port %d to MMC/SD slot %d\n", + SAM34_MMCSDSPIPORTNO, SAM34_MMCSDSLOTNO); + + ret = mmcsd_spislotinitialize(minor, SAM34_MMCSDSLOTNO, spi); + if (ret < 0) + { + fdbg("Failed to bind SPI port %d to MMC/SD slot %d: %d\n", + SAM34_MMCSDSPIPORTNO, SAM34_MMCSDSLOTNO, ret); + return ret; + } + + fvdbg("Successfuly bound SPI port %d to MMC/SD slot %d\n", + SAM34_MMCSDSPIPORTNO, SAM34_MMCSDSLOTNO); +#endif + + return OK; +} + +#endif /* CONFIG_SAM4L_XPLAINED_IOMODULE */ diff --git a/nuttx/configs/sam4l-xplained/src/sam_nsh.c b/nuttx/configs/sam4l-xplained/src/sam_nsh.c new file mode 100644 index 000000000..e5c77a926 --- /dev/null +++ b/nuttx/configs/sam4l-xplained/src/sam_nsh.c @@ -0,0 +1,120 @@ +/**************************************************************************** + * config/shenzhou/src/sam_nsh.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "sam4l-xplained.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE +/* Support for the SD card slot on the I/O1 module */ +/* Verify NSH PORT and SLOT settings */ + +# define SAM34_MMCSDSPIPORTNO 0 /* Port is SPI (there is only one port) */ +# define SAM34_MMCSDSLOTNO 0 /* There is only one slot */ + +# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != SAM34_MMCSDSLOTNO +# error Only one MMC/SD slot: Slot 0 (CONFIG_NSH_MMCSDSLOTNO) +# endif + +# if defined(CONFIG_NSH_MMCSDSPIPORTNO) && CONFIG_NSH_MMCSDSPIPORTNO != SAM34_MMCSDSPIPORTNO +# error Only one MMC/SD port: Port 0 (CONFIG_NSH_MMCSDSPIPORTNO) +# endif + +/* Default MMC/SD minor number */ + +# ifndef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +# endif +#endif + +/* Debug ********************************************************************/ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_DEBUG +# define message(...) lowsyslog(__VA_ARGS__) +# else +# define message(...) printf(__VA_ARGS__) +# endif +#else +# ifdef CONFIG_DEBUG +# define message lowsyslog +# else +# define message printf +# endif +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_archinitialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int nsh_archinitialize(void) +{ +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + int ret; +#endif + + /* Initialize the SPI-based MMC/SD slot */ + +#ifdef CONFIG_SAM4L_XPLAINED_IOMODULE + ret = sam_sdinitialize(CONFIG_NSH_MMCSDMINOR); + if (ret < 0) + { + message("nsh_archinitialize: Failed to initialize MMC/SD slot: %d\n", + ret); + return ret; + } +#endif + + return OK; +} -- cgit v1.2.3