Resync new repository with old repo r5166

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_NXCONSOLE
bool "NxConsole example"
default n
---help---
Enable the NxConsole example
if EXAMPLES_NXCONSOLE
endif
+93
View File
@@ -0,0 +1,93 @@
############################################################################
# apps/examples/nxconsole/Makefile
#
# Copyright (C) 2011 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# NuttX NX Console Example.
ASRCS =
CSRCS = nxcon_main.c nxcon_toolbar.c nxcon_wndo.c nxcon_server.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
context:
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+310
View File
@@ -0,0 +1,310 @@
/****************************************************************************
* examples/nxconsole/nxcon_internal.h
*
* Copyright (C) 2012 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.
*
****************************************************************************/
#ifndef __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H
#define __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include <nuttx/rgbcolors.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxtk.h>
#include <nuttx/nx/nxconsole.h>
/****************************************************************************
* Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* Need NX graphics support */
#ifndef CONFIG_NX
# error "NX is not enabled (CONFIG_NX=y)"
#endif
/* Can't do the NxConsole example if the NxConsole driver is not built */
#ifndef CONFIG_NXCONSOLE
# error "NxConsole is not enabled (CONFIG_NXCONSOLE=y)"
#endif
/* NxConsole requires NX Multi-user mode */
#ifndef CONFIG_NX_MULTIUSER
# error "Multi-user NX support is required (CONFIG_NX_MULTIUSER=y)"
#endif
/* If there is no NSH console, then why are we running this example? */
#ifndef CONFIG_NSH_CONSOLE
# warning "Expected CONFIG_NSH_CONSOLE=y"
#endif
/* The NSH telnet console requires networking support (and TCP/IP) */
#ifndef CONFIG_NET
# undef CONFIG_NSH_TELNET
#endif
/* 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_NXCON_VPLANE
# define CONFIG_EXAMPLES_NXCON_VPLANE 0
#endif
/* Pixel depth. If none provided, pick the smallest enabled pixel depth */
#ifndef CONFIG_EXAMPLES_NXCON_BPP
# if !defined(CONFIG_NX_DISABLE_1BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 1
# elif !defined(CONFIG_NX_DISABLE_2BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 2
# elif !defined(CONFIG_NX_DISABLE_4BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 4
# elif !defined(CONFIG_NX_DISABLE_8BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 8
# elif !defined(CONFIG_NX_DISABLE_16BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 16
//#elif !defined(CONFIG_NX_DISABLE_24BPP)
//# define CONFIG_NXCONSOLE_BPP 24
# elif !defined(CONFIG_NX_DISABLE_32BPP)
# define CONFIG_EXAMPLES_NXCON_BPP 32
# else
# error "No pixel depth provided"
# endif
#endif
/* Background color (default is darker royal blue) */
#ifndef CONFIG_EXAMPLES_NXCON_BGCOLOR
# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
# define CONFIG_EXAMPLES_NXCON_BGCOLOR RGBTO24(39, 64, 139)
# elif CONFIG_EXAMPLES_NXCON_BPP == 16
# define CONFIG_EXAMPLES_NXCON_BGCOLOR RGBTO16(39, 64, 139)
# else
# define CONFIG_EXAMPLES_NXCON_BGCOLOR RGBTO8(39, 64, 139)
# endif
#endif
/* Window color (lighter steel blue) */
#ifndef CONFIG_EXAMPLES_NXCON_WCOLOR
# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
# define CONFIG_EXAMPLES_NXCON_WCOLOR RGBTO24(202, 225, 255)
# elif CONFIG_EXAMPLES_NXCON_BPP == 16
# define CONFIG_EXAMPLES_NXCON_WCOLOR RGBTO16(202, 225, 255)
# else
# define CONFIG_EXAMPLES_NXCON_WCOLOR RGBTO8(202, 225, 255)
# endif
#endif
/* Toolbar color (medium grey) */
#ifndef CONFIG_EXAMPLES_NXCON_TBCOLOR
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
# define CONFIG_EXAMPLES_NXCON_TBCOLOR RGBTO24(188, 188, 188)
# elif CONFIG_EXAMPLES_NX_BPP == 16
# define CONFIG_EXAMPLES_NXCON_TBCOLOR RGBTO16(188, 188, 188)
# else
# define CONFIG_EXAMPLES_NXCON_TBCOLOR RGBTO8(188, 188, 188)
# endif
#endif
/* Font ID */
#ifndef CONFIG_EXAMPLES_NXCON_FONTID
# define CONFIG_EXAMPLES_NXCON_FONTID NXFONT_DEFAULT
#endif
/* Font color */
#ifndef CONFIG_EXAMPLES_NXCON_FONTCOLOR
# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
# define CONFIG_EXAMPLES_NXCON_FONTCOLOR RGBTO24(0, 0, 0)
# elif CONFIG_EXAMPLES_NXCON_BPP == 16
# define CONFIG_EXAMPLES_NXCON_FONTCOLOR RGBTO16(0, 0, 0)
# else
# define CONFIG_EXAMPLES_NXCON_FONTCOLOR RGBTO8(0, 0, 0)
# endif
#endif
/* Height of the toolbar */
#ifndef CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT
# define CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT 16
#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_NXCON_STACKSIZE
# define CONFIG_EXAMPLES_NXCON_STACKSIZE 2048
#endif
#ifndef CONFIG_EXAMPLES_NXCON_LISTENERPRIO
# define CONFIG_EXAMPLES_NXCON_LISTENERPRIO 100
#endif
#ifndef CONFIG_EXAMPLES_NXCON_CLIENTPRIO
# define CONFIG_EXAMPLES_NXCON_CLIENTPRIO 100
#endif
#ifndef CONFIG_EXAMPLES_NXCON_SERVERPRIO
# define CONFIG_EXAMPLES_NXCON_SERVERPRIO 120
#endif
#ifndef CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO
# define CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO 4
#endif
/* Graphics Device */
#ifndef CONFIG_EXAMPLES_NXCON_DEVNO
# define CONFIG_EXAMPLES_NXCON_DEVNO 0
#endif
/* NX Console Device */
#ifndef CONFIG_EXAMPLES_NXCON_MINOR
# define CONFIG_EXAMPLES_NXCON_MINOR 0
#endif
#ifndef CONFIG_EXAMPLES_NXCON_DEVNAME
# define CONFIG_EXAMPLES_NXCON_DEVNAME "/dev/nxcon0"
#endif
/* NxConsole task */
#ifndef CONFIG_EXAMPLES_NXCONSOLE_PRIO
# define CONFIG_EXAMPLES_NXCONSOLE_PRIO SCHED_PRIORITY_DEFAULT
#endif
#ifndef CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE
# define CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE 2048
#endif
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* All example global variables are retained in a structure to minimize
* the chance of name collisions.
*/
struct nxcon_state_s
{
volatile bool haveres; /* True: Have screen resolution */
volatile bool connected; /* True: Connected to server */
sem_t eventsem; /* Control waiting for display events */
pid_t pid; /* Console task ID */
NXHANDLE hnx; /* The connection handler */
NXTKWINDOW hwnd; /* The window */
NXCONSOLE hdrvr; /* The console driver */
struct nxcon_window_s wndo; /* Describes the window */
nxgl_coord_t xres; /* Screen X resolution */
nxgl_coord_t yres; /* Screen Y resolution */
struct nxgl_size_s wsize; /* Window size */
struct nxgl_point_s wpos; /* Window position */
};
/****************************************************************************
* Public Variables
****************************************************************************/
/* All example global variables are retained in a structure to minimize
* the chance of name collisions.
*/
extern struct nxcon_state_s g_nxcon_vars;
/* NX callback vtables */
extern const struct nx_callback_s g_nxconcb;
extern const struct nx_callback_s g_nxtoolcb;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* Board-specific driver intiialization */
#ifdef CONFIG_EXAMPLES_NXCON_EXTERNINIT
extern FAR NX_DRIVERTYPE *up_nxdrvinit(unsigned int devno);
#endif
/* Server thread support */
extern int nxcon_server(int argc, char *argv[]);
extern FAR void *nxcon_listener(FAR void *arg);
#endif /* __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H */
+412
View File
@@ -0,0 +1,412 @@
/****************************************************************************
* examples/nxconsole/nxcon_main.c
*
* Copyright (C) 2012 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 <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <debug.h>
#ifdef CONFIG_NX_LCDDRIVER
# include <nuttx/lcd/lcd.h>
#else
# include <nuttx/fb.h>
#endif
#include <nuttx/arch.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxfonts.h>
#include <nuttx/nx/nxconsole.h>
#include <apps/nsh.h>
#include "nxcon_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/* All example global variables are retained in a structure to minimize
* the chance of name collisions.
*/
struct nxcon_state_s g_nxcon_vars;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxcon_initialize
****************************************************************************/
static int nxcon_initialize(void)
{
struct sched_param param;
pthread_t thread;
pid_t servrid;
int ret;
/* Set the client task priority */
param.sched_priority = CONFIG_EXAMPLES_NXCON_CLIENTPRIO;
ret = sched_setparam(0, &param);
if (ret < 0)
{
message("nxcon_initialize: sched_setparam failed: %d\n" , ret);
return ERROR;
}
/* Start the server task */
message("nxcon_initialize: Starting nxcon_server task\n");
servrid = task_create("NX Server", CONFIG_EXAMPLES_NXCON_SERVERPRIO,
CONFIG_EXAMPLES_NXCON_STACKSIZE, nxcon_server, NULL);
if (servrid < 0)
{
message("nxcon_initialize: Failed to create nxcon_server task: %d\n", errno);
return ERROR;
}
/* Wait a bit to let the server get started */
sleep(1);
/* Connect to the server */
g_nxcon_vars.hnx = nx_connect();
if (g_nxcon_vars.hnx)
{
pthread_attr_t attr;
/* 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_NXCON_LISTENERPRIO;
(void)pthread_attr_setschedparam(&attr, &param);
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXCON_STACKSIZE);
ret = pthread_create(&thread, &attr, nxcon_listener, NULL);
if (ret != 0)
{
printf("nxcon_initialize: pthread_create failed: %d\n", ret);
return ERROR;
}
/* Don't return until we are connected to the server */
while (!g_nxcon_vars.connected)
{
/* Wait for the listener thread to wake us up when we really
* are connected.
*/
(void)sem_wait(&g_nxcon_vars.eventsem);
}
}
else
{
message("nxcon_initialize: nx_connect failed: %d\n", errno);
return ERROR;
}
return OK;
}
/****************************************************************************
* Name: nxcon_task
****************************************************************************/
static int nxcon_task(int argc, char **argv)
{
/* If the console front end is selected, then run it on this thread */
#ifdef CONFIG_NSH_CONSOLE
(void)nsh_consolemain(0, NULL);
#endif
printf("nxcon_task: Unregister the NX console device\n");
(void)nxcon_unregister(g_nxcon_vars.hdrvr);
printf("nxcon_task: Close the window\n");
(void)nxtk_closewindow(g_nxcon_vars.hwnd);
/* Disconnect from the server */
printf("nxcon_task: Disconnect from the server\n");
nx_disconnect(g_nxcon_vars.hnx);
return EXIT_SUCCESS;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxcon_main
****************************************************************************/
int nxcon_main(int argc, char **argv)
{
nxgl_mxpixel_t color;
int fd;
int ret;
/* General Initialization *************************************************/
/* Reset all global data */
message("nxcon_main: Started\n");
memset(&g_nxcon_vars, 0, sizeof(struct nxcon_state_s));
/* Call all C++ static constructors */
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
up_cxxinitialize();
#endif
/* NSH Initialization *****************************************************/
/* Initialize the NSH library */
message("nxcon_main: Initialize NSH\n");
nsh_initialize();
/* If the Telnet console is selected as a front-end, then start the
* Telnet daemon.
*/
#ifdef CONFIG_NSH_TELNET
ret = nsh_telnetstart();
if (ret < 0)
{
/* The daemon is NOT running. Report the the error then fail...
* either with the serial console up or just exiting.
*/
fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret);
}
#endif
/* NX Initialization ******************************************************/
/* Initialize NX */
message("nxcon_main: Initialize NX\n");
ret = nxcon_initialize();
message("nxcon_main: NX handle=%p\n", g_nxcon_vars.hnx);
if (!g_nxcon_vars.hnx || ret < 0)
{
message("nxcon_main: Failed to get NX handle: %d\n", errno);
goto errout;
}
/* Set the background to the configured background color */
message("nxcon_main: Set background color=%d\n", CONFIG_EXAMPLES_NXCON_BGCOLOR);
color = CONFIG_EXAMPLES_NXCON_BGCOLOR;
ret = nx_setbgcolor(g_nxcon_vars.hnx, &color);
if (ret < 0)
{
message("nxcon_main: nx_setbgcolor failed: %d\n", errno);
goto errout_with_nx;
}
/* Window Configuration ***************************************************/
/* Create a window */
message("nxcon_main: Create window\n");
g_nxcon_vars.hwnd = nxtk_openwindow(g_nxcon_vars.hnx, &g_nxconcb, NULL);
if (!g_nxcon_vars.hwnd)
{
message("nxcon_main: nxtk_openwindow failed: %d\n", errno);
goto errout_with_nx;
}
message("nxcon_main: hwnd=%p\n", g_nxcon_vars.hwnd);
/* Wait until we have the screen resolution. We'll have this immediately
* unless we are dealing with the NX server.
*/
while (!g_nxcon_vars.haveres)
{
(void)sem_wait(&g_nxcon_vars.eventsem);
}
message("nxcon_main: Screen resolution (%d,%d)\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
/* Determine the size and position of the window */
g_nxcon_vars.wndo.wsize.w = g_nxcon_vars.xres / 2 + g_nxcon_vars.xres / 4;
g_nxcon_vars.wndo.wsize.h = g_nxcon_vars.yres / 2 + g_nxcon_vars.yres / 4;
g_nxcon_vars.wpos.x = g_nxcon_vars.xres / 8;
g_nxcon_vars.wpos.y = g_nxcon_vars.yres / 8;
/* Set the window position */
message("nxcon_main: Set window position to (%d,%d)\n",
g_nxcon_vars.wpos.x, g_nxcon_vars.wpos.y);
ret = nxtk_setposition(g_nxcon_vars.hwnd, &g_nxcon_vars.wpos);
if (ret < 0)
{
message("nxcon_main: nxtk_setposition failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Set the window size */
message("nxcon_main: Set window size to (%d,%d)\n",
g_nxcon_vars.wndo.wsize.w, g_nxcon_vars.wndo.wsize.h);
ret = nxtk_setsize(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo.wsize);
if (ret < 0)
{
message("nxcon_main: nxtk_setsize failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Open the toolbar */
message("nxcon_main: Add toolbar to window\n");
ret = nxtk_opentoolbar(g_nxcon_vars.hwnd, CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT, &g_nxtoolcb, NULL);
if (ret < 0)
{
message("nxcon_main: nxtk_opentoolbar failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Sleep a little bit to allow the server to catch up */
sleep(2);
/* NxConsole Configuration ************************************************/
/* Use the window to create an NX console */
g_nxcon_vars.wndo.wcolor[0] = CONFIG_EXAMPLES_NXCON_WCOLOR;
g_nxcon_vars.wndo.fcolor[0] = CONFIG_EXAMPLES_NXCON_FONTCOLOR;
g_nxcon_vars.wndo.fontid = CONFIG_EXAMPLES_NXCON_FONTID;
g_nxcon_vars.hdrvr = nxtk_register(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo, CONFIG_EXAMPLES_NXCON_MINOR);
if (!g_nxcon_vars.hdrvr)
{
message("nxcon_main: nxtk_register failed: %d\n", errno);
goto errout_with_hwnd;
}
/* Open the NxConsole driver */
fd = open(CONFIG_EXAMPLES_NXCON_DEVNAME, O_WRONLY);
if (fd < 0)
{
message("nxcon_main: open %s read-only failed: %d\n",
CONFIG_EXAMPLES_NXCON_DEVNAME, errno);
goto errout_with_driver;
}
/* Start Console Task *****************************************************/
/* Now re-direct stdout and stderr so that they use the NX console driver.
* Note that stdin is retained (file descriptor 0, probably the the serial console).
*/
message("nxcon_main: Starting the console task\n");
msgflush();
(void)fflush(stdout);
(void)fflush(stderr);
(void)fclose(stdout);
(void)fclose(stderr);
(void)dup2(fd, 1);
(void)dup2(fd, 2);
/* And we can close our original driver file descriptor */
close(fd);
/* And start the console task. It will inherit stdin, stdout, and stderr
* from this task.
*/
g_nxcon_vars.pid = TASK_CREATE("NxConsole", CONFIG_EXAMPLES_NXCONSOLE_PRIO,
CONFIG_EXAMPLES_NXCONSOLE_STACKSIZE,
nxcon_task, NULL);
ASSERT(g_nxcon_vars.pid > 0);
return EXIT_SUCCESS;
/* Error Exits ************************************************************/
errout_with_driver:
(void)nxcon_unregister(g_nxcon_vars.hdrvr);
errout_with_hwnd:
(void)nxtk_closewindow(g_nxcon_vars.hwnd);
errout_with_nx:
/* Disconnect from the server */
nx_disconnect(g_nxcon_vars.hnx);
errout:
return EXIT_FAILURE;
}
+189
View File
@@ -0,0 +1,189 @@
/****************************************************************************
* examples/nxconsole/nxcon_server.c
*
* Copyright (C) 2012 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/nx/nx.h>
#ifdef CONFIG_NX_LCDDRIVER
# include <nuttx/lcd/lcd.h>
#else
# include <nuttx/fb.h>
#endif
#include "nxcon_internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxcon_server
****************************************************************************/
int nxcon_server(int argc, char *argv[])
{
FAR NX_DRIVERTYPE *dev;
int ret;
#if defined(CONFIG_EXAMPLES_NXCON_EXTERNINIT)
/* Use external graphics driver initialization */
message("nxcon_server: Initializing external graphics device\n");
dev = up_nxdrvinit(CONFIG_EXAMPLES_NXCON_DEVNO);
if (!dev)
{
message("nxcon_server: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NXCON_DEVNO);
return ERROR;
}
#elif defined(CONFIG_NX_LCDDRIVER)
/* Initialize the LCD device */
message("nxcon_server: Initializing LCD\n");
ret = up_lcdinitialize();
if (ret < 0)
{
message("nxcon_server: up_lcdinitialize failed: %d\n", -ret);
return 1;
}
/* Get the device instance */
dev = up_lcdgetdev(CONFIG_EXAMPLES_NXCON_DEVNO);
if (!dev)
{
message("nxcon_server: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NXCON_DEVNO);
return 2;
}
/* Turn the LCD on at 75% power */
(void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
#else
/* Initialize the frame buffer device */
message("nxcon_server: Initializing framebuffer\n");
ret = up_fbinitialize();
if (ret < 0)
{
message("nxcon_server: up_fbinitialize failed: %d\n", -ret);
return 1;
}
dev = up_fbgetvplane(CONFIG_EXAMPLES_NXCON_VPLANE);
if (!dev)
{
message("nxcon_server: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NXCON_VPLANE);
return 2;
}
#endif
/* Then start the server */
ret = nx_run(dev);
gvdbg("nx_run returned: %d\n", errno);
return 3;
}
/****************************************************************************
* Name: nxcon_listener
****************************************************************************/
FAR void *nxcon_listener(FAR void *arg)
{
int ret;
/* Process events forever */
for (;;)
{
/* Handle the next event. If we were configured blocking, then
* we will stay right here until the next event is received. Since
* we have dedicated a while thread to servicing events, it would
* be most natural to also select CONFIG_NX_BLOCKING -- if not, the
* following would be a tight infinite loop (unless we added addition
* logic with nx_eventnotify and sigwait to pace it).
*/
ret = nx_eventhandler(g_nxcon_vars.hnx);
if (ret < 0)
{
/* An error occurred... assume that we have lost connection with
* the server.
*/
message("nxcon_listener: Lost server connection: %d\n", errno);
exit(EXIT_FAILURE);
}
/* If we received a message, we must be connected */
if (!g_nxcon_vars.connected)
{
g_nxcon_vars.connected = true;
sem_post(&g_nxcon_vars.eventsem);
message("nxcon_listener: Connected\n");
}
}
}
+172
View File
@@ -0,0 +1,172 @@
/****************************************************************************
* examples/nxconsole/nxcon_toolbar.c
*
* Copyright (C) 2012 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 <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxcon_internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool morem, FAR void *arg);
static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
#ifdef CONFIG_NX_MOUSE
static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg);
#endif
#ifdef CONFIG_NX_KBD
static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
FAR void *arg);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/* Background window call table */
const struct nx_callback_s g_nxtoolcb =
{
nxtool_redraw, /* redraw */
nxtool_position /* position */
#ifdef CONFIG_NX_MOUSE
, nxtool_mousein /* mousein */
#endif
#ifdef CONFIG_NX_KBD
, nxtool_kbdin /* my kbdin */
#endif
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxtool_redraw
****************************************************************************/
static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg)
{
nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
int ret;
gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "true" : "false");
color[0] = CONFIG_EXAMPLES_NXCON_TBCOLOR;
ret = nxtk_filltoolbar(hwnd, rect, color);
if (ret < 0)
{
gdbg("nxtk_filltoolbar failed: %d\n", errno);
}
}
/****************************************************************************
* Name: nxtool_position
****************************************************************************/
static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{
gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
hwnd, size->w, size->h, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
}
/****************************************************************************
* Name: nxtool_mousein
****************************************************************************/
#ifdef CONFIG_NX_MOUSE
static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg)
{
gvdbg("hwnd=%p pos=(%d,%d) button=%02x\n", hwnd, pos->x, pos->y, buttons);
}
#endif
/****************************************************************************
* Name: nxtool_kbdin
****************************************************************************/
#ifdef CONFIG_NX_KBD
static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
FAR void *arg)
{
gvdbg("hwnd=%p nch=%d\n", hwnd, nch);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
+208
View File
@@ -0,0 +1,208 @@
/****************************************************************************
* examples/nxconsole/nxcon_wndo.c
*
* Copyright (C) 2012 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 <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <semaphore.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxcon_internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool morem, FAR void *arg);
static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
#ifdef CONFIG_NX_MOUSE
static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg);
#endif
#ifdef CONFIG_NX_KBD
static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
FAR void *arg);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/* Background window call table */
const struct nx_callback_s g_nxconcb =
{
nxwndo_redraw, /* redraw */
nxwndo_position /* position */
#ifdef CONFIG_NX_MOUSE
, nxwndo_mousein /* mousein */
#endif
#ifdef CONFIG_NX_KBD
, nxwndo_kbdin /* my kbdin */
#endif
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxwndo_redraw
****************************************************************************/
static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
bool more, FAR void *arg)
{
nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES];
gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "true" : "false");
/* Don't attempt to redraw if the driver has not yet been opened */
if (g_nxcon_vars.hdrvr)
{
/* Inform the NX console of the redraw request */
nxcon_redraw(g_nxcon_vars.hdrvr, rect, more);
}
else
{
/* If the driver has not been opened, then just redraw the window color */
wcolor[0] = CONFIG_EXAMPLES_NXCON_WCOLOR;
(void)nxtk_fillwindow(hwnd, rect, wcolor);
}
}
/****************************************************************************
* Name: nxwndo_position
****************************************************************************/
static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{
/* Report the position */
gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
hwnd, size->w, size->h, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
/* Have we picked off the window bounds yet? */
if (!g_nxcon_vars.haveres)
{
/* Save the background window handle */
g_nxcon_vars.hwnd = hwnd;
/* Save the background window size */
g_nxcon_vars.wndo.wsize.w = size->w;
g_nxcon_vars.wndo.wsize.h = size->h;
/* Save the window limits (these should be the same for all places and all windows */
g_nxcon_vars.xres = bounds->pt2.x + 1;
g_nxcon_vars.yres = bounds->pt2.y + 1;
g_nxcon_vars.haveres = true;
sem_post(&g_nxcon_vars.eventsem);
gvdbg("Have xres=%d yres=%d\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
}
}
/****************************************************************************
* Name: nxwndo_mousein
****************************************************************************/
#ifdef CONFIG_NX_MOUSE
static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg)
{
gvdbg("hwnd=%p pos=(%d,%d) button=%02x\n",
hwnd, pos->x, pos->y, buttons);
}
#endif
/****************************************************************************
* Name: nxwndo_kbdin
****************************************************************************/
#ifdef CONFIG_NX_KBD
static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
FAR void *arg)
{
gvdbg("hwnd=%p nch=%d\n", hwnd, nch);
(void)write(1, ch, nch);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/