From a31300cb05bdb9760a6d869d4980ef549e5c6454 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Mar 2016 13:26:00 -0600 Subject: [PATCH 1/6] Replace calls to OS internal cdcacm_*, usbmsc_*, and composite_* with boardctl() calls --- examples/usbserial/usbserial_main.c | 22 +++++- examples/usbterm/usbterm_main.c | 29 +++++--- nshlib/nsh_usbconsole.c | 40 +++++------ system/cdcacm/cdcacm_main.c | 35 +++++---- system/composite/composite.h | 10 --- system/composite/composite_main.c | 107 ++++++++++++++++++++++------ system/usbmsc/README.txt | 13 ++-- system/usbmsc/usbmsc.h | 12 ---- system/usbmsc/usbmsc_main.c | 59 +++++++++++---- 9 files changed, 218 insertions(+), 109 deletions(-) diff --git a/examples/usbserial/usbserial_main.c b/examples/usbserial/usbserial_main.c index 04af142de..88a44dd71 100644 --- a/examples/usbserial/usbserial_main.c +++ b/examples/usbserial/usbserial_main.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ #include #include +#include + #include #include #include @@ -195,6 +197,10 @@ int main(int argc, FAR char *argv[]) int usbserial_main(int argc, char *argv[]) #endif { +#ifdef CONFIG_CDCACM + struct boardioc_usbdev_ctrl_s ctrl; + FAR void *handle; +#endif #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY int infd; #endif @@ -213,11 +219,23 @@ 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; + + ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); + #else +# warning REVISIT: This violates the OS/application interface + ret = usbdev_serialinitialize(0); + #endif + if (ret < 0) { printf("usbserial_main: ERROR: Failed to create the USB serial device: %d\n", diff --git a/examples/usbterm/usbterm_main.c b/examples/usbterm/usbterm_main.c index ed1c56833..173d29235 100644 --- a/examples/usbterm/usbterm_main.c +++ b/examples/usbterm/usbterm_main.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -65,14 +66,6 @@ #include "usbterm.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -190,6 +183,10 @@ int main(int argc, FAR char *argv[]) int usbterm_main(int argc, char *argv[]) #endif { +#ifdef CONFIG_CDCACM + struct boardioc_usbdev_ctrl_s ctrl; + FAR void *handle; +#endif pthread_attr_t attr; int ret; @@ -214,11 +211,23 @@ 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; + + ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); + #else +# warning REVISIT: This violates the OS/application interface + ret = usbdev_serialinitialize(0); + #endif + if (ret < 0) { printf("usbterm_main: ERROR: Failed to create the USB serial device: %d\n", -ret); diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c index 894a0ea68..79289d858 100644 --- a/nshlib/nsh_usbconsole.c +++ b/nshlib/nsh_usbconsole.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ #include +#include + #include #include #include @@ -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,10 @@ restart: int nsh_consolemain(int argc, char *argv[]) { FAR struct console_stdio_s *pstate = nsh_newconsole(); +#ifdef CONFIG_CDCACM + struct boardioc_usbdev_ctrl_s ctrl; + FAR void *handle; +#endif int ret; DEBUGASSERT(pstate); @@ -301,9 +287,19 @@ 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 = 0; + ctrl.handle = &handle; + + ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); + #else +# warning REVISIT: This violates the OS/application interface + ret = usbdev_serialinitialize(CONFIG_NSH_USBDEV_MINOR); + #endif UNUSED(ret); /* Eliminate warning if not used */ diff --git a/system/cdcacm/cdcacm_main.c b/system/cdcacm/cdcacm_main.c index c53d2df69..b3bb4606b 100644 --- a/system/cdcacm/cdcacm_main.c +++ b/system/cdcacm/cdcacm_main.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -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; } diff --git a/system/composite/composite.h b/system/composite/composite.h index d64228dd2..56ec20cd7 100644 --- a/system/composite/composite.h +++ b/system/composite/composite.h @@ -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 */ diff --git a/system/composite/composite_main.c b/system/composite/composite_main.c index 8ea490739..410642e13 100644 --- a/system/composite/composite_main.c +++ b/system/composite/composite_main.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,8 @@ #include #include +#include + #include #include #include @@ -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_USBMSC; + 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 diff --git a/system/usbmsc/README.txt b/system/usbmsc/README.txt index 9207dfb6b..935687a51 100755 --- a/system/usbmsc/README.txt +++ b/system/usbmsc/README.txt @@ -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 diff --git a/system/usbmsc/usbmsc.h b/system/usbmsc/usbmsc.h index 5b19a9e03..1abbe0c52 100644 --- a/system/usbmsc/usbmsc.h +++ b/system/usbmsc/usbmsc.h @@ -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 */ diff --git a/system/usbmsc/usbmsc_main.c b/system/usbmsc/usbmsc_main.c index e8a87b7c4..fc8735080 100644 --- a/system/usbmsc/usbmsc_main.c +++ b/system/usbmsc/usbmsc_main.c @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,8 @@ #include #include +#include + #include #include #include @@ -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_USBMSC; + 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_USBMSC; + 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 */ From e01e664ccb67e6e888aa81ffdd6c7930ad7301ff Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Mar 2016 14:24:01 -0600 Subject: [PATCH 2/6] Fix a few issues related to new USB device boardctl() commands --- ChangeLog.txt | 5 +++++ system/composite/composite_main.c | 2 +- system/usbmsc/usbmsc_main.c | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index fc1aaf72e..ec95aa01f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -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). diff --git a/system/composite/composite_main.c b/system/composite/composite_main.c index 410642e13..ab473124b 100644 --- a/system/composite/composite_main.c +++ b/system/composite/composite_main.c @@ -514,7 +514,7 @@ static void usbmsc_disconnect(void) { struct boardioc_usbdev_ctrl_s ctrl; - ctrl.usbdev = BOARDIOC_USBDEV_USBMSC; + ctrl.usbdev = BOARDIOC_USBDEV_MSC; ctrl.action = BOARDIOC_USBDEV_DISCONNECT; ctrl.instance = 0; ctrl.handle = &g_composite.mschandle; diff --git a/system/usbmsc/usbmsc_main.c b/system/usbmsc/usbmsc_main.c index fc8735080..83a2dd9d4 100644 --- a/system/usbmsc/usbmsc_main.c +++ b/system/usbmsc/usbmsc_main.c @@ -410,7 +410,7 @@ static void usbmsc_disconnect(FAR void *handle) { struct boardioc_usbdev_ctrl_s ctrl; - ctrl.usbdev = BOARDIOC_USBDEV_USBMSC; + ctrl.usbdev = BOARDIOC_USBDEV_MSC; ctrl.action = BOARDIOC_USBDEV_DISCONNECT; ctrl.instance = 0; ctrl.handle = &handle; @@ -481,7 +481,7 @@ int msconn_main(int argc, char *argv[]) printf("mcsonn_main: Creating block drivers\n"); - ctrl.usbdev = BOARDIOC_USBDEV_USBMSC; + ctrl.usbdev = BOARDIOC_USBDEV_MSC; ctrl.action = BOARDIOC_USBDEV_INITIALIZE; ctrl.instance = 0; ctrl.handle = NULL; From da0447357638e7bbe90d5d4002cb73a1fa7fcbba Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Mar 2016 15:02:47 -0600 Subject: [PATCH 3/6] Add platform files for STM32L476-DISCO --- platform/stm32l476vg-disco/Kconfig | 8 + platform/stm32l476vg-disco/Make.defs | 40 +++++ .../stm32l476vg-disco/stm32_cxxinitialize.c | 153 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 platform/stm32l476vg-disco/Kconfig create mode 100644 platform/stm32l476vg-disco/Make.defs create mode 100644 platform/stm32l476vg-disco/stm32_cxxinitialize.c diff --git a/platform/stm32l476vg-disco/Kconfig b/platform/stm32l476vg-disco/Kconfig new file mode 100644 index 000000000..5c4adb26a --- /dev/null +++ b/platform/stm32l476vg-disco/Kconfig @@ -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 diff --git a/platform/stm32l476vg-disco/Make.defs b/platform/stm32l476vg-disco/Make.defs new file mode 100644 index 000000000..bca6dc247 --- /dev/null +++ b/platform/stm32l476vg-disco/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/platform/stm32l476vg-disco/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 diff --git a/platform/stm32l476vg-disco/stm32_cxxinitialize.c b/platform/stm32l476vg-disco/stm32_cxxinitialize.c new file mode 100644 index 000000000..4d7081af0 --- /dev/null +++ b/platform/stm32l476vg-disco/stm32_cxxinitialize.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * apps/platform/stm32l476vg-disco/src/stm32_cxxinitialize.c + * + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#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 */ From 843d2b90e671eec60ceaa2c830be3720d465f777 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Mar 2016 15:16:56 -0600 Subject: [PATCH 4/6] Move stm32_cxxinitialize to where it belongs in apps/platform --- platform/nucleo-l476rg/Kconfig | 8 + platform/nucleo-l476rg/Make.defs | 40 +++++ platform/nucleo-l476rg/stm32_cxxinitialize.c | 153 ++++++++++++++++++ .../stm32l476vg-disco/stm32_cxxinitialize.c | 2 +- 4 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 platform/nucleo-l476rg/Kconfig create mode 100644 platform/nucleo-l476rg/Make.defs create mode 100644 platform/nucleo-l476rg/stm32_cxxinitialize.c diff --git a/platform/nucleo-l476rg/Kconfig b/platform/nucleo-l476rg/Kconfig new file mode 100644 index 000000000..33619ff06 --- /dev/null +++ b/platform/nucleo-l476rg/Kconfig @@ -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 diff --git a/platform/nucleo-l476rg/Make.defs b/platform/nucleo-l476rg/Make.defs new file mode 100644 index 000000000..fca3c15f0 --- /dev/null +++ b/platform/nucleo-l476rg/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/platform/nucleo-l476rg/Make.defs +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 diff --git a/platform/nucleo-l476rg/stm32_cxxinitialize.c b/platform/nucleo-l476rg/stm32_cxxinitialize.c new file mode 100644 index 000000000..05a408736 --- /dev/null +++ b/platform/nucleo-l476rg/stm32_cxxinitialize.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * apps/platform/nucleo-l476rg/src/stm32_cxxinitialize.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#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 */ diff --git a/platform/stm32l476vg-disco/stm32_cxxinitialize.c b/platform/stm32l476vg-disco/stm32_cxxinitialize.c index 4d7081af0..ba024de68 100644 --- a/platform/stm32l476vg-disco/stm32_cxxinitialize.c +++ b/platform/stm32l476vg-disco/stm32_cxxinitialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/platform/stm32l476vg-disco/src/stm32_cxxinitialize.c * - * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without From 6951366ecaa8f6e60fd2bf99bf531e031690ff02 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Mar 2016 16:00:28 -0600 Subject: [PATCH 5/6] Replace all calls to the OS internal usbdev_serialinitialize with proper calls to boardctl() --- examples/usbserial/usbserial_main.c | 11 +++++------ examples/usbterm/usbterm_main.c | 12 ++++++------ nshlib/nsh_usbconsole.c | 13 ++++++------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/examples/usbserial/usbserial_main.c b/examples/usbserial/usbserial_main.c index 88a44dd71..989b9c5c5 100644 --- a/examples/usbserial/usbserial_main.c +++ b/examples/usbserial/usbserial_main.c @@ -197,10 +197,8 @@ int main(int argc, FAR char *argv[]) int usbserial_main(int argc, char *argv[]) #endif { -#ifdef CONFIG_CDCACM struct boardioc_usbdev_ctrl_s ctrl; FAR void *handle; -#endif #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY int infd; #endif @@ -227,15 +225,16 @@ int usbserial_main(int argc, char *argv[]) ctrl.instance = 0; ctrl.handle = &handle; - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - #else -# warning REVISIT: This violates the OS/application interface - 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", diff --git a/examples/usbterm/usbterm_main.c b/examples/usbterm/usbterm_main.c index 173d29235..12a3dcee6 100644 --- a/examples/usbterm/usbterm_main.c +++ b/examples/usbterm/usbterm_main.c @@ -183,10 +183,8 @@ int main(int argc, FAR char *argv[]) int usbterm_main(int argc, char *argv[]) #endif { -#ifdef CONFIG_CDCACM struct boardioc_usbdev_ctrl_s ctrl; FAR void *handle; -#endif pthread_attr_t attr; int ret; @@ -219,20 +217,22 @@ int usbterm_main(int argc, char *argv[]) ctrl.instance = 0; ctrl.handle = &handle; - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - #else -# warning REVISIT: This violates the OS/application interface - 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 diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c index 79289d858..e766ead9b 100644 --- a/nshlib/nsh_usbconsole.c +++ b/nshlib/nsh_usbconsole.c @@ -269,10 +269,8 @@ restart: int nsh_consolemain(int argc, char *argv[]) { FAR struct console_stdio_s *pstate = nsh_newconsole(); -#ifdef CONFIG_CDCACM struct boardioc_usbdev_ctrl_s ctrl; FAR void *handle; -#endif int ret; DEBUGASSERT(pstate); @@ -290,18 +288,19 @@ int nsh_consolemain(int argc, char *argv[]) ctrl.usbdev = BOARDIOC_USBDEV_CDCACM; ctrl.action = BOARDIOC_USBDEV_CONNECT; - ctrl.instance = 0; + ctrl.instance = CONFIG_NSH_USBDEV_MINOR; ctrl.handle = &handle; - ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); - #else -# warning REVISIT: This violates the OS/application interface - 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 From 0943afd2f90eff8d7a327394ea85e6f5e6826ff5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Mar 2016 07:13:57 -0600 Subject: [PATCH 6/6] Kconfig files: All USB-related options depend on CONFIG_LIB_BOARDCTRL and now set CONFIG_BOARDCTL_USBDEVCTL=y --- examples/usbserial/Kconfig | 2 ++ nshlib/Kconfig | 3 ++- system/cdcacm/Kconfig | 3 ++- system/composite/Kconfig | 3 ++- system/usbmsc/Kconfig | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/usbserial/Kconfig b/examples/usbserial/Kconfig index 0ceea5d75..5133678ac 100644 --- a/examples/usbserial/Kconfig +++ b/examples/usbserial/Kconfig @@ -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 diff --git a/nshlib/Kconfig b/nshlib/Kconfig index a843c5f72..81c14f173 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -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 diff --git a/system/cdcacm/Kconfig b/system/cdcacm/Kconfig index 0f67f86be..4fb293772 100644 --- a/system/cdcacm/Kconfig +++ b/system/cdcacm/Kconfig @@ -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: diff --git a/system/composite/Kconfig b/system/composite/Kconfig index 8fec3f356..a787f0934 100644 --- a/system/composite/Kconfig +++ b/system/composite/Kconfig @@ -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: diff --git a/system/usbmsc/Kconfig b/system/usbmsc/Kconfig index 9ab522f6f..1bfe307e8 100644 --- a/system/usbmsc/Kconfig +++ b/system/usbmsc/Kconfig @@ -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: