From dbfb72ee2b28fefcf09705d0c366b1b319f644bf Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 11 Apr 2010 15:32:07 +0000 Subject: [PATCH] Add MCI CD GPIO git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2585 42af7a65-404d-4744-a932-0658087f49c3 --- configs/sam3u-ek/src/Makefile | 3 + configs/sam3u-ek/src/sam3uek_internal.h | 42 ++++++++ configs/sam3u-ek/src/up_boot.c | 15 ++- configs/sam3u-ek/src/up_mmcsd.c | 134 ++++++++++++++++++++++++ configs/sam3u-ek/src/up_nsh.c | 8 +- 5 files changed, 192 insertions(+), 10 deletions(-) create mode 100755 configs/sam3u-ek/src/up_mmcsd.c diff --git a/configs/sam3u-ek/src/Makefile b/configs/sam3u-ek/src/Makefile index 7140269748..4b842ad579 100755 --- a/configs/sam3u-ek/src/Makefile +++ b/configs/sam3u-ek/src/Makefile @@ -44,6 +44,9 @@ CSRCS = up_boot.c up_leds.c up_buttons.c up_spi.c up_usbdev.c ifeq ($(CONFIG_EXAMPLES_NSH_ARCHINIT),y) CSRCS += up_nsh.c endif +ifeq ($(CONFIG_SAM3U_HSMCI),y) +CSRCS += up_mmcsd.c +endif ifeq ($(CONFIG_EXAMPLE),usbstorage) CSRCS += up_usbstrg.c endif diff --git a/configs/sam3u-ek/src/sam3uek_internal.h b/configs/sam3u-ek/src/sam3uek_internal.h index 61ddb1f18d..f092cbb02f 100755 --- a/configs/sam3u-ek/src/sam3uek_internal.h +++ b/configs/sam3u-ek/src/sam3uek_internal.h @@ -108,6 +108,48 @@ extern void weak_function sam3u_spiinitialize(void); extern void weak_function sam3u_usbinitialize(void); +/**************************************************************************** + * Name: sam3u_hsmciinit + * + * Description: + * Initialize HSMCI support + * + ****************************************************************************/ + +#ifdef CONFIG_SAM3U_HSMCI +extern int weak_function sam3u_hsmciinit(void); +#else +# define sam3u_boardmciinit() +#endif + +/**************************************************************************** + * Name: sam3u_cardinserted + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ****************************************************************************/ + +#ifdef CONFIG_SAM3U_HSMCI +extern bool sam3u_cardinserted(unsigned char slot); +#else +# define sam3u_cardinserted(slot) (false) +#endif + +/**************************************************************************** + * Name: sam3u_writeprotected + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ****************************************************************************/ + +#ifdef CONFIG_SAM3U_HSMCI +extern bool sam3u_writeprotected(unsigned char slot); +#else +# define sam3u_writeprotected(slot) (false) +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_SAM3U_EK_SRC_SAM3UEK_INTERNAL_H */ diff --git a/configs/sam3u-ek/src/up_boot.c b/configs/sam3u-ek/src/up_boot.c index 4ae2699ed3..36154f905e 100755 --- a/configs/sam3u-ek/src/up_boot.c +++ b/configs/sam3u-ek/src/up_boot.c @@ -2,7 +2,7 @@ * configs/sam3u-ek/src/up_boot.c * arch/arm/src/board/up_boot.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -82,7 +82,7 @@ void sam3u_boardinitialize(void) } #endif - /* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not + /* Initialize USB if 1) USBDEV is selected, 2) the USB controller is not * disabled, and 3) the weak function sam3u_usbinitialize() has been brought * into the build. */ @@ -100,9 +100,14 @@ void sam3u_boardinitialize(void) up_ledinit(); #endif - /* Setup SD card detection PIO */ + /* Setup SD card-related PIOs if 1) HSMCI is selected and 2) the weak + * function sam3u_hsmciinit() has been brought into the build. + */ -#if CONFIG_SAM3U_HSMCI - sam3u_configgpio(GPIO_MCI_CD); +#ifdef CONFIG_SAM3U_HSMCI + if (sam3u_hsmciinit) + { + sam3u_hsmciinit(); + } #endif } diff --git a/configs/sam3u-ek/src/up_mmcsd.c b/configs/sam3u-ek/src/up_mmcsd.c new file mode 100755 index 0000000000..45762ee281 --- /dev/null +++ b/configs/sam3u-ek/src/up_mmcsd.c @@ -0,0 +1,134 @@ +/************************************************************************************ + * configs/sam3u-ek/src/up_mmcsd.c + * arch/arm/src/board/up_mmcsd.c + * + * Copyright (C) 2010 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 "sam3u_internal.h" +#include "sam3uek_internal.h" + +#ifdef CONFIG_SAM3U_HSMCI + +/************************************************************************************ + * Definitions + ************************************************************************************/ + +/* This needs to be extended. The card detect GPIO must be configured as an interrupt. + * when the interrupt indicating that a card has been inserted or removed is received, + * this function must call sio_mediachange() to handle that event. See + * arch/arm/src/sam3u/sam3u_internal.h for more information. + */ + +#ifdef GPIO_MCI_CD +# warning "Card detect interrupt handling needed" +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/**************************************************************************** + * Name: sam3u_hsmciinit + * + * Description: + * Initialize HSMCI support + * + ****************************************************************************/ + +int sam3u_hsmciinit(void) +{ +#if GPIO_MCI_CD + sam3u_configgpio(GPIO_MCI_CD); +#endif +#if GPIO_MCI_WP + sam3u_configgpio(GPIO_MCI_WP); +#endif + return OK; +} + +/**************************************************************************** + * Name: sam3u_cardinserted + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ****************************************************************************/ + +bool sam3u_cardinserted(unsigned char slot) +{ + if (slot == 0) + { +#ifdef GPIO_MCI_CD + return !sam3u_gpioread(GPIO_MCI_CD); +#else + return true; +#endif + } + return false; +} + +/**************************************************************************** + * Name: sam3u_writeprotected + * + * Description: + * Check if a card is inserted into the selected HSMCI slot + * + ****************************************************************************/ + +bool sam3u_writeprotected(unsigned char slot) +{ + if (slot == 0) + { +#ifdef GPIO_MCI_WP + return sam3u_gpioread(GPIO_MCI_WP); +#else + return false; +#endif + } + return false; +} + +#endif /* CONFIG_SAM3U_HSMCI */ diff --git a/configs/sam3u-ek/src/up_nsh.c b/configs/sam3u-ek/src/up_nsh.c index c8370369cb..ae1ecb673e 100755 --- a/configs/sam3u-ek/src/up_nsh.c +++ b/configs/sam3u-ek/src/up_nsh.c @@ -49,6 +49,7 @@ #include #include "sam3u_internal.h" +#include "sam3uek_internal.h" #ifdef CONFIG_SAM3U_HSMCI @@ -154,12 +155,9 @@ int nsh_archinitialize(void) } message("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n"); - /* Then let's guess and say that there is a card in the slot. I need to check to - * see if the SAM3U-EK board supports a GPIO to detect if there is a card in - * the slot. - */ + /* Then inform the HSMCI driver if there is or is not a card in the slot. */ - sdio_mediachange(sdio, true); + sdio_mediachange(sdio, sam3u_cardinserted(0)); #endif return OK; }