summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-12-29 11:11:48 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-12-29 11:11:48 -0600
commitf3ce29aa9b591ff1b6a697484528f7340580ace7 (patch)
tree69b85fc081c232b5ed806b06e8d0f750b42cbdea /nuttx
parent513671256fe287033b8874d352fdf34bf6a14bea (diff)
downloadnuttx-f3ce29aa9b591ff1b6a697484528f7340580ace7.tar.gz
nuttx-f3ce29aa9b591ff1b6a697484528f7340580ace7.tar.bz2
nuttx-f3ce29aa9b591ff1b6a697484528f7340580ace7.zip
Add nx_start() to simplify starting the NX server from within the RTOS
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/graphics/Kconfig60
-rw-r--r--nuttx/graphics/nxmu/Make.defs4
-rw-r--r--nuttx/graphics/nxmu/nx_start.c208
-rw-r--r--nuttx/graphics/nxmu/nxmu_kbdin.c3
-rw-r--r--nuttx/include/nuttx/nx/nx.h29
6 files changed, 300 insertions, 6 deletions
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 <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/nx/nx.h>
+
+#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
@@ -270,6 +270,35 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *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)
*
* Description: