Merged nuttx/apps into master

This commit is contained in:
ziggurat29 2016-03-26 10:44:59 -05:00
commit be530ca3bb
21 changed files with 636 additions and 116 deletions

View File

@ -1567,3 +1567,8 @@
* apps/examples/sched_note: Add a simple example to exercise
the scheduler instrumentation logic. Kind of buggy right now
(2016-03-17).
* apps/system/cdcacm, usbmsc, and composite, apps/examples/usbserial,
composite, usbterm: Use new boardctl() instead of callinig directly
in the OS when possible. There are still a few bad OS calls for
USB device interfaces that do not yet have boardctl() commands
(2016-03-25).

View File

@ -6,6 +6,8 @@
config EXAMPLES_USBSERIAL
bool "USB serial test example"
default n
depends on LIB_BOARDCTL
select BOARDCTL_USBDEVCTRL
---help---
Enable the USB serial test example

View File

@ -1,7 +1,7 @@
/****************************************************************************
* examples/usbserial/usbserial_main.c
*
* Copyright (C) 2008, 2010-2012, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2010-2012, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -41,6 +41,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
@ -195,6 +197,8 @@ int main(int argc, FAR char *argv[])
int usbserial_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
FAR void *handle;
#ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY
int infd;
#endif
@ -213,11 +217,24 @@ int usbserial_main(int argc, char *argv[])
/* Initialize the USB serial driver */
printf("usbserial_main: Registering USB serial driver\n");
#ifdef CONFIG_CDCACM
ret = cdcacm_initialize(0, NULL);
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = 0;
ctrl.handle = &handle;
#else
ret = usbdev_serialinitialize(0);
ctrl.usbdev = BOARDIOC_USBDEV_PL2303;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = 0;
ctrl.handle = &handle;
#endif
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("usbserial_main: ERROR: Failed to create the USB serial device: %d\n",

View File

@ -1,7 +1,7 @@
/****************************************************************************
* examples/usbterm/usbterm_main.c
*
* Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -41,6 +41,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <unistd.h>
@ -65,14 +66,6 @@
#include "usbterm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
@ -190,6 +183,8 @@ int main(int argc, FAR char *argv[])
int usbterm_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
FAR void *handle;
pthread_attr_t attr;
int ret;
@ -214,16 +209,30 @@ int usbterm_main(int argc, char *argv[])
/* Initialize the USB serial driver */
printf("usbterm_main: Registering USB serial driver\n");
#ifdef CONFIG_CDCACM
ret = cdcacm_initialize(0, NULL);
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = 0;
ctrl.handle = &handle;
#else
ret = usbdev_serialinitialize(0);
ctrl.usbdev = BOARDIOC_USBDEV_PL2303;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = 0;
ctrl.handle = &handle;
#endif
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("usbterm_main: ERROR: Failed to create the USB serial device: %d\n", -ret);
goto errout_with_devinit;
}
printf("usbterm_main: Successfully registered the serial driver\n");
#if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0

View File

@ -767,7 +767,8 @@ config NSH_CONSOLE
config NSH_USBCONSOLE
bool "Use a USB serial console"
default n
depends on NSH_CONSOLE && USBDEV && (CDCACM || PL2303)
depends on LIB_BOARDCTL && NSH_CONSOLE && USBDEV && (CDCACM || PL2303)
select BOARDCTL_USBDEVCTRL
---help---
If defined, then the an arbitrary USB serial device may be used
to as the NSH console. In this case, NSH_USBCONDEV must be defined

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/nshlib/nsh_usbconsole.c
*
* Copyright (C) 2012-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2012-2014, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -39,6 +39,8 @@
#include <nuttx/config.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -59,26 +61,6 @@
#ifdef HAVE_USB_CONSOLE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
@ -287,6 +269,8 @@ restart:
int nsh_consolemain(int argc, char *argv[])
{
FAR struct console_stdio_s *pstate = nsh_newconsole();
struct boardioc_usbdev_ctrl_s ctrl;
FAR void *handle;
int ret;
DEBUGASSERT(pstate);
@ -301,11 +285,22 @@ int nsh_consolemain(int argc, char *argv[])
#if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM)
#ifdef CONFIG_CDCACM
ret = cdcacm_initialize(CONFIG_NSH_USBDEV_MINOR, NULL);
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = CONFIG_NSH_USBDEV_MINOR;
ctrl.handle = &handle;
#else
ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR);
ctrl.usbdev = BOARDIOC_USBDEV_PL2303;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = CONFIG_NSH_USBDEV_MINOR;
ctrl.handle = &handle;
#endif
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
UNUSED(ret); /* Eliminate warning if not used */
DEBUGASSERT(ret == OK);
#endif

