Add MCI CD GPIO

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2585 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2010-04-11 15:32:07 +00:00
parent 1bee4a3f0f
commit 03b90172f4
7 changed files with 202 additions and 14 deletions

View File

@ -447,7 +447,7 @@ static inline uint32_t sam3u_rxctrlabits(struct sam3u_dma_s *dmach)
uint32_t regval; uint32_t regval;
unsigned int ndx; unsigned int ndx;
DEBUGASSERT(dmach && dmasize <= DMACHAN_CTRLA_BTSIZE_MAX); DEBUGASSERT(dmach);
/* Since this is a receive, the source is described by the peripheral /* Since this is a receive, the source is described by the peripheral
* selections. Set the source width (peripheral width). * selections. Set the source width (peripheral width).
@ -748,7 +748,7 @@ sam3u_allocdesc(struct sam3u_dma_s *dmach, struct dma_linklist_s *prev,
} }
else 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 /* When the second link is added to the list, that is the
* cue that we are going to do the link list transfer. * cue that we are going to do the link list transfer.

View File

@ -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) ifeq ($(CONFIG_EXAMPLES_NSH_ARCHINIT),y)
CSRCS += up_nsh.c CSRCS += up_nsh.c
endif endif
ifeq ($(CONFIG_SAM3U_HSMCI),y)
CSRCS += up_mmcsd.c
endif
ifeq ($(CONFIG_EXAMPLE),usbstorage) ifeq ($(CONFIG_EXAMPLE),usbstorage)
CSRCS += up_usbstrg.c CSRCS += up_usbstrg.c
endif endif

View File

@ -108,6 +108,48 @@ extern void weak_function sam3u_spiinitialize(void);
extern void weak_function sam3u_usbinitialize(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 /* __ASSEMBLY__ */
#endif /* __CONFIGS_SAM3U_EK_SRC_SAM3UEK_INTERNAL_H */ #endif /* __CONFIGS_SAM3U_EK_SRC_SAM3UEK_INTERNAL_H */

View File

@ -2,7 +2,7 @@
* configs/sam3u-ek/src/up_boot.c * configs/sam3u-ek/src/up_boot.c
* arch/arm/src/board/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> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -82,7 +82,7 @@ void sam3u_boardinitialize(void)
} }
#endif #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 * disabled, and 3) the weak function sam3u_usbinitialize() has been brought
* into the build. * into the build.
*/ */
@ -100,9 +100,14 @@ void sam3u_boardinitialize(void)
up_ledinit(); up_ledinit();
#endif #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 #ifdef CONFIG_SAM3U_HSMCI
sam3u_configgpio(GPIO_MCI_CD); if (sam3u_hsmciinit)
{
sam3u_hsmciinit();
}
#endif #endif
} }

134
configs/sam3u-ek/src/up_mmcsd.c Executable file
View File

@ -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 */

View File

@ -49,6 +49,7 @@
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#include "sam3u_internal.h" #include "sam3u_internal.h"
#include "sam3uek_internal.h"
#ifdef CONFIG_SAM3U_HSMCI #ifdef CONFIG_SAM3U_HSMCI
@ -154,12 +155,9 @@ int nsh_archinitialize(void)
} }
message("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n"); 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 /* Then inform the HSMCI driver if there is or is not a card in the slot. */
* see if the SAM3U-EK board supports a GPIO to detect if there is a card in
* the slot.
*/
sdio_mediachange(sdio, true); sdio_mediachange(sdio, sam3u_cardinserted(0));
#endif #endif
return OK; return OK;
} }

View File

@ -767,7 +767,10 @@ struct sdio_dev_s
/* Command/Status/Data Transfer */ /* Command/Status/Data Transfer */
void (*sendcmd)(FAR struct sdio_dev_s *dev, uint32_t cmd, uint32_t arg); 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, int (*recvsetup)(FAR struct sdio_dev_s *dev, FAR uint8_t *buffer,
size_t nbytes); size_t nbytes);
int (*sendsetup)(FAR struct sdio_dev_s *dev, FAR const uint8_t *buffer, 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, int (*registercallback)(FAR struct sdio_dev_s *dev,
worker_t callback, void *arg); 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 #ifdef CONFIG_SDIO_DMA
bool (*dmasupported)(FAR struct sdio_dev_s *dev); bool (*dmasupported)(FAR struct sdio_dev_s *dev);