examples/nxhello now supports only multiuser mode.

This commit is contained in:
Gregory Nutt 2017-10-14 14:18:45 -06:00
parent 47dabf17aa
commit 7e151940cc
8 changed files with 169 additions and 181 deletions

View File

@ -7,6 +7,7 @@ config EXAMPLES_NX
bool "NX graphics example"
default n
depends on NX_MULTIUSER
select LIB_BOARDCTL
---help---
Enable the NX graphics example

View File

@ -56,13 +56,8 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#ifdef CONFIG_NX_LCDDRIVER
# include <nuttx/lcd/lcd.h>
#else
# include <nuttx/video/fb.h>
# ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
# endif
#ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
#endif
#include <nuttx/nx/nx.h>

View File

@ -6,24 +6,28 @@
config EXAMPLES_NXHELLO
bool "NX graphics \"Hello, World!\" example"
default n
depends on NX_MULTIUSER
select LIB_BOARDCTL
---help---
Enable the NX graphics \"Hello, World!\" example
if EXAMPLES_NXHELLO
config EXAMPLES_NXHELLO_VPLANE
int "Video Plane"
default 0
config EXAMPLES_NXHELLO_PROGNAME
string "NX Hello Program name"
default "nxhello"
depends on BUILD_KERNEL
---help---
The plane to select from the framebuffer driver for use in the test.
Default: 0
This is the name of the program that will be use when the NSH ELF
program is installed.
config EXAMPLES_NXHELLO_DEVNO
int "Video Device Number"
default 0
---help---
The LCD device to select from the LCD driver for use in the test:
Default: 0
config EXAMPLES_NXHELLO_PRIORITY
int "NX Hello task priority"
default 100
config EXAMPLES_NXHELLO_STACKSIZE
int "NX Hello stack size"
default 2048
config EXAMPLES_NXHELLO_BPP
int "Bits-Per-Pixel"
@ -32,7 +36,6 @@ config EXAMPLES_NXHELLO_BPP
Pixels per pixel to use. Valid options include 1, 2, 4, 8, 16, 24,
and 32. Default is 32.
comment "Example Color Configuration"
config EXAMPLES_NXHELLO_DEFAULT_COLORS
@ -74,25 +77,36 @@ config EXAMPLES_NXHELLO_FONTID
endif
config EXAMPLES_NXHELLO_EXTERNINIT
bool "External Device Initialization"
default n
depends on LIB_BOARDCTL
select BOARDCTL_GRAPHICS
comment "NX Server Options"
config EXAMPLES_NXHELLO_LISTENER_STACKSIZE
int "NX Server/Listener Stack Size"
default 2048
---help---
The driver for the graphics device on this platform requires some
unusual initialization. This is the case, for example, for SPI LCD/OLED
devices. If this configuration is selected, then the platform code
must provide an LCD initialization function with a prototype like:
The stacksize to use when creating the NX server. Default 2048
#ifdef CONFIG_NX_LCDDRIVER
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno);
#else
FAR struct fb_vtable_s *board_graphics_setup(unsigned int devno);
#endif
config EXAMPLES_NXHELLO_CLIENTPRIO
int "Client Priority"
default 100
---help---
The client priority. Default: 100
and must also define: CONFIG_LIB_BOARDCTL=y and
CONFIG_BOARDCTL_GRAPHICS=y so that the boardctl() interface
will be available in order to access this function.
config EXAMPLES_NXHELLO_SERVERPRIO
int "Server Priority"
default 120
---help---
The server priority. Default: 120
config EXAMPLES_NXHELLO_LISTENERPRIO
int "Listener Priority"
default 80
---help---
The priority of the event listener thread. Default 80.
config EXAMPLES_NXHELLO_NOTIFYSIGNO
int "Notify Signal Number"
default 4
---help---
The signal number to use with nx_eventnotify(). Default: 4
endif

View File