View File

@ -0,0 +1,8 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_NUCLEO_L476RG
endif

View File

@ -0,0 +1,40 @@
############################################################################
# apps/platform/nucleo-l476rg/Make.defs
#
# Copyright (C) 2016 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.
#
############################################################################
# Add platform specific sources to ASRCS and CSRCS
ifeq ($(CONFIG_HAVE_CXX),y)
CSRCS += stm32_cxxinitialize.c
endif

View File

@ -0,0 +1,153 @@
/****************************************************************************
* apps/platform/nucleo-l476rg/src/stm32_cxxinitialize.c
*
* Copyright (C) 2016 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 <debug.h>
#include <nuttx/arch.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing the static
* constructors.
*/
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_CXX
#endif
#ifdef CONFIG_DEBUG_CXX
# define cxxdbg dbg
# define cxxlldbg lldbg
# ifdef CONFIG_DEBUG_VERBOSE
# define cxxvdbg vdbg
# define cxxllvdbg llvdbg
# else
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
# endif
#else
# define cxxdbg(x...)
# define cxxlldbg(x...)
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/* This type defines one entry in initialization array */
typedef void (*initializer_t)(void);
/****************************************************************************
* External References
****************************************************************************/
/* _sinit and _einit are symbols exported by the linker script that mark the
* beginning and the end of the C++ initialization section.
*/
extern initializer_t _sinit;
extern initializer_t _einit;
/* _stext and _etext are symbols exported by the linker script that mark the
* beginning and the end of text.
*/
extern uint32_t _stext;
extern uint32_t _etext;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_cxxinitialize
*
* Description:
* If C++ and C++ static constructors are supported, then this function
* must be provided by board-specific logic in order to perform
* initialization of the static C++ class instances.
*
* This function should then be called in the application-specific
* user_start logic in order to perform the C++ initialization. NOTE
* that no component of the core NuttX RTOS logic is involved; this
* function definition only provides the 'contract' between application
* specific C++ code and platform-specific toolchain support.
*
****************************************************************************/
void up_cxxinitialize(void)
{
initializer_t *initp;
cxxdbg("_sinit: %p _einit: %p _stext: %p _etext: %p\n",
&_sinit, &_einit, &_stext, &_etext);
/* Visit each entry in the initialization table */
for (initp = &_sinit; initp != &_einit; initp++)
{
initializer_t initializer = *initp;
cxxdbg("initp: %p initializer: %p\n", initp, initializer);
/* Make sure that the address is non-NULL and lies in the text region
* defined by the linker script. Some toolchains may put NULL values
* or counts in the initialization table.
*/
if ((void *)initializer > (void *)&_stext &&
(void *)initializer < (void *)&_etext)
{
cxxdbg("Calling %p\n", initializer);
initializer();
}
}
}
#endif /* CONFIG_HAVE_CXX && CONFIG_HAVE_CXXINITIALIZE */

View File

@ -0,0 +1,8 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_STM32L476VG_DISCO
endif

View File

@ -0,0 +1,40 @@
############################################################################
# apps/platform/stm32l476vg-disco/Make.defs
#
# Copyright (C) 2016 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.
#
############################################################################
# Add platform specific sources to ASRCS and CSRCS
ifeq ($(CONFIG_HAVE_CXX),y)
CSRCS += stm32_cxxinitialize.c
endif

View File

