From e3ba485a852fc10a85533d0c5a28c6e01d66a0d4 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 22 Jul 2011 20:12:50 +0000 Subject: apps/examples/usbstorage can now be built as NSH built-in commands; configs/stm3210e-eval/nsh2 now uses these usb storage commands git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3812 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 4 + apps/examples/Makefile | 20 +++- apps/examples/README.txt | 4 + apps/examples/nx/nx_main.c | 112 ++++++++++++----------- apps/examples/nxhello/nxhello_bkgd.c | 2 +- apps/examples/nxhello/nxhello_main.c | 4 +- apps/examples/nxtext/nxtext_main.c | 36 ++++---- apps/examples/usbstorage/Makefile | 21 ++++- apps/examples/usbstorage/usbstrg_main.c | 156 +++++++++++++++++++++++++------- 9 files changed, 250 insertions(+), 109 deletions(-) (limited to 'apps') diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 712e1e4f7..f771b97fa 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -82,3 +82,7 @@ * apps/examples/nximage: Another super simple graphics example: It just puts the NuttX logo in the center of the display. This example can also be built as an NSH "built-in" command. + * apps/examples/usbstorage: Can now be built as two NSH "built-in" commands: + 'msconn' will connect the USB mass storage device; 'msdis' will disconnect + the USB storage device. + diff --git a/apps/examples/Makefile b/apps/examples/Makefile index 45f05d8db..f5ab34a1c 100644 --- a/apps/examples/Makefile +++ b/apps/examples/Makefile @@ -38,13 +38,29 @@ # Sub-directories SUBDIRS = buttons dhcpd ftpc hello helloxx hidkbd igmp mm mount nettest \ - nsh null nx nxffs nxflat nxhello nximage nxtext stest pashello pipe \ + nsh null nx nxffs nxflat nxhello nximage nxtext ostest pashello pipe \ poll rgmp romfs sendmail serloop thttpd udp uip usbserial usbstorage \ wget wlan # Sub-directories that might need context setup -CNTXTDIRS = nx nxhello nximage nxtext +CNTXTDIRS = + +ifeq ($(CONFIG_EXAMPLES_NX_BUILTIN),y) +CNTXTDIRS += nx +endif +ifeq ($(CONFIG_EXAMPLES_NXHELLO_BUILTIN),y) +CNTXTDIRS += nxhello +endif +ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y) +CNTXTDIRS += nximage +endif +ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y) +CNTXTDIRS += nxtext +endif +ifeq ($(CONFIG_EXAMPLES_USBSTRG_BUILTIN),y) +CNTXTDIRS += usbstorage +endif all: nothing .PHONY: nothing context depend clean distclean diff --git a/apps/examples/README.txt b/apps/examples/README.txt index d234a5549..bef78528e 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -800,6 +800,10 @@ examples/usbstorage Configuration options: + CONFIG_EXAMPLES_USBSTRG_BUILTIN + This example can be built as two NSH "built-in" commands if this option + is selection: 'msconn' will connect the USB mass storage device; 'msdis' + will disconnect the USB storage device. CONFIG_EXAMPLES_USBSTRG_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/apps/examples/nx/nx_main.c b/apps/examples/nx/nx_main.c index 6d85d0fb7..366ec80a4 100644 --- a/apps/examples/nx/nx_main.c +++ b/apps/examples/nx/nx_main.c @@ -231,7 +231,7 @@ static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, hwnd = nx_openwindow(g_hnx, cb, (FAR void *)state); if (!hwnd) { - message("user_start: nx_openwindow failed: %d\n", errno); + message("nxeg_openwindow: nx_openwindow failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENWINDOW; } return hwnd; @@ -245,7 +245,7 @@ static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb, hwnd = nxtk_openwindow(g_hnx, cb, (FAR void *)state); if (!hwnd) { - message("user_start: nxtk_openwindow failed: %d\n", errno); + message("nxeg_openwindow: nxtk_openwindow failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENWINDOW; } return hwnd; @@ -262,7 +262,7 @@ static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *sta int ret = nx_closewindow(hwnd); if (ret < 0) { - message("user_start: nx_closewindow failed: %d\n", errno); + message("nxeg_closewindow: nx_closewindow failed: %d\n", errno); g_exitcode = NXEXIT_NXCLOSEWINDOW; } return ret; @@ -273,7 +273,7 @@ static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *sta int ret = nxtk_closewindow(hwnd); if (ret < 0) { - message("user_start: nxtk_closewindow failed: %d\n", errno); + message("nxeg_closewindow: nxtk_closewindow failed: %d\n", errno); g_exitcode = NXEXIT_NXCLOSEWINDOW; } nxeg_freestate(state); @@ -291,7 +291,7 @@ static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size) int ret = nx_setsize(hwnd, size); if (ret < 0) { - message("user_start: nx_setsize failed: %d\n", errno); + message("nxeg_setsize: nx_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } return ret; @@ -302,7 +302,7 @@ static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size) int ret = nxtk_setsize(hwnd, size); if (ret < 0) { - message("user_start: nxtk_setsize failed: %d\n", errno); + message("nxeg_setsize: nxtk_setsize failed: %d\n", errno); g_exitcode = NXEXIT_NXSETSIZE; } return ret; @@ -319,7 +319,7 @@ static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos int ret = nx_setposition(hwnd, pos); if (ret < 0) { - message("user_start: nx_setposition failed: %d\n", errno); + message("nxeg_setposition: nx_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } return ret; @@ -330,7 +330,7 @@ static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos int ret = nxtk_setposition(hwnd, pos); if (ret < 0) { - message("user_start: nxtk_setposition failed: %d\n", errno); + message("nxeg_setposition: nxtk_setposition failed: %d\n", errno); g_exitcode = NXEXIT_NXSETPOSITION; } return ret; @@ -350,7 +350,7 @@ static inline int nxeq_opentoolbar(NXEGWINDOW hwnd, nxgl_coord_t height, ret = nxtk_opentoolbar(hwnd, height, cb, (FAR void *)state); if (ret < 0) { - message("user_start: nxtk_opentoolbar failed: %d\n", errno); + message("nxeq_opentoolbar: nxtk_opentoolbar failed: %d\n", errno); g_exitcode = NXEXIT_NXOPENTOOLBAR; } return ret; @@ -367,7 +367,7 @@ static inline int nxeg_lower(NXEGWINDOW hwnd) int ret = nx_lower(hwnd); if (ret < 0) { - message("user_start: nx_lower failed: %d\n", errno); + message("nxeg_lower: nx_lower failed: %d\n", errno); g_exitcode = NXEXIT_NXLOWER; } return ret; @@ -378,7 +378,7 @@ static inline int nxeg_lower(NXEGWINDOW hwnd) int ret = nxtk_lower(hwnd); if (ret < 0) { - message("user_start: nxtk_lower failed: %d\n", errno); + message("nxeg_lower: nxtk_lower failed: %d\n", errno); g_exitcode = NXEXIT_NXLOWER; } return ret; @@ -395,7 +395,7 @@ static inline int nxeg_raise(NXEGWINDOW hwnd) int ret = nx_raise(hwnd); if (ret < 0) { - message("user_start: nx_raise failed: %d\n", errno); + message("nxeg_raise: nx_raise failed: %d\n", errno); g_exitcode = NXEXIT_NXRAISE; } return ret; @@ -406,7 +406,7 @@ static inline int nxeg_raise(NXEGWINDOW hwnd) int ret = nxtk_raise(hwnd); if (ret < 0) { - message("user_start: nxtk_raise failed: %d\n", errno); + message("nxeg_raise: nxtk_raise failed: %d\n", errno); g_exitcode = NXEXIT_NXRAISE; } return ret; @@ -490,7 +490,7 @@ static inline int nxeg_suinitialize(void) g_hnx = nx_open(dev); if (!g_hnx) { - message("user_start: nx_open failed: %d\n", errno); + message("nxeg_suinitialize: nx_open failed: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; return ERROR; } @@ -618,10 +618,14 @@ static int nxeg_initialize(void) ****************************************************************************/ #ifdef CONFIG_EXAMPLES_NX_BUILTIN -int nx_main(int argc, char **argv) +# define MAIN_NAME nx_main +# define MAIN_NAME_STRING "nx_main" #else -int user_start(int argc, char *argv[]) +# define MAIN_NAME user_start +# define MAIN_NAME_STRING "user_start" #endif + +int MAIN_NAME(int argc, char *argv[]) { NXEGWINDOW hwnd1; NXEGWINDOW hwnd2; @@ -633,10 +637,10 @@ int user_start(int argc, char *argv[]) /* Initialize */ ret = nxeg_initialize(); - message("user_start: NX handle=%p\n", g_hnx); + message(MAIN_NAME_STRING ": NX handle=%p\n", g_hnx); if (!g_hnx || ret < 0) { - message("user_start: Failed to get NX handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get NX handle: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; goto errout; } @@ -646,29 +650,29 @@ int user_start(int argc, char *argv[]) g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT); if (!g_fonthandle) { - message("user_start: Failed to get font handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ - message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR); + message(MAIN_NAME_STRING ": Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR); color = CONFIG_EXAMPLES_NX_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) { - message("user_start: nx_setbgcolor failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Create window #1 */ - message("user_start: Create window #1\n"); + message(MAIN_NAME_STRING ": Create window #1\n"); nxeg_initstate(&g_wstate[0], 1, CONFIG_EXAMPLES_NX_COLOR1); hwnd1 = nxeg_openwindow(&g_nxcb, &g_wstate[0]); - message("user_start: hwnd1=%p\n", hwnd1); + message(MAIN_NAME_STRING ": hwnd1=%p\n", hwnd1); if (!hwnd1) { goto errout_with_nx; @@ -680,14 +684,14 @@ int user_start(int argc, char *argv[]) { (void)sem_wait(&g_semevent); } - message("user_start: Screen resolution (%d,%d)\n", g_xres, g_yres); + message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_xres, g_yres); /* Set the size of the window 1 */ size.w = g_xres / 2; size.h = g_yres / 2; - message("user_start: Set window #1 size to (%d,%d)\n", size.w, size.h); + message(MAIN_NAME_STRING ": Set window #1 size to (%d,%d)\n", size.w, size.h); ret = nxeg_setsize(hwnd1, &size); if (ret < 0) { @@ -699,7 +703,7 @@ int user_start(int argc, char *argv[]) * actually do them! */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); /* Set the position of window #1 */ @@ -707,7 +711,7 @@ int user_start(int argc, char *argv[]) pt.x = g_xres / 8; pt.y = g_yres / 8; - message("user_start: Set window #1 postion to (%d,%d)\n", pt.x, pt.y); + message(MAIN_NAME_STRING ": Set window #1 postion to (%d,%d)\n", pt.x, pt.y); ret = nxeg_setposition(hwnd1, &pt); if (ret < 0) { @@ -716,13 +720,13 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); /* Open the toolbar */ #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS - message("user_start: Add toolbar to window #1\n"); + message(MAIN_NAME_STRING ": Add toolbar to window #1\n"); ret = nxeq_opentoolbar(hwnd1, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[0]); if (ret < 0) { @@ -731,16 +735,16 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #endif /* Create window #2 */ - message("user_start: Create window #2\n"); + message(MAIN_NAME_STRING ": Create window #2\n"); nxeg_initstate(&g_wstate[1], 2, CONFIG_EXAMPLES_NX_COLOR2); hwnd2 = nxeg_openwindow(&g_nxcb, &g_wstate[1]); - message("user_start: hwnd2=%p\n", hwnd2); + message(MAIN_NAME_STRING ": hwnd2=%p\n", hwnd2); if (!hwnd2) { goto errout_with_hwnd1; @@ -748,12 +752,12 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); /* Set the size of the window 2 == size of window 1*/ - message("user_start: Set hwnd2 size to (%d,%d)\n", size.w, size.h); + message(MAIN_NAME_STRING ": Set hwnd2 size to (%d,%d)\n", size.w, size.h); ret = nxeg_setsize(hwnd2, &size); if (ret < 0) { @@ -762,7 +766,7 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); /* Set the position of window #2 */ @@ -770,7 +774,7 @@ int user_start(int argc, char *argv[]) pt.x = g_xres - size.w - pt.x; pt.y = g_yres - size.h - pt.y; - message("user_start: Set hwnd2 postion to (%d,%d)\n", pt.x, pt.y); + message(MAIN_NAME_STRING ": Set hwnd2 postion to (%d,%d)\n", pt.x, pt.y); ret = nxeg_setposition(hwnd2, &pt); if (ret < 0) { @@ -779,11 +783,11 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS - message("user_start: Add toolbar to window #2\n"); + message(MAIN_NAME_STRING ": Add toolbar to window #2\n"); ret = nxeq_opentoolbar(hwnd2, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[1]); if (ret < 0) { @@ -792,30 +796,30 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #endif /* Give keyboard input to the top window -- should be window #2 */ #ifdef CONFIG_NX_KBD - message("user_start: Send keyboard input: %s\n", g_kbdmsg1); + message(MAIN_NAME_STRING ": Send keyboard input: %s\n", g_kbdmsg1); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg1), g_kbdmsg1); if (ret < 0) { - message("user_start: nx_kbdin failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_kbdin failed: %d\n", errno); goto errout_with_hwnd2; } /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #endif /* Lower window 2 */ - message("user_start: Lower window #2\n"); + message(MAIN_NAME_STRING ": Lower window #2\n"); ret = nxeg_lower(hwnd2); if (ret < 0) { @@ -824,7 +828,7 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); /* Put mouse left-button clicks all over the screen and see who responds */ @@ -834,30 +838,30 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #endif /* Give keyboard input to the top window -- should be window #1 */ #ifdef CONFIG_NX_KBD - message("user_start: Send keyboard input: %s\n", g_kbdmsg2); + message(MAIN_NAME_STRING ": Send keyboard input: %s\n", g_kbdmsg2); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg2), g_kbdmsg2); if (ret < 0) { - message("user_start: nx_kbdin failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_kbdin failed: %d\n", errno); goto errout_with_hwnd2; } /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(1); #endif /* Raise window 2 */ - message("user_start: Raise window #2\n"); + message(MAIN_NAME_STRING ": Raise window #2\n"); ret = nxeg_raise(hwnd2); if (ret < 0) { @@ -872,31 +876,31 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ - message("user_start: Sleeping\n\n"); + message(MAIN_NAME_STRING ": Sleeping\n\n"); sleep(2); /* Close the window 2 */ errout_with_hwnd2: - message("user_start: Close window #2\n"); + message(MAIN_NAME_STRING ": Close window #2\n"); (void)nxeg_closewindow(hwnd2, &g_wstate[1]); /* Close the window1 */ errout_with_hwnd1: - message("user_start: Close window #1\n"); + message(MAIN_NAME_STRING ": Close window #1\n"); (void)nxeg_closewindow(hwnd1, &g_wstate[0]); errout_with_nx: #ifdef CONFIG_NX_MULTIUSER /* Disconnect from the server */ - message("user_start: Disconnect from the server\n"); + message(MAIN_NAME_STRING ": Disconnect from the server\n"); nx_disconnect(g_hnx); #else /* Close the server */ - message("user_start: Close NX\n"); + message(MAIN_NAME_STRING ": Close NX\n"); nx_close(g_hnx); #endif errout: diff --git a/apps/examples/nxhello/nxhello_bkgd.c b/apps/examples/nxhello/nxhello_bkgd.c index 3b609d1f6..09beac952 100644 --- a/apps/examples/nxhello/nxhello_bkgd.c +++ b/apps/examples/nxhello/nxhello_bkgd.c @@ -248,7 +248,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos, */ pos->x = (g_nxhello.xres - width) / 2; - pos->y = (g_nxhello.yres - fbm->metric.height) / 2; + pos->y = (g_nxhello.yres - fontset->mxheight) / 2; } /**************************************************************************** diff --git a/apps/examples/nxhello/nxhello_main.c b/apps/examples/nxhello/nxhello_main.c index 4f6701aa5..38c2e52c2 100644 --- a/apps/examples/nxhello/nxhello_main.c +++ b/apps/examples/nxhello/nxhello_main.c @@ -211,7 +211,7 @@ static inline int nxhello_initialize(void) # define MAIN_NAME_STRING "nxhello_main" #else # define MAIN_NAME user_start -# define MAIN_NAME_STRING "user_start" +# define MAIN_NAME_STRING MAIN_NAME_STRING "" #endif int MAIN_NAME(int argc, char *argv[]) @@ -235,7 +235,7 @@ int MAIN_NAME(int argc, char *argv[]) g_nxhello.hfont = nxf_getfonthandle(NXFONT_DEFAULT); if (!g_nxhello.hfont) { - message("user_start: Failed to get font handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get font handle: %d\n", errno); g_nxhello.code = NXEXIT_FONTOPEN; goto errout; } diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c index a9d9207e6..58d29d33c 100644 --- a/apps/examples/nxtext/nxtext_main.c +++ b/apps/examples/nxtext/nxtext_main.c @@ -233,7 +233,7 @@ static inline int nxtext_suinitialize(void) g_hnx = nx_open(dev); if (!g_hnx) { - message("user_start: nx_open failed: %d\n", errno); + message("nxtext_initialize: nx_open failed: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; return ERROR; } @@ -348,10 +348,14 @@ static int nxtext_initialize(void) ****************************************************************************/ #ifdef CONFIG_EXAMPLES_NXTEXT_BUILTIN -int nxtext_main(int argc, char **argv) +# define MAIN_NAME nxtext_main +# define MAIN_NAME_STRING "nxtext_main" #else -int user_start(int argc, char *argv[]) +# define MAIN_NAME user_start +# define MAIN_NAME_STRING "user_start" #endif + +int MAIN_NAME(int argc, char **argv) { FAR struct nxtext_state_s *bgstate; NXWINDOW hwnd = NULL; @@ -363,10 +367,10 @@ int user_start(int argc, char *argv[]) /* Initialize NX */ ret = nxtext_initialize(); - message("user_start: NX handle=%p\n", g_hnx); + message(MAIN_NAME_STRING ": NX handle=%p\n", g_hnx); if (!g_hnx || ret < 0) { - message("user_start: Failed to get NX handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get NX handle: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; goto errout; } @@ -376,19 +380,19 @@ int user_start(int argc, char *argv[]) g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT); if (!g_fonthandle) { - message("user_start: Failed to get font handle: %d\n", errno); + message(MAIN_NAME_STRING ": Failed to get font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ - message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); + message(MAIN_NAME_STRING ": Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); color = CONFIG_EXAMPLES_NXTEXT_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) { - message("user_start: nx_setbgcolor failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } @@ -399,7 +403,7 @@ int user_start(int argc, char *argv[]) ret = nx_requestbkgd(g_hnx, &g_bgcb, bgstate); if (ret < 0) { - message("user_start: nx_setbgcolor failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } @@ -412,7 +416,7 @@ int user_start(int argc, char *argv[]) { (void)sem_wait(&g_semevent); } - message("user_start: Screen resolution (%d,%d)\n", g_xres, g_yres); + message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_xres, g_yres); /* Now loop, adding text to the background and periodically presenting * a pop-up window. @@ -440,11 +444,11 @@ int user_start(int argc, char *argv[]) /* Give keyboard input to the top window (which should be the pop-up) */ #ifdef CONFIG_NX_KBD - message("user_start: Send keyboard input: %s\n", g_pumsg); + message(MAIN_NAME_STRING ": Send keyboard input: %s\n", g_pumsg); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_pumsg), g_pumsg); if (ret < 0) { - message("user_start: nx_kbdin failed: %d\n", errno); + message(MAIN_NAME_STRING ": nx_kbdin failed: %d\n", errno); goto errout_with_hwnd; } #endif @@ -453,7 +457,7 @@ int user_start(int argc, char *argv[]) { /* Destroy the pop-up window and restart the sequence */ - message("user_start: Close pop-up\n"); + message(MAIN_NAME_STRING ": Close pop-up\n"); (void)nxpu_close(hwnd); popcnt = 0; } @@ -475,7 +479,7 @@ int user_start(int argc, char *argv[]) errout_with_hwnd: if (popcnt >= 3) { - message("user_start: Close pop-up\n"); + message(MAIN_NAME_STRING ": Close pop-up\n"); (void)nxpu_close(hwnd); } @@ -486,12 +490,12 @@ errout_with_nx: #ifdef CONFIG_NX_MULTIUSER /* Disconnect from the server */ - message("user_start: Disconnect from the server\n"); + message(MAIN_NAME_STRING ": Disconnect from the server\n"); nx_disconnect(g_hnx); #else /* Close the server */ - message("user_start: Close NX\n"); + message(MAIN_NAME_STRING ": Close NX\n"); nx_close(g_hnx); #endif errout: diff --git a/apps/examples/usbstorage/Makefile b/apps/examples/usbstorage/Makefile index 39957f141..e821468be 100644 --- a/apps/examples/usbstorage/Makefile +++ b/apps/examples/usbstorage/Makefile @@ -56,12 +56,22 @@ endif ROOTDEPPATH = --dep-path . +# NXTEXT built-in application info + +APPNAME1 = msconn +PRIORITY1 = SCHED_PRIORITY_DEFAULT +STACKSIZE1 = 2048 + +APPNAME2 = msdis +PRIORITY2 = SCHED_PRIORITY_DEFAULT +STACKSIZE2 = 2048 + # Common build VPATH = all: .built -.PHONY: clean depend distclean +.PHONY: context clean depend distclean $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) @@ -75,7 +85,14 @@ $(COBJS): %$(OBJEXT): %.c done ; ) @touch .built -context: +.context: +ifeq ($(CONFIG_EXAMPLES_USBSTRG_BUILTIN),y) + $(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main) + $(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(APPNAME2)_main) + @touch $@ +endif + +context: .context .depend: Makefile $(SRCS) @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep diff --git a/apps/examples/usbstorage/usbstrg_main.c b/apps/examples/usbstorage/usbstrg_main.c index 3f0cf57e5..76e864fee 100644 --- a/apps/examples/usbstorage/usbstrg_main.c +++ b/apps/examples/usbstorage/usbstrg_main.c @@ -93,6 +93,17 @@ * Private Data ****************************************************************************/ +/* This is the handle that references to this particular USB storage driver + * instance. It is only needed if the USB mass storage device example is + * built using CONFIG_EXAMPLES_USBSTRG_BUILTIN. In this case, the value + * of the driver handle must be remembered between the 'msconn' and 'msdis' + * commands. + */ + +#ifdef CONFIG_EXAMPLES_USBSTRG_BUILTIN +static FAR void *g_mshandle; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -284,72 +295,104 @@ static int usbstrg_enumerate(struct usbtrace_s *trace, void *arg) ****************************************************************************/ /**************************************************************************** - * user_start + * user_start/msconn_main + * + * Description: + * This is the main program that configures the USB mass storage device + * and exports the LUN(s). If CONFIG_EXAMPLES_USBSTRG_BUILTIN is defined + * in the NuttX configuration, then this program can be executed by + * entering the "msconn" command at the NSH console. + * ****************************************************************************/ -int user_start(int argc, char *argv[]) +#ifdef CONFIG_EXAMPLES_USBSTRG_BUILTIN +# define MAIN_NAME msconn_main +# define MAIN_NAME_STRING "msconn" +#else +# define MAIN_NAME user_start +# define MAIN_NAME_STRING "user_start" +#endif + +int MAIN_NAME(int argc, char *argv[]) { - void *handle; + FAR void *handle; int ret; + /* If this program is implemented as the NSH 'msconn' command, then we need to + * do a little error checking to assure that we are not being called re-entrantly. + */ + +#ifdef CONFIG_EXAMPLES_USBSTRG_BUILTIN + + /* Check if there is a non-NULL USB mass storage device handle (meaning that the + * USB mass storage device is already configured). + */ + + if (g_mshandle) + { + message(MAIN_NAME_STRING ": ERROR: Already connected\n"); + return 1; + } +#endif + /* Initialize USB trace output IDs */ usbtrace_enable(TRACE_BITSET); /* Register block drivers (architecture-specific) */ - message("user_start: Creating block drivers\n"); + message(MAIN_NAME_STRING ": Creating block drivers\n"); ret = usbstrg_archinitialize(); if (ret < 0) { - message("user_start: usbstrg_archinitialize failed: %d\n", -ret); - return 1; + message(MAIN_NAME_STRING ": usbstrg_archinitialize failed: %d\n", -ret); + return 2; } /* Then exports the LUN(s) */ - message("user_start: Configuring with NLUNS=%d\n", CONFIG_EXAMPLES_USBSTRG_NLUNS); + message(MAIN_NAME_STRING ": Configuring with NLUNS=%d\n", CONFIG_EXAMPLES_USBSTRG_NLUNS); ret = usbstrg_configure(CONFIG_EXAMPLES_USBSTRG_NLUNS, &handle); if (ret < 0) { - message("user_start: usbstrg_configure failed: %d\n", -ret); + message(MAIN_NAME_STRING ": usbstrg_configure failed: %d\n", -ret); usbstrg_uninitialize(handle); - return 2; + return 3; } - message("user_start: handle=%p\n", handle); + message(MAIN_NAME_STRING ": handle=%p\n", handle); - message("user_start: Bind LUN=0 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH1); + message(MAIN_NAME_STRING ": Bind LUN=0 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH1); ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH1, 0, 0, 0, false); if (ret < 0) { - message("user_start: usbstrg_bindlun failed for LUN 1 using %s: %d\n", + message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 1 using %s: %d\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH1, -ret); usbstrg_uninitialize(handle); - return 2; + return 4; } #if CONFIG_EXAMPLES_USBSTRG_NLUNS > 1 - message("user_start: Bind LUN=1 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH2); + message(MAIN_NAME_STRING ": Bind LUN=1 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH2); ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH2, 1, 0, 0, false); if (ret < 0) { - message("user_start: usbstrg_bindlun failed for LUN 2 using %s: %d\n", + message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 2 using %s: %d\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH2, -ret); usbstrg_uninitialize(handle); - return 3; + return 5; } #if CONFIG_EXAMPLES_USBSTRG_NLUNS > 2 - message("user_start: Bind LUN=2 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH3); + message(MAIN_NAME_STRING ": Bind LUN=2 to %s\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH3); ret = usbstrg_bindlun(handle, CONFIG_EXAMPLES_USBSTRG_DEVPATH3, 2, 0, 0, false); if (ret < 0) { - message("user_start: usbstrg_bindlun failed for LUN 3 using %s: %d\n", + message(MAIN_NAME_STRING ": usbstrg_bindlun failed for LUN 3 using %s: %d\n", CONFIG_EXAMPLES_USBSTRG_DEVPATH3, -ret); usbstrg_uninitialize(handle); - return 4; + return 6; } #endif @@ -358,34 +401,83 @@ int user_start(int argc, char *argv[]) ret = usbstrg_exportluns(handle); if (ret < 0) { - message("user_start: usbstrg_exportluns failed: %d\n", -ret); + message(MAIN_NAME_STRING ": usbstrg_exportluns failed: %d\n", -ret); usbstrg_uninitialize(handle); - return 5; + return 7; } - /* Now just hang around and monitor the USB storage activity */ + /* It this program was configued as an NSH command, then just exit now. + * Also, if signals are not enabled (and, hence, sleep() is not supported. + * then we have not real option but to exit now. + */ + +#if !defined(CONFIG_EXAMPLES_USBSTRG_BUILTIN) && !defined(CONFIG_DISABLE_SIGNALS) + + /* Otherwise, this thread will hang around and monitor the USB storage activity */ -#ifndef CONFIG_DISABLE_SIGNALS for (;;) { msgflush(); sleep(5); -#ifdef CONFIG_USBDEV_TRACE +# ifdef CONFIG_USBDEV_TRACE message("\nuser_start: USB TRACE DATA:\n"); ret = usbtrace_enumerate(usbstrg_enumerate, NULL); if (ret < 0) { - message("user_start: usbtrace_enumerate failed: %d\n", -ret); + message(MAIN_NAME_STRING ": usbtrace_enumerate failed: %d\n", -ret); usbstrg_uninitialize(handle); - return 6; + return 8; } -#else - message("user_start: Still alive\n"); -#endif +# else + message(MAIN_NAME_STRING ": Still alive\n"); +# endif } -#else - message("user_start: Exiting\n"); - #endif +#elif defined(CONFIG_EXAMPLES_USBSTRG_BUILTIN) + + /* Return the USB mass storage device handle so it can be used by the 'misconn' + * command. + */ + + message(MAIN_NAME_STRING ": Connected\n"); + g_mshandle = handle; + +#else /* defined(CONFIG_DISABLE_SIGNALS) */ + + /* Just exit */ + + message(MAIN_NAME_STRING ": Exiting\n"); + +#endif + return 0; } +/**************************************************************************** + * msdis_main + * + * Description: + * This is a program entry point that will disconnet the USB mass storage + * device. This program is only available if CONFIG_EXAMPLES_USBSTRG_BUILTIN + * is defined in the NuttX configuration. In that case, this program can + * be executed by entering the "msdis" command at the NSH console. + * + ****************************************************************************/ + +#ifdef CONFIG_EXAMPLES_USBSTRG_BUILTIN +int msdis_main(int argc, char *argv[]) +{ + /* First check if the USB mass storage device is already connected */ + + if (!g_mshandle) + { + message("msdis: ERROR: Not connected\n"); + return 1; + } + + /* Then disconnect the device and uninitialize the USB mass storage driver */ + + usbstrg_uninitialize(g_mshandle); + g_mshandle = NULL; + message("msdis: Disconnected\n"); +} +#endif -- cgit v1.2.3