diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-12-21 02:36:11 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-12-21 02:36:11 +0000 |
commit | 923217b39059d97f275771a13d032da287b7327f (patch) | |
tree | 25b9523e971235f7744b94e611bac118225a0ea4 /nuttx/configs/olimex-lpc1766stk | |
parent | a774c58708c599daef71e7a30cf83bb2a342a51c (diff) | |
download | px4-nuttx-923217b39059d97f275771a13d032da287b7327f.tar.gz px4-nuttx-923217b39059d97f275771a13d032da287b7327f.tar.bz2 px4-nuttx-923217b39059d97f275771a13d032da287b7327f.zip |
Add USB host support to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3206 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/configs/olimex-lpc1766stk')
-rwxr-xr-x | nuttx/configs/olimex-lpc1766stk/src/up_nsh.c | 155 |
1 files changed, 150 insertions, 5 deletions
diff --git a/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c b/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c index 26eb3158d..2d7e2753e 100755 --- a/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c +++ b/nuttx/configs/olimex-lpc1766stk/src/up_nsh.c @@ -46,6 +46,7 @@ #include <nuttx/spi.h> #include <nuttx/mmcsd.h> +#include <nuttx/usb/usbhost.h> #include "lpc17_internal.h" #include "lpc1766stk_internal.h" @@ -60,6 +61,7 @@ #ifdef CONFIG_ARCH_BOARD_LPC1766STK # define CONFIG_EXAMPLES_NSH_HAVEMMCSD 1 +# define CONFIG_EXAMPLES_NSH_HAVEUSBHOST 1 # if !defined(CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO) || CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO != 1 # error "The LPC1766-STK MMC/SD is on SSP1" # undef CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO @@ -72,10 +74,12 @@ # endif # ifndef CONFIG_LPC17_SSP1 # warning "CONFIG_LPC17_SSP1 is not enabled" +# undef CONFIG_EXAMPLES_NSH_HAVEMMCSD # endif #else # error "Unrecognized board" # undef CONFIG_EXAMPLES_NSH_HAVEMMCSD +# undef CONFIG_EXAMPLES_NSH_HAVEUSBHOST #endif /* Can't support MMC/SD features if mountpoints are disabled */ @@ -88,6 +92,33 @@ # define CONFIG_EXAMPLES_NSH_MMCSDMINOR 0 #endif +/* USB Host */ + +#ifdef CONFIG_USBHOST +# ifndef CONFIG_LPC17_USBHOST +# error "CONFIG_LPC17_USBHOST is not selected" +# endif +#endif + +#ifdef CONFIG_LPC17_USBHOST +# ifndef CONFIG_USBHOST +# warning "CONFIG_USBHOST is not selected" +# endif +#endif + +#if !defined(CONFIG_USBHOST) || !defined(CONFIG_LPC17_USBHOST) +# undef CONFIG_EXAMPLES_NSH_HAVEUSBHOST +#endif + +#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST +# ifndef CONFIG_USBHOST_DEFPRIO +# define CONFIG_USBHOST_DEFPRIO 50 +# endif +# ifndef CONFIG_USBHOST_STACKSIZE +# define CONFIG_USBHOST_STACKSIZE 1024 +# endif +#endif + /* Debug ********************************************************************/ #ifdef CONFIG_CPP_HAVE_VARARGS @@ -105,18 +136,65 @@ #endif /**************************************************************************** - * Public Functions + * Private Data ****************************************************************************/ +#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST +static struct usbhost_driver_s *g_drvr; +#endif + /**************************************************************************** - * Name: nsh_archinitialize + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_waiter * * Description: - * Perform architecture specific initialization + * Wait for USB devices to be connected. * ****************************************************************************/ -int nsh_archinitialize(void) +#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST +static int nsh_waiter(int argc, char *argv[]) +{ + bool connected = false; + int ret; + + for (;;) + { + /* Wait for the device to change state */ + + ret = DRVR_WAIT(g_drvr, connected); + DEBUGASSERT(ret == OK); + connected = !connected; + + /* Did we just become connected? */ + + if (connected) + { + /* Yes.. enumerate the newly connected device */ + + (void)DRVR_ENUMERATE(g_drvr); + } + } + + /* Keep the compiler from complaining */ + + return 0; +} +#endif + +/**************************************************************************** + * Name: nsh_sdinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_NSH_HAVEMMCSD +static int nsh_sdinitialize(void) { FAR struct spi_dev_s *ssp; int ret; @@ -145,7 +223,7 @@ int nsh_archinitialize(void) CONFIG_EXAMPLES_NSH_MMCSDSLOTNO, ssp); if (ret < 0) { - message("nsh_archinitialize: " + message("nsh_sdinitialize: " "Failed to bind SSP port %d to MMC/SD slot %d: %d\n", CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO, CONFIG_EXAMPLES_NSH_MMCSDSLOTNO, ret); @@ -163,3 +241,70 @@ errout: lpc17_gpiowrite(LPC1766STK_MMC_PWR, true); return ret; } +#else +# define nsh_sdinitialize() (OK) +#endif + +/**************************************************************************** + * Name: nsh_usbhostinitialize + * + * Description: + * Initialize SPI-based microSD. + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST +static int nsh_usbhostinitialize(void) +{ + int pid; + + /* First, get an instance of the USB host interface */ + + g_drvr = usbhost_initialize(0); + if (g_drvr) + { + /* Start a thread to handle device connection. */ + +#ifndef CONFIG_CUSTOM_STACK + pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO, + CONFIG_USBHOST_STACKSIZE, + (main_t)nsh_waiter, (const char **)NULL); +#else + pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO, + (main_t)nsh_waiter, (const char **)NULL); +#endif + return pid < 0 ? -ENOEXEC : OK; + } + return -ENODEV; +} +#else +# define nsh_usbhostinitialize() (OK) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_archinitialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int nsh_archinitialize(void) +{ + int ret; + + /* Initialize SPI-based microSD */ + + ret = nsh_sdinitialize(); + if (ret == OK) + { + /* Initialize USB host */ + + ret = nsh_usbhostinitialize(); + } + return ret; +} |