@ -0,0 +1,153 @@
/****************************************************************************
* apps/platform/stm32l476vg-disco/src/stm32_cxxinitialize.c
*
* Copyright (C) 2016 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 <debug.h>
#include <nuttx/arch.h>
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing the static
* constructors.
*/
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_CXX
#endif
#ifdef CONFIG_DEBUG_CXX
# define cxxdbg dbg
# define cxxlldbg lldbg
# ifdef CONFIG_DEBUG_VERBOSE
# define cxxvdbg vdbg
# define cxxllvdbg llvdbg
# else
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
# endif
#else
# define cxxdbg(x...)
# define cxxlldbg(x...)
# define cxxvdbg(x...)
# define cxxllvdbg(x...)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/* This type defines one entry in initialization array */
typedef void (*initializer_t)(void);
/****************************************************************************
* External References
****************************************************************************/
/* _sinit and _einit are symbols exported by the linker script that mark the
* beginning and the end of the C++ initialization section.
*/
extern initializer_t _sinit;
extern initializer_t _einit;
/* _stext and _etext are symbols exported by the linker script that mark the
* beginning and the end of text.
*/
extern uint32_t _stext;
extern uint32_t _etext;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_cxxinitialize
*
* Description:
* If C++ and C++ static constructors are supported, then this function
* must be provided by board-specific logic in order to perform
* initialization of the static C++ class instances.
*
* This function should then be called in the application-specific
* user_start logic in order to perform the C++ initialization. NOTE
* that no component of the core NuttX RTOS logic is involved; this
* function definition only provides the 'contract' between application
* specific C++ code and platform-specific toolchain support.
*
****************************************************************************/
void up_cxxinitialize(void)
{
initializer_t *initp;
cxxdbg("_sinit: %p _einit: %p _stext: %p _etext: %p\n",
&_sinit, &_einit, &_stext, &_etext);
/* Visit each entry in the initialization table */
for (initp = &_sinit; initp != &_einit; initp++)
{
initializer_t initializer = *initp;
cxxdbg("initp: %p initializer: %p\n", initp, initializer);
/* Make sure that the address is non-NULL and lies in the text region
* defined by the linker script. Some toolchains may put NULL values
* or counts in the initialization table.
*/
if ((void *)initializer > (void *)&_stext &&
(void *)initializer < (void *)&_etext)
{
cxxdbg("Calling %p\n", initializer);
initializer();
}
}
}
#endif /* CONFIG_HAVE_CXX && CONFIG_HAVE_CXXINITIALIZE */

View File

@ -6,7 +6,8 @@
menuconfig SYSTEM_CDCACM
bool "USB CDC/ACM Device Commands"
default n
depends on CDCACM && !KERNEL_BUILD
depends on LIB_BOARDCTL && CDCACM
select BOARDCTL_USBDEVCTRL
---help---
Enable the USB CDC/ACM class controls. These controls include:

View File

@ -1,7 +1,7 @@
/****************************************************************************
* system/cdcacm/cdcacm_main.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <debug.h>
@ -49,10 +50,6 @@
#include "cdcacm.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
@ -63,10 +60,6 @@
struct cdcacm_state_s g_cdcacm;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
@ -85,6 +78,7 @@ int main(int argc, FAR char *argv[])
int sercon_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
int ret;
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
@ -106,7 +100,13 @@ int sercon_main(int argc, char *argv[])
/* Initialize the USB CDC/ACM serial driver */
printf("sercon: Registering CDC/ACM serial driver\n");
ret = cdcacm_initialize(CONFIG_SYSTEM_CDCACM_DEVMINOR, &g_cdcacm.handle);
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
ctrl.handle = &g_cdcacm.handle;
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret);
@ -131,6 +131,8 @@ int main(int argc, FAR char **argv)
int serdis_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
/* First check if the USB mass storage device is already connected */
if (!g_cdcacm.handle)
@ -147,8 +149,13 @@ int serdis_main(int argc, char *argv[])
/* Then disconnect the device and uninitialize the USB mass storage driver */
cdcacm_uninitialize(g_cdcacm.handle);
g_cdcacm.handle = NULL;
printf("serdis: Disconnected\n");
return EXIT_SUCCESS;
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
ctrl.handle = &g_cdcacm.handle;
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
g_cdcacm.handle = NULL;
printf("serdis: Disconnected\n");
return EXIT_SUCCESS;
}

