From 428f2147af15142f6a02b3d86d3635bd5dbe3f2a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Jul 2017 09:24:32 -0600 Subject: [PATCH] Composite: Move board_msc* interfaces from apps/system/composite to the board specific OS logic where they belong. --- .../mcu123-lpc214x/src/lpc2148_composite.c | 81 +++++++++++++++++-- configs/olimexino-stm32/src/stm32_composite.c | 81 +++++++++++++++++-- configs/samv71-xult/src/sam_composite.c | 81 +++++++++++++++++-- configs/spark/src/stm32_composite.c | 81 +++++++++++++++++-- configs/stm3210e-eval/src/stm32_composite.c | 81 +++++++++++++++++-- 5 files changed, 380 insertions(+), 25 deletions(-) diff --git a/configs/mcu123-lpc214x/src/lpc2148_composite.c b/configs/mcu123-lpc214x/src/lpc2148_composite.c index 8b966edcd6..454c0d751a 100644 --- a/configs/mcu123-lpc214x/src/lpc2148_composite.c +++ b/configs/mcu123-lpc214x/src/lpc2148_composite.c @@ -70,6 +70,14 @@ #define LPC214X_MMCSDSPIPORTNO 1 #define LPC214X_MMCSDSLOTNO 0 +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_USBMSC_COMPOSITE +static FAR void *g_mschandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -101,13 +109,74 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devdesc, FAR struct usbdevclass_driver_s **classdev) { - FAR void *handle; int ret; - ret = usbmsc_configure(1, &handle); - if (ret >= 0) + DEBUGASSERT(g_mschandle == NULL); + + /* Configure the mass storage device */ + + uinfo("Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS); + ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_mschandle); + if (ret < 0) { - ret = usbmsc_classobject(handle, devdesc, classdev); + uerr("ERROR: usbmsc_configure failed: %d\n", -ret); + return ret; + } + + uinfo("MSC handle=%p\n", g_mschandle); + + /* Bind the LUN(s) */ + + uinfo("Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, + 0, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 1 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1 + + uinfo("Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, + 1, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 2 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2 + + uinfo("Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, + 2, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 3 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } +#endif +#endif + + /* Get the mass storage device's class object */ + + ret = usbmsc_classobject(g_mschandle, devdesc, classdev); + if (ret < 0) + { + uerr("ERROR: usbmsc_classobject failed: %d\n", -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } return ret; @@ -134,7 +203,9 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devd #ifdef CONFIG_USBMSC_COMPOSITE void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev) { - usbmsc_uninitialize(classdev); + DEBUGASSERT(g_mschandle != NULL); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } #endif diff --git a/configs/olimexino-stm32/src/stm32_composite.c b/configs/olimexino-stm32/src/stm32_composite.c index 47c57202d6..cba2198dbf 100644 --- a/configs/olimexino-stm32/src/stm32_composite.c +++ b/configs/olimexino-stm32/src/stm32_composite.c @@ -81,6 +81,14 @@ # error "Unrecognized STM32 board" #endif +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_USBMSC_COMPOSITE +static FAR void *g_mschandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -112,13 +120,74 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devdesc, FAR struct usbdevclass_driver_s **classdev) { - FAR void *handle; int ret; - ret = usbmsc_configure(1, &handle); - if (ret >= 0) + DEBUGASSERT(g_mschandle == NULL); + + /* Configure the mass storage device */ + + uinfo("Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS); + ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_mschandle); + if (ret < 0) { - ret = usbmsc_classobject(handle, devdesc, classdev); + uerr("ERROR: usbmsc_configure failed: %d\n", -ret); + return ret; + } + + uinfo("MSC handle=%p\n", g_mschandle); + + /* Bind the LUN(s) */ + + uinfo("Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, + 0, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 1 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1 + + uinfo("Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, + 1, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 2 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2 + + uinfo("Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, + 2, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 3 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } +#endif +#endif + + /* Get the mass storage device's class object */ + + ret = usbmsc_classobject(g_mschandle, devdesc, classdev); + if (ret < 0) + { + uerr("ERROR: usbmsc_classobject failed: %d\n", -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } return ret; @@ -145,7 +214,9 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devd #ifdef CONFIG_USBMSC_COMPOSITE void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev) { - usbmsc_uninitialize(classdev); + DEBUGASSERT(g_mschandle != NULL); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } #endif diff --git a/configs/samv71-xult/src/sam_composite.c b/configs/samv71-xult/src/sam_composite.c index 672ca2260c..e89a7b0b93 100644 --- a/configs/samv71-xult/src/sam_composite.c +++ b/configs/samv71-xult/src/sam_composite.c @@ -49,6 +49,14 @@ #if defined(CONFIG_BOARDCTL_USBDEVCTRL) && defined(CONFIG_USBDEV_COMPOSITE) +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_USBMSC_COMPOSITE +static FAR void *g_mschandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -80,13 +88,74 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devdesc, FAR struct usbdevclass_driver_s **classdev) { - FAR void *handle; int ret; - ret = usbmsc_configure(1, &handle); - if (ret >= 0) + DEBUGASSERT(g_mschandle == NULL); + + /* Configure the mass storage device */ + + uinfo("Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS); + ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_mschandle); + if (ret < 0) { - ret = usbmsc_classobject(handle, devdesc, classdev); + uerr("ERROR: usbmsc_configure failed: %d\n", -ret); + return ret; + } + + uinfo("MSC handle=%p\n", g_mschandle); + + /* Bind the LUN(s) */ + + uinfo("Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, + 0, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 1 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1 + + uinfo("Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, + 1, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 2 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2 + + uinfo("Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, + 2, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 3 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } +#endif +#endif + + /* Get the mass storage device's class object */ + + ret = usbmsc_classobject(g_mschandle, devdesc, classdev); + if (ret < 0) + { + uerr("ERROR: usbmsc_classobject failed: %d\n", -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } return ret; @@ -113,7 +182,9 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devd #ifdef CONFIG_USBMSC_COMPOSITE void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev) { - usbmsc_uninitialize(classdev); + DEBUGASSERT(g_mschandle != NULL); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } #endif diff --git a/configs/spark/src/stm32_composite.c b/configs/spark/src/stm32_composite.c index eb62d01b61..9c6e361a7f 100644 --- a/configs/spark/src/stm32_composite.c +++ b/configs/spark/src/stm32_composite.c @@ -121,6 +121,14 @@ # undef HAVE_USBMONITOR #endif +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_USBMSC_COMPOSITE +static FAR void *g_mschandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -311,13 +319,74 @@ static int stm32_composite_initialize(void) static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devdesc, FAR struct usbdevclass_driver_s **classdev) { - FAR void *handle; int ret; - ret = usbmsc_configure(1, &handle); - if (ret >= 0) + DEBUGASSERT(g_mschandle == NULL); + + /* Configure the mass storage device */ + + uinfo("Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS); + ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_mschandle); + if (ret < 0) { - ret = usbmsc_classobject(handle, devdesc, classdev); + uerr("ERROR: usbmsc_configure failed: %d\n", -ret); + return ret; + } + + uinfo("MSC handle=%p\n", g_mschandle); + + /* Bind the LUN(s) */ + + uinfo("Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, + 0, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 1 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1 + + uinfo("Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, + 1, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 2 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2 + + uinfo("Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, + 2, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 3 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } +#endif +#endif + + /* Get the mass storage device's class object */ + + ret = usbmsc_classobject(g_mschandle, devdesc, classdev); + if (ret < 0) + { + uerr("ERROR: usbmsc_classobject failed: %d\n", -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } return ret; @@ -342,7 +411,9 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devd void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev) { - usbmsc_uninitialize(classdev); + DEBUGASSERT(g_mschandle != NULL); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } /**************************************************************************** diff --git a/configs/stm3210e-eval/src/stm32_composite.c b/configs/stm3210e-eval/src/stm32_composite.c index 4e446c1585..c0785ebae6 100644 --- a/configs/stm3210e-eval/src/stm32_composite.c +++ b/configs/stm3210e-eval/src/stm32_composite.c @@ -79,6 +79,14 @@ # error "Unrecognized STM32 board" #endif +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_USBMSC_COMPOSITE +static FAR void *g_mschandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -110,13 +118,74 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devdesc, FAR struct usbdevclass_driver_s **classdev) { - FAR void *handle; int ret; - ret = usbmsc_configure(1, &handle); - if (ret >= 0) + DEBUGASSERT(g_mschandle == NULL); + + /* Configure the mass storage device */ + + uinfo("Configuring with NLUNS=%d\n", CONFIG_SYSTEM_COMPOSITE_NLUNS); + ret = usbmsc_configure(CONFIG_SYSTEM_COMPOSITE_NLUNS, &g_mschandle); + if (ret < 0) { - ret = usbmsc_classobject(handle, devdesc, classdev); + uerr("ERROR: usbmsc_configure failed: %d\n", -ret); + return ret; + } + + uinfo("MSC handle=%p\n", g_mschandle); + + /* Bind the LUN(s) */ + + uinfo("Bind LUN=0 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH1); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH1, + 0, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 1 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH1, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 1 + + uinfo("Bind LUN=1 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH2); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH2, + 1, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 2 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH2, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } + +#if CONFIG_SYSTEM_COMPOSITE_NLUNS > 2 + + uinfo("Bind LUN=2 to %s\n", CONFIG_SYSTEM_COMPOSITE_DEVPATH3); + ret = usbmsc_bindlun(g_mschandle, CONFIG_SYSTEM_COMPOSITE_DEVPATH3, + 2, 0, 0, false); + if (ret < 0) + { + uerr("ERROR: usbmsc_bindlun failed for LUN 3 using %s: %d\n", + CONFIG_SYSTEM_COMPOSITE_DEVPATH3, -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; + return ret; + } +#endif +#endif + + /* Get the mass storage device's class object */ + + ret = usbmsc_classobject(g_mschandle, devdesc, classdev); + if (ret < 0) + { + uerr("ERROR: usbmsc_classobject failed: %d\n", -ret); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } return ret; @@ -143,7 +212,9 @@ static int board_mscclassobject(int minor, FAR struct usbdev_description_s *devd #ifdef CONFIG_USBMSC_COMPOSITE void board_mscuninitialize(FAR struct usbdevclass_driver_s *classdev) { - usbmsc_uninitialize(classdev); + DEBUGASSERT(g_mschandle != NULL); + usbmsc_uninitialize(g_mschandle); + g_mschandle = NULL; } #endif