Olimex LPC-H3131: Some restructuring of intialization logic
This commit is contained in:
parent
22378d66c5
commit
dace1ec4b0
@ -50,6 +50,10 @@ ifeq ($(CONFIG_LPC31_SPI),y)
|
||||
CSRCS += lpc31_spi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LPC31_MCI),y)
|
||||
CSRCS += lpc31_mmcsd.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NSH_ARCHINIT),y)
|
||||
CSRCS += lpc31_nsh.c
|
||||
endif
|
||||
|
@ -94,7 +94,7 @@ void lpc31_boardinitialize(void)
|
||||
* into the build.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_USBDEV) && defined(CONFIG_LPC31_USBOTG)
|
||||
#ifdef HAVE_USBDEV
|
||||
if (lpc31_usbdev_initialize)
|
||||
{
|
||||
lpc31_usbdev_initialize();
|
||||
@ -107,7 +107,7 @@ void lpc31_boardinitialize(void)
|
||||
* selected.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_USBHOST) || defined(CONFIG_LPC31_USBOTG)
|
||||
#ifdef HAVE_USBHOST
|
||||
lpc31_usbhost_bootinitialize();
|
||||
#endif
|
||||
|
||||
|
108
configs/olimex-lpc-h3131/src/lpc31_mmcsd.c
Normal file
108
configs/olimex-lpc-h3131/src/lpc31_mmcsd.c
Normal file
@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
* configs/olimex-lpc-h3131/src/lpc31_mmcsd.c
|
||||
*
|
||||
* Copyright (C) 2013 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 "lpc31_internal.h"
|
||||
|
||||
#include "lpc_h3131.h"
|
||||
|
||||
#ifdef HAVE_MMCSD
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc31_mmcsd_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create the SDIO-based MMC/SD device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int lpc31_mmcsd_initialize(int slot, int minor)
|
||||
{
|
||||
FAR struct sdio_dev_s *sdio;
|
||||
int ret;
|
||||
|
||||
/* First, get an instance of the SDIO interface */
|
||||
|
||||
fvdbg("Initializing SDIO slot %d\n", slot);
|
||||
sdio = sdio_initialize(slot);
|
||||
if (!sdio)
|
||||
{
|
||||
fdbg("ERROR: Failed to initialize SDIO slot %d\n", slot);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Now bind the SPI interface to the MMC/SD driver */
|
||||
|
||||
fvdbg("Bind SDIO to the MMC/SD driver, minor=%d\n", minor);
|
||||
ret = mmcsd_slotinitialize(minor, sdio);
|
||||
if (ret != OK)
|
||||
{
|
||||
fdbg("ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
fvdbg("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 LPC-H3131 board supports a GPIO to detect if there is a card in
|
||||
* the slot.
|
||||
*/
|
||||
|
||||
sdio_mediachange(sdio, true);
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* HAVE_MMCSD */
|
@ -44,11 +44,6 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef CONFIG_LPC31_MCI
|
||||
# include <nuttx/sdio.h>
|
||||
# include <nuttx/mmcsd.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSTEM_USBMONITOR
|
||||
# include <apps/usbmonitor.h>
|
||||
#endif
|
||||
@ -60,49 +55,18 @@
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* PORT and SLOT number probably depend on the board configuration */
|
||||
|
||||
#define HAVE_MMCSD 1
|
||||
#define HAVE_USBHOST 1
|
||||
#define HAVE_USBMONTOR 1
|
||||
|
||||
#if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0
|
||||
# error "Only one MMC/SD slot"
|
||||
# undef CONFIG_NSH_MMCSDSLOTNO
|
||||
#endif
|
||||
#ifndef CONFIG_NSH_MMCSDSLOTNO
|
||||
# define CONFIG_NSH_MMCSDSLOTNO 0
|
||||
#endif
|
||||
|
||||
/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support
|
||||
* is not enabled.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_LPC31_MCI)
|
||||
# undef HAVE_MMCSD
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_MMCSDMINOR
|
||||
# define CONFIG_NSH_MMCSDMINOR 0
|
||||
#endif
|
||||
|
||||
/* Can't support USB host features if USB host is not enabled */
|
||||
|
||||
#if !defined(CONFIG_LPC31_USBOTG) || !defined(CONFIG_USBHOST)
|
||||
# undef HAVE_USBHOST
|
||||
#endif
|
||||
|
||||
/* Check if we need to support the USB monitor */
|
||||
|
||||
#ifndef HAVE_USBHOST
|
||||
# undef CONFIG_USBHOST_TRACE
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_SYSTEM_USBMONITOR) || !defined(CONFIG_USBHOST_TRACE)
|
||||
# undef HAVE_USBMONITOR
|
||||
#ifdef HAVE_MMCSD
|
||||
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0
|
||||
# error "Only one MMC/SD slot"
|
||||
# undef CONFIG_NSH_MMCSDSLOTNO
|
||||
# endif
|
||||
# ifndef CONFIG_NSH_MMCSDSLOTNO
|
||||
# define CONFIG_NSH_MMCSDSLOTNO 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
@ -135,44 +99,21 @@
|
||||
|
||||
int nsh_archinitialize(void)
|
||||
{
|
||||
#ifdef HAVE_MMCSD
|
||||
FAR struct sdio_dev_s *sdio;
|
||||
#endif
|
||||
#if defined(HAVE_MMCSD) || defined(HAVE_USBHOST)
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMCSD
|
||||
/* First, get an instance of the SDIO interface */
|
||||
/* Create the SDIO-based MMC/SD device */
|
||||
|
||||
message("nsh_archinitialize: Initializing SDIO slot %d\n",
|
||||
CONFIG_NSH_MMCSDSLOTNO);
|
||||
sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
|
||||
message("nsh_archinitialize: Create the MMC/SD device\n");
|
||||
ret = lpc31_mmcsd_initialize(CONFIG_NSH_MMCSDSLOTNO);
|
||||
if (!sdio)
|
||||
{
|
||||
message("nsh_archinitialize: Failed to initialize SDIO slot %d\n",
|
||||
CONFIG_NSH_MMCSDSLOTNO);
|
||||
CONFIG_NSH_MMCSDSLOTNO, CONFIG_NSH_MMCSDMINOR);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Now bind the SPI interface to the MMC/SD driver */
|
||||
|
||||
message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
|
||||
CONFIG_NSH_MMCSDMINOR);
|
||||
ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
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 LPC-H3131 board supports a GPIO to detect if there is a card in
|
||||
* the slot.
|
||||
*/
|
||||
|
||||
sdio_mediachange(sdio, true);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USBHOST
|
||||
@ -180,10 +121,11 @@ int nsh_archinitialize(void)
|
||||
* will monitor for USB connection and disconnection events.
|
||||
*/
|
||||
|
||||
message("nsh_archinitialize: Start USB host services\n");
|
||||
ret = lpc31_usbhost_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
message("ERROR: Failed to initialize USB host: %d\n", ret);
|
||||
message("ERROR: Failed to start USB host services: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@ -191,10 +133,11 @@ int nsh_archinitialize(void)
|
||||
#ifdef HAVE_USBMONITOR
|
||||
/* Start the USB Monitor */
|
||||
|
||||
message("nsh_archinitialize: Start the USB monitor\n");
|
||||
ret = usbmonitor_start(0, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
message("nsh_archinitialize: Start USB monitor: %d\n", ret);
|
||||
message("nsh_archinitialize: Failed to start USB monitor: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
#include "lpc31_internal.h"
|
||||
#include "lpc_h3131.h"
|
||||
|
||||
#if defined(CONFIG_LPC31_USBOTG) && defined(CONFIG_USBHOST)
|
||||
#ifdef HAVE_USBHOST
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -312,4 +312,4 @@ xcpt_t lpc31_setup_overcurrent(xcpt_t handler)
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
#endif /* CONFIG_LPC31_USBOTG || CONFIG_USBHOST */
|
||||
#endif /* HAVE_USBHOST */
|
||||
|
@ -49,6 +49,42 @@
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* PORT and SLOT number probably depend on the board configuration */
|
||||
|
||||
#define HAVE_MMCSD 1
|
||||
#undef HAVE_USBDEV
|
||||
#define HAVE_USBHOST 1
|
||||
#define HAVE_USBMONITOR 1
|
||||
|
||||
/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support
|
||||
* is not enabled.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_LPC31_MCI)
|
||||
# undef HAVE_MMCSD
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_MMCSDMINOR
|
||||
# define CONFIG_NSH_MMCSDMINOR 0
|
||||
#endif
|
||||
|
||||
/* Can't support USB host features if USB host is not enabled */
|
||||
|
||||
#if !defined(CONFIG_LPC31_USBOTG) || !defined(CONFIG_USBHOST)
|
||||
# undef HAVE_USBHOST
|
||||
#endif
|
||||
|
||||
/* Check if we need to support the USB monitor */
|
||||
|
||||
#ifndef HAVE_USBHOST
|
||||
# undef CONFIG_USBHOST_TRACE
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_SYSTEM_USBMONITOR) || !defined(CONFIG_USBHOST_TRACE)
|
||||
# undef HAVE_USBMONITOR
|
||||
#endif
|
||||
|
||||
/* LPC-H3131 GPIOs ******************************************************************/
|
||||
/* BUTTONS. There are no user accessible buttons on the LPC-H3131 */
|
||||
@ -126,7 +162,7 @@ void weak_function lpc31_spiinitialize(void);
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LPC31_USBOTG) && defined(CONFIG_USBDEV)
|
||||
#ifdef HAVE_USBDEV
|
||||
void weak_function lpc31_usbdev_initialize(void);
|
||||
#endif
|
||||
|
||||
@ -139,7 +175,7 @@ void weak_function lpc31_usbdev_initialize(void);
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LPC31_USBOTG) && defined(CONFIG_USBHOST)
|
||||
#ifdef HAVE_USBHOST
|
||||
void weak_function lpc31_usbhost_bootinitialize(void);
|
||||
#endif
|
||||
|
||||
@ -153,10 +189,22 @@ void weak_function lpc31_usbhost_bootinitialize(void);
|
||||
*
|
||||
***********************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LPC31_USBOTG) && defined(CONFIG_USBHOST)
|
||||
#ifdef HAVE_USBHOST
|
||||
int lpc31_usbhost_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc31_mmcsd_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create the SDIO-based MMC/SD device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_MMCSD
|
||||
int lpc31_mmcsd_initialize(int slot, int minor)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_ledinit
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user