View File

@ -6,7 +6,8 @@
menuconfig SYSTEM_COMPOSITE
bool "USB Composite Device Commands"
default n
depends on USBDEV_COMPOSITE && !KERNEL_BUILD
depends on LIB_BOARDCTL && USBDEV_COMPOSITE && !KERNEL_BUILD
select BOARDCTL_USBDEVCTRL
---help---
Enable the USB composite class controls. These controls include:

View File

@ -226,14 +226,4 @@ extern struct composite_state_s g_composite;
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: composite_archinitialize
*
* Description:
* Perform architecture specific initialization.
*
****************************************************************************/
extern int composite_archinitialize(void);
#endif /* __SYSTEM_COMPOSITE_COMPOSITE_H */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* system/composite/composite_main.c
*
* Copyright (C) 2012-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2012-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -40,6 +40,8 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -494,6 +496,32 @@ static int echo_serial(void)
}
#endif
/****************************************************************************
* Name: usbmsc_disconnect
*
* Description:
* Disconnect the USB MSC device
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
static void usbmsc_disconnect(void)
{
struct boardioc_usbdev_ctrl_s ctrl;
ctrl.usbdev = BOARDIOC_USBDEV_MSC;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = 0;
ctrl.handle = &g_composite.mschandle;
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -553,7 +581,7 @@ int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
{
printf("board_mscclassobject: usbmsc_bindlun failed for LUN 1 using %s: %d\n",
CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret);
usbmsc_uninitialize(g_composite.mschandle);
usbmsc_disconnect();
return ret;
}
@ -567,7 +595,7 @@ int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
{
printf("board_mscclassobject: usbmsc_bindlun failed for LUN 2 using %s: %d\n",
CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret);
usbmsc_uninitialize(g_composite.mschandle);
usbmsc_disconnect();
return ret;
}
@ -581,7 +609,7 @@ int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
{
printf("board_mscclassobject: usbmsc_bindlun failed for LUN 3 using %s: %d\n",
CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret);
usbmsc_uninitialize(g_composite.mschandle);
usbmsc_disconnect();
return ret;
}
@ -596,7 +624,7 @@ int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
if (ret < 0)
{
printf("board_mscclassobject: usbmsc_classobject failed: %d\n", -ret);
usbmsc_uninitialize(g_composite.mschandle);
usbmsc_disconnect();
}
check_test_memory_usage("After usbmsc_classobject()");
@ -623,7 +651,7 @@ int board_mscclassobject(FAR struct usbdevclass_driver_s **classdev)
void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev)
{
DEBUGASSERT(g_composite.mschandle != NULL);
usbmsc_uninitialize(g_composite.mschandle);
usbmsc_disconnect();
}
/****************************************************************************
@ -679,8 +707,16 @@ int board_cdcclassobject(FAR struct usbdevclass_driver_s **classdev)
void board_cdcuninitialize(FAR struct usbdevclass_driver_s *classdev)
{
struct boardioc_usbdev_ctrl_s ctrl;
DEBUGASSERT(classdev != NULL);
cdcacm_uninitialize(classdev);
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = CONFIG_SYSTEM_COMPOSITE_TTYUSB;
ctrl.handle = (FAR void **)&classdev;
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
}
/****************************************************************************
@ -700,6 +736,7 @@ int main(int argc, FAR char *argv[])
int conn_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
int ret;
/* If this program is implemented as the NSH 'msconn' command, then we need to
@ -731,25 +768,36 @@ int conn_main(int argc, char *argv[])
/* Perform architecture-specific initialization */
printf("conn_main: Performing architecture-specific initialization\n");
ret = composite_archinitialize();
ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE;
ctrl.action = BOARDIOC_USBDEV_INITIALIZE;
ctrl.instance = 0;
ctrl.handle = NULL;
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("conn_main: composite_archinitialize failed: %d\n", -ret);
printf("conn_main: boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", -ret);
return 1;
}
check_test_memory_usage("After composite_archinitialize()");
check_test_memory_usage("After boardctl(BOARDIOC_USBDEV_CONTROL)");
/* Initialize the USB composite device device */
g_composite.cmphandle = composite_initialize();
if (!g_composite.cmphandle)
ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE;
ctrl.action = BOARDIOC_USBDEV_CONNECT;
ctrl.instance = 0;
ctrl.handle = &g_composite.cmphandle;
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("conn_main: composite_initialize failed\n");
printf("conn_main: boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", -ret);
return 1;
}
check_test_memory_usage("After composite_initialize()");
check_test_memory_usage("After boardctl(BOARDIOC_USBDEV_CONTROL)");
#if defined(CONFIG_USBDEV_TRACE) && CONFIG_USBDEV_TRACE_INITIALIDSET != 0
/* If USB tracing is enabled and tracing of initial USB events is specified,
@ -841,7 +889,12 @@ errout:
close(g_composite.outfd);
#endif
composite_uninitialize(g_composite.cmphandle);
ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = 0;
ctrl.handle = &g_composite.cmphandle;
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
final_memory_usage("Final memory usage");
return 1;
}
@ -864,6 +917,8 @@ int main(int argc, FAR char **argv)
int disconn_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
/* First check if the USB mass storage device is already connected */
if (!g_composite.cmphandle)
@ -872,18 +927,24 @@ int disconn_main(int argc, char *argv[])
return 1;
}
check_test_memory_usage("Since MS connection");
check_test_memory_usage("Since MS connection");
/* Then disconnect the device and uninitialize the USB mass storage driver */
composite_uninitialize(g_composite.cmphandle);
g_composite.cmphandle = NULL;
printf("disconn_main: Disconnected\n");
check_test_memory_usage("After composite_uninitialize()");
ctrl.usbdev = BOARDIOC_USBDEV_COMPOSITE;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = 0;
ctrl.handle = &g_composite.cmphandle;
/* Dump debug memory usage */
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
final_memory_usage("Final memory usage");
return 0;
g_composite.cmphandle = NULL;
printf("disconn_main: Disconnected\n");
check_test_memory_usage("After boardctl(BOARDIOC_USBDEV_CONTROL)");
/* Dump debug memory usage */
final_memory_usage("Final memory usage");
return 0;
}
#endif

