From f3ce29aa9b591ff1b6a697484528f7340580ace7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 29 Dec 2013 11:11:48 -0600 Subject: Add nx_start() to simplify starting the NX server from within the RTOS --- NxWidgets/Kconfig | 4 +- NxWidgets/libnxwidgets/include/cnxserver.hxx | 2 +- NxWidgets/libnxwidgets/src/cnxserver.cxx | 6 +- apps/NxWidgets/Kconfig | 4 +- nuttx/ChangeLog | 2 + nuttx/graphics/Kconfig | 60 +++++++- nuttx/graphics/nxmu/Make.defs | 4 + nuttx/graphics/nxmu/nx_start.c | 208 +++++++++++++++++++++++++++ nuttx/graphics/nxmu/nxmu_kbdin.c | 3 +- nuttx/include/nuttx/nx/nx.h | 29 ++++ 10 files changed, 308 insertions(+), 14 deletions(-) create mode 100644 nuttx/graphics/nxmu/nx_start.c diff --git a/NxWidgets/Kconfig b/NxWidgets/Kconfig index b6ac4fb7d..2d1467425 100644 --- a/NxWidgets/Kconfig +++ b/NxWidgets/Kconfig @@ -28,8 +28,7 @@ config NXWIDGETS_FLICKERFREE config NXWIDGETS_EXTERNINIT bool "External display Initialization" - default 0 - depends on NXWIDGET_SERVERINIT + default n ---help--- Define to support external display initialization. @@ -44,6 +43,7 @@ config NXWIDGETS_DEVNO config NXWIDGETS_VPLANE int "Plane Number" default 0 + depends on !NX_LCDDRIVER && !NXWIDGETS_EXTERNINIT ---help--- Only a single video plane is supported. Default: 0 diff --git a/NxWidgets/libnxwidgets/include/cnxserver.hxx b/NxWidgets/libnxwidgets/include/cnxserver.hxx index c6ca21bfc..f70dbdbdb 100644 --- a/NxWidgets/libnxwidgets/include/cnxserver.hxx +++ b/NxWidgets/libnxwidgets/include/cnxserver.hxx @@ -95,7 +95,7 @@ namespace NXWidgets * serializes the multi-threaded accesses to the display. */ -#ifdef CONFIG_NX_MULTIUSER +#if defined(CONFIG_NX_MULTIUSER) && defined(CONFIG_NXWIDGET_SERVERINIT) static int server(int argc, char *argv[]); #endif diff --git a/NxWidgets/libnxwidgets/src/cnxserver.cxx b/NxWidgets/libnxwidgets/src/cnxserver.cxx index 84f6701da..6adbc20a5 100644 --- a/NxWidgets/libnxwidgets/src/cnxserver.cxx +++ b/NxWidgets/libnxwidgets/src/cnxserver.cxx @@ -201,7 +201,6 @@ bool CNxServer::connect(void) { struct sched_param param; pthread_t thread; - pid_t serverId; int ret; // Set the client task priority @@ -218,8 +217,9 @@ bool CNxServer::connect(void) // Start the server task gvdbg("CNxServer::connect: Starting server task\n"); - serverId = TASK_CREATE("NX Server", CONFIG_NXWIDGETS_SERVERPRIO, - CONFIG_NXWIDGETS_SERVERSTACK, server, (FAR char * const *)0); + pid_t serverId = TASK_CREATE("NX Server", CONFIG_NXWIDGETS_SERVERPRIO, + CONFIG_NXWIDGETS_SERVERSTACK, server, + (FAR char * const *)0); if (serverId < 0) { gdbg("NxServer::connect: Failed to create nx_servertask task: %d\n", errno); diff --git a/apps/NxWidgets/Kconfig b/apps/NxWidgets/Kconfig index b6ac4fb7d..2d1467425 100644 --- a/apps/NxWidgets/Kconfig +++ b/apps/NxWidgets/Kconfig @@ -28,8 +28,7 @@ config NXWIDGETS_FLICKERFREE config NXWIDGETS_EXTERNINIT bool "External display Initialization" - default 0 - depends on NXWIDGET_SERVERINIT + default n ---help--- Define to support external display initialization. @@ -44,6 +43,7 @@ config NXWIDGETS_DEVNO config NXWIDGETS_VPLANE int "Plane Number" default 0 + depends on !NX_LCDDRIVER && !NXWIDGETS_EXTERNINIT ---help--- Only a single video plane is supported. Default: 0 diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index a8d5ffa68..6f48d1ea3 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -6332,4 +6332,6 @@ * Move graphics/nxtk to libnx/nxtk (2013-12-28). * syscalls: Need to add sem_timedwait() (2013-12-28) * Move more files from graphics/nxmu to libnx/nxmu (2013-12-29). + * graphics/nxmu/nx_start.c: NX server start-up wrapper function to + simplify starting the NX server from within the RTOS (2013-12-29). diff --git a/nuttx/graphics/Kconfig b/nuttx/graphics/Kconfig index 7d34b872d..aacd1e8c1 100644 --- a/nuttx/graphics/Kconfig +++ b/nuttx/graphics/Kconfig @@ -168,7 +168,7 @@ config NXTK_BORDERCOLOR3 NXTK_BORDERCOLOR2 is the shadow side color and so is normally darker. NXTK_BORDERCOLOR3 is the shiny side color and so is normally brighter. -endif +endif # !NXTK_DEFAULT_BORDERCOLORS endmenu config NXTK_AUTORAISE @@ -413,7 +413,7 @@ config NXCONSOLE_NPOLLWAITERS The number of threads that can be waiting for read data available. Default: 4 -endif +endif # NXCONSOLE comment "NX Multi-user only options" @@ -450,5 +450,57 @@ config NX_MXCLIENTMSGS flooding of the client or server with too many messages (PREALLOC_MQ_MSGS controls how many messages are pre-allocated). -endif -endif +config NX_NXSTART + bool "nx_start()" + default n + ---help--- + If this option is selected, then the nx_start() interface will be + built. The nx_start() interface provides a single call to initialize + and start the NX server. + +if NX_NXSTART + +config NXSTART_EXTERNINIT + bool "External display Initialization" + default n + ---help--- + Define to support external display initialization by platform- + specific code. This this option is defined, then nx_start() will + call up_nxdrvinit(CONFIG_NXSTART_DEVNO) to initialize the graphics + device. This option is necessary if display is used that cannot be + initialized using the standard LCD or framebuffer interfaces. + +config NXSTART_SERVERPRIO + int "NX Server priority" + default 110 + ---help--- + Priority of the NX server. This applies only if NX is configured in + multi-user mode (NX_MULTIUSER=y). Default: 110. + + NOTE: NXSTART_SERVERPRIO should have a relatively high priority to + avoid data overrun race conditions. + +config NXSTART_SERVERSTACK + int "NX Server Stack Size" + default 2048 + ---help--- + NX server thread stack size (in multi-user mode). Default 2048 + +config NXSTART_DEVNO + int "LCD Device Number" + default 0 + depends on NX_LCDDRIVER || NXSTART_EXTERNINIT + ---help--- + LCD device number (in case there are more than one LCDs connected). + Default: 0 + +config NXSTART_VPLANE + int "Plane Number" + default 0 + depends on !NX_LCDDRIVER && !NXSTART_EXTERNINIT + ---help--- + Only a single video plane is supported. Default: 0 + +endif # NX_NXSTART +endif # NX_MULTIUSER +endif # NX diff --git a/nuttx/graphics/nxmu/Make.defs b/nuttx/graphics/nxmu/Make.defs index 2f443c20f..2832f034e 100644 --- a/nuttx/graphics/nxmu/Make.defs +++ b/nuttx/graphics/nxmu/Make.defs @@ -38,3 +38,7 @@ NX_ASRCS = NX_CSRCS += nxmu_kbdin.c nxmu_mouse.c nxmu_openwindow.c nxmu_redrawreq.c NX_CSRCS += nxmu_releasebkgd.c nxmu_requestbkgd.c nxmu_reportposition.c NX_CSRCS += nxmu_sendclient.c nxmu_sendclientwindow.c nxmu_server.c + +ifeq ($(CONFIG_NX_NXSTART),y) +NX_CSRCS += nx_start.c +endif diff --git a/nuttx/graphics/nxmu/nx_start.c b/nuttx/graphics/nxmu/nx_start.c new file mode 100644 index 000000000..a15316d04 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_start.c @@ -0,0 +1,208 @@ +/**************************************************************************** + * graphics/nxmu/nx_start.c + * + * Copyright (C) 2013 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 +#include +#include +#include + +#include + +#include "nxfe.h" + +#ifdef CONFIG_NX_NXSTART + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_servertask + * + * Description: + * NX server thread. This is the entry point into the server thread that + * serializes the multi-threaded accesses to the display. + * + * Input Parameters: + * Standard task start-up parameters (none of which are used) + * + * Returned Value: + * This function does not normally return but may exit with EXIT_FAILURE + * under certain error conditions. + * + ****************************************************************************/ + +int nx_servertask(int argc, char *argv[]) +{ + FAR NX_DRIVERTYPE *dev; + int ret; + +#if defined(CONFIG_NXSTART_EXTERNINIT) + /* Use external graphics driver initialization */ + + dev = up_nxdrvinit(CONFIG_NXSTART_DEVNO); + if (!dev) + { + gdbg("ERROR: up_nxdrvinit failed, devno=%d\n", CONFIG_NXSTART_DEVNO); + return EXIT_FAILURE; + } + +#elif defined(CONFIG_NX_LCDDRIVER) + /* Initialize the LCD device */ + + ret = up_lcdinitialize(); + if (ret < 0) + { + gdbg("ERROR: up_lcdinitialize failed: %d\n", ret); + return EXIT_FAILURE; + } + + /* Get the device instance */ + + dev = up_lcdgetdev(CONFIG_NXSTART_DEVNO); + if (!dev) + { + gdbg("ERROR: up_lcdgetdev failed, devno=%d\n", CONFIG_NXSTART_DEVNO); + return EXIT_FAILURE; + } + + /* Turn the LCD on at 75% power */ + + (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4)); + +#else /* CONFIG_NX_LCDDRIVER */ + /* Initialize the frame buffer device */ + + ret = up_fbinitialize(); + if (ret < 0) + { + gdbg("ERROR: up_fbinitialize failed: %d\n", ret); + return EXIT_FAILURE; + } + + dev = up_fbgetvplane(CONFIG_NXSTART_VPLANE); + if (!dev) + { + gdbg("ERROR: up_fbgetvplane failed, vplane=%d\n", CONFIG_NXSTART_VPLANE); + return EXIT_FAILURE; + } + +#endif /* CONFIG_NX_LCDDRIVER */ + + /* Then start the server (nx_run does not normally retun) */ + + ret = nx_run(dev); + gvdbg("nx_run returned: %d\n", errno); + return EXIT_FAILURE; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_start + * + * Description: + * nx_start() provides a wrapper function to simplify and standardize the + * starting of the NX server. + * + * NOTE: Currently, many applications include logic to start the NX + * server from application initialization logic. That, of course, cannot + * work in the NuttX kernel build because the resources required by the + * NX server are private to the kernel mode logic. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) is returned on success. This indicates that the NX server + * has been successfully started, is running, and waiting to accept + * connections from NX clients. + * + * A negated errno value is returned on failure. The errno value indicates + * the nature of the failure. + * + ****************************************************************************/ + +int nx_start(void) +{ + pid_t server; + + /* Start the server task */ + + gvdbg("Starting server task\n"); + server = TASK_CREATE("NX Server", CONFIG_NXSTART_SERVERPRIO, + CONFIG_NXSTART_SERVERSTACK, nx_servertask, + (FAR char * const *)0); + if (server < 0) + { + int errcode = errno; + DEBUGASSERT(errcode > 0); + + gdbg("ERROR: Failed to create nx_servertask task: %d\n", errcode); + return -errcode; + } + + /* Wait a bit to let the server get started */ + + usleep(50*1000); + return OK; +} + +#endif /* CONFIG_NX_NXSTART */ diff --git a/nuttx/graphics/nxmu/nxmu_kbdin.c b/nuttx/graphics/nxmu/nxmu_kbdin.c index f156a4151..1486a4d2b 100644 --- a/nuttx/graphics/nxmu/nxmu_kbdin.c +++ b/nuttx/graphics/nxmu/nxmu_kbdin.c @@ -78,7 +78,7 @@ /**************************************************************************** * Name: nxmu_kbdin * - * Descripton: + * Description: * New keyboard data has been received from the thread or interrupt * handler that manages some kind of keyboard/keypad hardware. Route that * positional data to the appropriate window client. @@ -116,4 +116,3 @@ void nxmu_kbdin(FAR struct nxfe_state_s *fe, uint8_t nch, FAR uint8_t *ch) } #endif /* CONFIG_NX_KBD */ - diff --git a/nuttx/include/nuttx/nx/nx.h b/nuttx/include/nuttx/nx/nx.h index e1357a342..27c738d41 100644 --- a/nuttx/include/nuttx/nx/nx.h +++ b/nuttx/include/nuttx/nx/nx.h @@ -269,6 +269,35 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev); # define nx_run(dev) nx_runinstance(NX_DEFAULT_SERVER_MQNAME, dev) #endif +/**************************************************************************** + * Name: nx_start + * + * Description: + * nx_start() provides a wrapper function to simplify and standardize the + * starting of the NX server. + * + * NOTE: Currently, many applications include logic to start the NX + * server from application initialization logic. That, of course, cannot + * work in the NuttX kernel build because the resources required by the + * NX server are private to the kernel mode logic. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero (OK) is returned on success. This indicates that the NX server + * has been successfully started, is running, and waiting to accept + * connections from NX clients. + * + * A negated errno value is returned on failure. The errno value indicates + * the nature of the failure. + * + ****************************************************************************/ + +#if defined(CONFIG_NX_MULTIUSER) && defined(CONFIG_NX_START) +int nx_start(void); +#endif + /**************************************************************************** * Name:nx_connectinstance (and nx_connect macro) * -- cgit v1.2.3