diff --git a/arch/arm/src/sam3u/sam3u_dmac.c b/arch/arm/src/sam3u/sam3u_dmac.c index 510ac7e8a3a44774462143b11767c582b9df43da..2084fc67864d62cf76f82873a464540a520146e4 100755 --- a/arch/arm/src/sam3u/sam3u_dmac.c +++ b/arch/arm/src/sam3u/sam3u_dmac.c @@ -447,7 +447,7 @@ static inline uint32_t sam3u_rxctrlabits(struct sam3u_dma_s *dmach) uint32_t regval; unsigned int ndx; - DEBUGASSERT(dmach && dmasize <= DMACHAN_CTRLA_BTSIZE_MAX); + DEBUGASSERT(dmach); /* Since this is a receive, the source is described by the peripheral * selections. Set the source width (peripheral width). @@ -748,7 +748,7 @@ sam3u_allocdesc(struct sam3u_dma_s *dmach, struct dma_linklist_s *prev, } else { - DEBUGASSERT(dmach->llhead != NULL && dmach->tail == prev); + DEBUGASSERT(dmach->llhead != NULL && dmach->lltail == prev); /* When the second link is added to the list, that is the * cue that we are going to do the link list transfer. diff --git a/configs/sam3u-ek/src/Makefile b/configs/sam3u-ek/src/Makefile index 7140269748fbd03af7d16c9b0f512238a5c96f11..4b842ad57933b434f6080d3c10f2fe638c9eb4d4 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 61ddb1f18da2d5884eb4a1434f5c420d8d511775..f092cbb02f7cb1f774b63ee6155b3558e1b555e7 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 4ae2699ed3dee21bdce1ba7bb20ab8e08569268b..36154f905e77eaef956055fc12faaab8a6f1b8f8 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 <spudmonkey@racsa.co.cr> * * 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 0000000000000000000000000000000000000000..45762ee2816a211733e9a77b8b348df51385e85d --- /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 <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. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include <nuttx/config.h> + +#include <stdbool.h> +#include <debug.h> + +#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 c8370369cbef3f56ca09275fcd7e3ba21a7afefb..ae1ecb673e6ed5f54e40d4a9a6addbe18023ddf3 100755 --- a/configs/sam3u-ek/src/up_nsh.c +++ b/configs/sam3u-ek/src/up_nsh.c @@ -49,6 +49,7 @@ #include <nuttx/mmcsd.h> #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; } diff --git a/include/nuttx/sdio.h b/include/nuttx/sdio.h index 8d4861c24b1fb4ea286328715ada76abb79d2f08..65d44dbc61bb08c3fdf111986b0768b943f61ab6 100755 --- a/include/nuttx/sdio.h +++ b/include/nuttx/sdio.h @@ -767,7 +767,10 @@ struct sdio_dev_s /* Command/Status/Data Transfer */ void (*sendcmd)(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t arg); - void (*blocksetup)(FAR struct sdio_dev_s *dev, unsigned int blocklen, unsigned int nblocks); +#ifdef CONFIG_SDIO_BLOCKSETUP + void (*blocksetup)(FAR struct sdio_dev_s *dev, unsigned int blocklen, + unsigned int nblocks); +#endif int (*recvsetup)(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer, size_t nbytes); int (*sendsetup)(FAR struct sdio_dev_s *dev, FAR const uint8_t *buffer, @@ -792,7 +795,10 @@ struct sdio_dev_s int (*registercallback)(FAR struct sdio_dev_s *dev, worker_t callback, void *arg); - /* DMA */ + /* DMA. CONFIG_SDIO_DMA should be set if the driver supports BOTH DMA + * and non-DMA transfer modes. If the driver supports only one mode + * CONFIG_SDIO_DMA is not required. + */ #ifdef CONFIG_SDIO_DMA bool (*dmasupported)(FAR struct sdio_dev_s *dev);