@ -38,16 +38,19 @@
# NuttX NX Graphics Example.
ASRCS =
CSRCS = nxhello_bkgd.c
CSRCS = nxhello_bkgd.c nxhello_listener.c
MAINSRC = nxhello_main.c
CONFIG_XYZ_PROGNAME ?= nxhello$(EXEEXT)
PROGNAME = $(CONFIG_XYZ_PROGNAME)
CONFIG_EXAMPLES_NXHELLO_PROGNAME ?= nxhello$(EXEEXT)
PROGNAME = $(CONFIG_EXAMPLES_NXHELLO_PROGNAME)
# NXHELLO built-in application info
CONFIG_EXAMPLES_NXHELLO_PRIORITY ?= SCHED_PRIORITY_DEFAULT
CONFIG_EXAMPLES_NXHELLO_STACKSIZE ?= 2048
APPNAME = nxhello
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
PRIORITY = $(CONFIG_EXAMPLES_NXHELLO_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_NXHELLO_STACKSIZE)
include $(APPDIR)/Application.mk

View File

@ -60,12 +60,14 @@
# error "NX is not enabled (CONFIG_NX)"
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_VPLANE
# define CONFIG_EXAMPLES_NXHELLO_VPLANE 0
#ifndef CONFIG_NX_MULTIUSER
# error "Multi-user NX support is required (CONFIG_NX_MULTIUSER=y)"
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_BPP
# define CONFIG_EXAMPLES_NXHELLO_BPP 32
/* If not specified, assume that the hardware supports one video plane */
#if CONFIG_NX_NPLANES != 1
# error "Only CONFIG_NX_NPLANES==1 supported"
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_BGCOLOR
@ -96,6 +98,35 @@
# endif
#endif
/* Multi-user NX support */
#ifdef CONFIG_DISABLE_MQUEUE
# error "The multi-threaded example requires MQ support (CONFIG_DISABLE_MQUEUE=n)"
#endif
#ifdef CONFIG_DISABLE_SIGNALS
# error "This example requires signal support (CONFIG_DISABLE_SIGNALS=n)"
#endif
#ifdef CONFIG_DISABLE_PTHREAD
# error "This example requires pthread support (CONFIG_DISABLE_PTHREAD=n)"
#endif
#ifndef CONFIG_NX_BLOCKING
# error "This example depends on CONFIG_NX_BLOCKING"
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_LISTENER_STACKSIZE
# define CONFIG_EXAMPLES_NXHELLO_LISTENER_STACKSIZE 2048
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_LISTENERPRIO
# define CONFIG_EXAMPLES_NXHELLO_LISTENERPRIO 100
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_CLIENTPRIO
# define CONFIG_EXAMPLES_NXHELLO_CLIENTPRIO 100
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_SERVERPRIO
# define CONFIG_EXAMPLES_NXHELLO_SERVERPRIO 120
#endif
#ifndef CONFIG_EXAMPLES_NXHELLO_NOTIFYSIGNO
# define CONFIG_EXAMPLES_NXHELLO_NOTIFYSIGNO 4
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@ -103,12 +134,7 @@
enum exitcode_e
{
NXEXIT_SUCCESS = 0,
NXEXIT_EXTINITIALIZE,
NXEXIT_FBINITIALIZE,
NXEXIT_FBGETVPLANE,
NXEXIT_LCDINITIALIZE,
NXEXIT_LCDGETDEV,
NXEXIT_NXOPEN,
NXEXIT_INIT,
NXEXIT_FONTOPEN,
NXEXIT_NXREQUESTBKGD,
NXEXIT_NXSETBGCOLOR
@ -142,6 +168,7 @@ struct nxhello_data_s
NXHANDLE hnx;
NXHANDLE hbkgd;
NXHANDLE hfont;
bool connected;
/* The screen resolution */
@ -149,7 +176,7 @@ struct nxhello_data_s
nxgl_coord_t yres;
volatile bool havepos;
sem_t sem;
sem_t eventsem;
volatile int code;
};
@ -169,6 +196,10 @@ extern const struct nx_callback_s g_nxhellocb;
* Public Function Prototypes
****************************************************************************/
/* NX event listener */
FAR void *nxhello_listener(FAR void *arg);
/* Background window interfaces */
void nxhello_hello(NXWINDOW hwnd);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* examples/nxhello/nxhello_bkgd.c
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -173,7 +173,7 @@ static void nxhello_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
g_nxhello.yres = bounds->pt2.y + 1;
g_nxhello.havepos = true;
sem_post(&g_nxhello.sem);
sem_post(&g_nxhello.eventsem);
ginfo("Have xres=%d yres=%d\n", g_nxhello.xres, g_nxhello.yres);
}
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* examples/nxhello/nxhello_main.c
*
* Copyright (C) 2011, 2015-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2015-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -56,13 +56,8 @@
#include <nuttx/arch.h>
#include <nuttx/board.h>
#ifdef CONFIG_NX_LCDDRIVER
# include <nuttx/lcd/lcd.h>
#else
# include <nuttx/video/fb.h>
# ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
# endif
#ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
#endif
#include <nuttx/nx/nx.h>
@ -71,49 +66,21 @@
#include "nxhello.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* If not specified, assume that the hardware supports one video plane */
#ifndef CONFIG_EXAMPLES_NXHELLO_VPLANE
# define CONFIG_EXAMPLES_NXHELLO_VPLANE 0
#endif
/* If not specified, assume that the hardware supports one LCD device */
#ifndef CONFIG_EXAMPLES_NXHELLO_DEVNO
# define CONFIG_EXAMPLES_NXHELLO_DEVNO 0
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
struct nxhello_data_s g_nxhello =
{
NULL, /* hnx */
NULL, /* hbkgd */
NULL, /* hfont */
0, /* xres */
0, /* yres */
false, /* havpos */
{ 0 }, /* sem */
NXEXIT_SUCCESS /* exit code */
NULL, /* hnx */
NULL, /* hbkgd */
NULL, /* hfont */
false, /* connected */
0, /* xres */
0, /* yres */
false, /* havpos */
SEM_INITIALIZER(0), /* sem */
NXEXIT_SUCCESS /* exit code */
};
/****************************************************************************
@ -126,106 +93,80 @@ struct nxhello_data_s g_nxhello =
static inline int nxhello_initialize(void)
{
FAR NX_DRIVERTYPE *dev;
struct sched_param param;
pthread_t thread;
int ret;
#if defined(CONFIG_EXAMPLES_NXHELLO_EXTERNINIT)
struct boardioc_graphics_s devinfo;
/* Set the client task priority */
/* Use external graphics driver initialization */
printf("nxhello_initialize: Initializing external graphics device\n");
devinfo.devno = CONFIG_EXAMPLES_NXHELLO_DEVNO;
devinfo.dev = NULL;
ret = boardctl(BOARDIOC_GRAPHICS_SETUP, (uintptr_t)&devinfo);
param.sched_priority = CONFIG_EXAMPLES_NXHELLO_CLIENTPRIO;
ret = sched_setparam(0, &param);
if (ret < 0)
{
printf("nxhello_initialize: boardctl failed, devno=%d: %d\n",
CONFIG_EXAMPLES_NXHELLO_DEVNO, errno);
g_nxhello.code = NXEXIT_EXTINITIALIZE;
printf("nxhello_initialize: sched_setparam failed: %d\n" , ret);
return ERROR;
}
dev = devinfo.dev;
/* Start the NX server kernel thread */
#elif defined(CONFIG_NX_LCDDRIVER)
/* Initialize the LCD device */
printf("nxhello_initialize: Initializing LCD\n");
ret = board_lcd_initialize();
ret = boardctl(BOARDIOC_NX_START, 0);
if (ret < 0)
{
printf("nxhello_initialize: board_lcd_initialize failed: %d\n", -ret);
g_nxhello.code = NXEXIT_LCDINITIALIZE;
printf("nxhello_initialize: Failed to start the NX server: %d\n", errno);
return ERROR;
}
/* Get the device instance */
/* Connect to the server */
dev = board_lcd_getdev(CONFIG_EXAMPLES_NXHELLO_DEVNO);
if (!dev)
g_nxhello.hnx = nx_connect();
if (g_nxhello.hnx)
{
printf("nxhello_initialize: board_lcd_getdev failed, devno=%d\n",
CONFIG_EXAMPLES_NXHELLO_DEVNO);
g_nxhello.code = NXEXIT_LCDGETDEV;
return ERROR;
}
/* Turn the LCD on at 75% power */
(void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
#else
/* Initialize the frame buffer device */
printf("nxhello_initialize: Initializing framebuffer\n");
ret = up_fbinitialize(0);
if (ret < 0)
{
printf("nxhello_initialize: up_fbinitialize failed: %d\n", -ret);
g_nxhello.code = NXEXIT_FBINITIALIZE;
return ERROR;
}
dev = up_fbgetvplane(0, CONFIG_EXAMPLES_NXHELLO_VPLANE);
if (!dev)
{
printf("nxhello_initialize: up_fbgetvplane failed, vplane=%d\n",
CONFIG_EXAMPLES_NXHELLO_VPLANE);
g_nxhello.code = NXEXIT_FBGETVPLANE;
return ERROR;
}
#endif
/* Then open NX */
printf("nxhello_initialize: Open NX\n");
g_nxhello.hnx = nx_open(dev);
if (!g_nxhello.hnx)
{
printf("nxhello_initialize: nx_open failed: %d\n", errno);
g_nxhello.code = NXEXIT_NXOPEN;
return ERROR;
}
pthread_attr_t attr;
#ifdef CONFIG_VNCSERVER
/* Setup the VNC server to support keyboard/mouse inputs */
/* Setup the VNC server to support keyboard/mouse inputs */
ret = vnc_default_fbinitialize(0, g_nxhello.hnx);
if (ret < 0)
ret = vnc_default_fbinitialize(0, g_nxhello.hnx);
if (ret < 0)
{
printf("vnc_default_fbinitialize failed: %d\n", ret);
nx_disconnect(g_nxhello.hnx);
return ERROR;
}
#endif
/* Start a separate thread to listen for server events. This is probably
* the least efficient way to do this, but it makes this example flow more
* smoothly.
*/
(void)pthread_attr_init(&attr);
param.sched_priority = CONFIG_EXAMPLES_NXHELLO_LISTENERPRIO;
(void)pthread_attr_setschedparam(&attr, &param);
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXHELLO_LISTENER_STACKSIZE);
ret = pthread_create(&thread, &attr, nxhello_listener, NULL);
if (ret != 0)
{
printf("nxhello_initialize: pthread_create failed: %d\n", ret);
return ERROR;
}
/* Don't return until we are connected to the server */
while (!g_nxhello.connected)
{
/* Wait for the listener thread to wake us up when we really
* are connected.
*/
(void)sem_wait(&g_nxhello.eventsem);
}
}
else
{
printf("vnc_default_fbinitialize failed: %d\n", ret);
nx_close(g_nxhello.hnx);
g_nxhello.code = NXEXIT_FBINITIALIZE;
printf("nxhello_initialize: nx_connect failed: %d\n", errno);
return ERROR;
}
#endif
return OK;
}
@ -254,7 +195,7 @@ int nxhello_main(int argc, char *argv[])
if (!g_nxhello.hnx || ret < 0)
{
printf("nxhello_main: Failed to get NX handle: %d\n", errno);
g_nxhello.code = NXEXIT_NXOPEN;
g_nxhello.code = NXEXIT_INIT;
goto errout;
}
@ -298,8 +239,9 @@ int nxhello_main(int argc, char *argv[])
while (!g_nxhello.havepos)
{
(void)sem_wait(&g_nxhello.sem);
(void)sem_wait(&g_nxhello.eventsem);
}
printf("nxhello_main: Screen resolution (%d,%d)\n", g_nxhello.xres, g_nxhello.yres);
/* Now, say hello and exit, sleeping a little before each. */
@ -315,8 +257,9 @@ int nxhello_main(int argc, char *argv[])
/* Close NX */
errout_with_nx:
printf("nxhello_main: Close NX\n");
nx_close(g_nxhello.hnx);
printf("nxhello_main: Disconnect from the server\n");
nx_disconnect(g_nxhello.hnx);
errout:
return g_nxhello.code;
}

View File

@ -7,6 +7,7 @@ config EXAMPLES_NXTERM
bool "NxTerm example"
default n
depends on NX_MULTIUSER
select LIB_BOARDCTL
---help---
Enable the NxTerm example