View File

@ -6,7 +6,8 @@
menuconfig SYSTEM_USBMSC
bool "USB Mass Storage Device Commands"
default n
depends on USBMSC && !KERNEL_BUILD
depends on LIB_BOARDCTL && USBMSC && !KERNEL_BUILD
select BOARDCTL_USBDEVCTRL
---help---
Enable the USB mass storage class controls. These controls include:

View File

@ -5,11 +5,12 @@ system/usbmsc
the device using the USB storage class driver. In order to use this
add-on, your board-specific logic must provide the function:
void usbmsc_archinitialize(void);
void board_usbmsc_initialize(void);
This function will be called by the system/usbmsc in order to
do the actual registration of the block device drivers. For examples
of the implementation of usbmsc_archinitialize() see
This function will be called by the system/usbmsc indirectly via the
boarctl BOARDIOC_USBDEV_CONTROL command in order to do the actual
registration of the block device drivers. For examples of the
implementation of board_usbmsc_initialize() see
configs/mcu123-lpc124x/src/up_usbmsc.c or
configs/stm3210e-eval/src/usbmsc.c
@ -19,6 +20,10 @@ system/usbmsc
This add-on can be built as two NSH "built-in" commands if this option
is selected: 'msconn' will connect the USB mass storage device; 'msdis'
will disconnect the USB storage device.
CONFIG_LIB_BOARDCTL
Enables the boardctl() interfaces.
CONFIG_BOARDCTL_USBDEVCTRL
Enables the BOARDIOC_USBDEV_CONTROL boardctl() command.
CONFIG_SYSTEM_USBMSC_NLUNS
Defines the number of logical units (LUNs) exported by the USB storage
driver. Each LUN corresponds to one exported block driver (or partition

View File

@ -139,16 +139,4 @@ extern struct usbmsc_state_s g_usbmsc;
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: usbmsc_archinitialize
*
* Description:
* Perform architecture specific initialization. This function must
* configure the block device to export via USB. This function must be
* provided by architecture-specific logic in order to use this add-on.
*
****************************************************************************/
extern int usbmsc_archinitialize(void);
#endif /* __SYSTEM_USBMSC_USBMSC_H */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* system/usbmsc/usbmsc_main.c
*
* Copyright (C) 2008-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2012, 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -40,6 +40,8 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
@ -390,6 +392,32 @@ static int usbmsc_enumerate(struct usbtrace_s *trace, void *arg)
}
#endif
/****************************************************************************
* Name: usbmsc_disconnect
*
* Description:
* Disconnect the USB MSC device
*
* Input Parameters:
* handle - Handle of the connect USB MSC device
*
* Returned Value:
* None
*
****************************************************************************/
static void usbmsc_disconnect(FAR void *handle)
{
struct boardioc_usbdev_ctrl_s ctrl;
ctrl.usbdev = BOARDIOC_USBDEV_MSC;
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
ctrl.instance = 0;
ctrl.handle = &handle;
(void)boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -411,6 +439,7 @@ int main(int argc, FAR char *argv[])
int msconn_main(int argc, char *argv[])
#endif
{
struct boardioc_usbdev_ctrl_s ctrl;
FAR void *handle;
int ret;
@ -451,14 +480,20 @@ int msconn_main(int argc, char *argv[])
/* Register block drivers (architecture-specific) */
printf("mcsonn_main: Creating block drivers\n");
ret = usbmsc_archinitialize();
ctrl.usbdev = BOARDIOC_USBDEV_MSC;
ctrl.action = BOARDIOC_USBDEV_INITIALIZE;
ctrl.instance = 0;
ctrl.handle = NULL;
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
if (ret < 0)
{
printf("mcsonn_main: usbmsc_archinitialize failed: %d\n", -ret);
printf("mcsonn_main: boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", -ret);
return EXIT_FAILURE;
}
check_test_memory_usage("After usbmsc_archinitialize()");
check_test_memory_usage("After boardctl(BOARDIOC_USBDEV_CONTROL)");
/* Then exports the LUN(s) */
@ -467,7 +502,7 @@ int msconn_main(int argc, char *argv[])
if (ret < 0)
{
printf("mcsonn_main: usbmsc_configure failed: %d\n", -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -480,7 +515,7 @@ int msconn_main(int argc, char *argv[])
{
printf("mcsonn_main: usbmsc_bindlun failed for LUN 1 using %s: %d\n",
CONFIG_SYSTEM_USBMSC_DEVPATH1, -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -494,7 +529,7 @@ int msconn_main(int argc, char *argv[])
{
printf("mcsonn_main: usbmsc_bindlun failed for LUN 2 using %s: %d\n",
CONFIG_SYSTEM_USBMSC_DEVPATH2, -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -508,7 +543,7 @@ int msconn_main(int argc, char *argv[])
{
printf("mcsonn_main: usbmsc_bindlun failed for LUN 3 using %s: %d\n",
CONFIG_SYSTEM_USBMSC_DEVPATH3, -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -521,7 +556,7 @@ int msconn_main(int argc, char *argv[])
if (ret < 0)
{
printf("mcsonn_main: usbmsc_exportluns failed: %d\n", -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -547,7 +582,7 @@ int msconn_main(int argc, char *argv[])
if (ret < 0)
{
printf("mcsonn_main: usbtrace_enumerate failed: %d\n", -ret);
usbmsc_uninitialize(handle);
usbmsc_disconnect(handle);
return EXIT_FAILURE;
}
@ -610,10 +645,10 @@ int msdis_main(int argc, char *argv[])
/* Then disconnect the device and uninitialize the USB mass storage driver */
usbmsc_uninitialize(g_usbmsc.mshandle);
usbmsc_disconnect(g_usbmsc.mshandle);
g_usbmsc.mshandle = NULL;
printf("msdis: Disconnected\n");
check_test_memory_usage("After usbmsc_uninitialize()");
check_test_memory_usage("After usbmsc_disconnect()");
/* Dump debug memory usage */