Merged nuttx/apps into master
This commit is contained in:
commit
e64e160250
@ -1678,3 +1678,32 @@
|
||||
From David Sidrane (2016-07-01).
|
||||
* apps/examples/canard: Add canard example application. From Matthias
|
||||
Renner (2016-07-08).
|
||||
* apps/builtins: exec_builtin was not using the provided open flags. As
|
||||
a result >> redirection was not working (2016-07-10).
|
||||
* apps/netutils/ntpclient: The NTP client will now optionally use
|
||||
pool.ntp.org as the NTP server; and reset the retry count upon success
|
||||
-- more robust. From David Alessio (2016-07-10).
|
||||
* apps/nshlib/nsh_proccmds.c: Recent enhancements to cmd_ps trips a
|
||||
floating point exception if LIBC_FLOATINGPOINT is not defined (at
|
||||
least on Cortex M4 w/ hardfloat). I’m using a buildroot gcc
|
||||
configured to support Cortex-M4F and the hard float ABI, target files
|
||||
are compiles with: -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16
|
||||
-mfloat-abi=hard. I’m not sure the best way to address this, but the
|
||||
this chage is the first that comes to mind. Note, I added the float
|
||||
qualifier ‘F’ after a few constants to prevent the compiler from
|
||||
promoting the multiplication and division to double (expensive on
|
||||
M4F) then demoting to single float for the store. From David
|
||||
Alessio (2016-07-10).
|
||||
* Call all includes fronm <apps/bla/bla.h> to "bla/bla.h". From
|
||||
Sebastien Lorquet (2016-07-11).
|
||||
* Build System: Add apps/include to include path in top-level
|
||||
Make.defs file. Remove multiple definitions of INCDIR opt
|
||||
(2016-07-11).
|
||||
* apps/netuils, uIP webserver: Fix a data declaration in a header file
|
||||
(2016-07-11).
|
||||
* apps/nshlib: In ps command, don't show stack usage is
|
||||
CONFIG_STACK_COLORATION is not enabled (2016-07-13).
|
||||
* apps/netutils/esp8266: In Kconfig, select ARCH_HAVE_NET when
|
||||
NETUTILS_ESP8266 is selected. This allows, among other things,
|
||||
support for network debug output. From Pierre-noel Bouteville
|
||||
(2016-07-14).
|
||||
|
@ -1627,6 +1627,11 @@ examples/posix_spawn
|
||||
|
||||
LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld
|
||||
|
||||
examples/pty_test
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
A test of NuttX pseudo-terminals. Provided by Alan Carvalho de Assis.
|
||||
|
||||
examples/pwm
|
||||
^^^^^^^^^^^^
|
||||
|
||||
|
11
examples/pty_test/.gitignore
vendored
Normal file
11
examples/pty_test/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
48
examples/pty_test/Kconfig
Normal file
48
examples/pty_test/Kconfig
Normal file
@ -0,0 +1,48 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_PTYTEST
|
||||
bool "Pseudo Terminal test example"
|
||||
default n
|
||||
depends on PSEUDOTERM
|
||||
select PSEUDOTERM_SUSV1
|
||||
---help---
|
||||
Enable the PTY example
|
||||
|
||||
if EXAMPLES_PTYTEST
|
||||
|
||||
config EXAMPLES_PTYTEST_PROGNAME
|
||||
string "Program name"
|
||||
default "pts"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_PTYTEST_POLL
|
||||
bool "Test poll() with data transfers"
|
||||
default n
|
||||
|
||||
config EXAMPLES_PTYTEST_SERIALDEV
|
||||
string "Test serial device"
|
||||
default"/dev/ttyS1"
|
||||
|
||||
config EXAMPLES_PTYTEST_PRIORITY
|
||||
int "PTY_Test task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_PTYTEST_STACKSIZE
|
||||
int "PTYTest stack size"
|
||||
default 2048
|
||||
|
||||
config EXAMPLES_PTYTEST_DAEMONPRIO,
|
||||
int "PTY_Test daemon task priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_PTYTEST_STACKSIZE
|
||||
int "PTY_Test daemon stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/pty_test/Make.defs
Normal file
39
examples/pty_test/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/pty_test/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2016 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_PTYTEST),y)
|
||||
CONFIGURED_APPS += examples/pty_test
|
||||
endif
|
57
examples/pty_test/Makefile
Normal file
57
examples/pty_test/Makefile
Normal file
@ -0,0 +1,57 @@
|
||||
############################################################################
|
||||
# apps/examples/pty_test/Makefile
|
||||
#
|
||||
# Copyright (C) 2016 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)/Make.defs
|
||||
|
||||
# Hello, World! built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_PTYTEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_PTYTEST_STACKSIZE ?= 8192
|
||||
|
||||
APPNAME = pty_test
|
||||
PRIORITY = $(CONFIG_EXAMPLES_PTYTEST_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_PTYTEST_STACKSIZE)
|
||||
|
||||
# PTY Test! Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
CFLAGS += -I$(APPDIR)/include
|
||||
MAINSRC = pty_test.c
|
||||
|
||||
CONFIG_EXAMPLES_PTYTEST_PROGNAME ?= pty_test$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_PTYTEST_PROGNAME)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
414
examples/pty_test/pty_test.c
Normal file
414
examples/pty_test/pty_test.c
Normal file
@ -0,0 +1,414 @@
|
||||
/****************************************************************************
|
||||
* examples/pty_test/pty_test.c
|
||||
*
|
||||
* Copyright (C) 2016, Gregory Nutt. All rights reserved.
|
||||
* Author: Alan Carvalho de Assisi <acassis@gmail.com>
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <termios.h>
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <nuttx/serial/pty.h>
|
||||
|
||||
#include "nshlib/nshlib.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_SERIALDEV
|
||||
# define CONFIG_EXAMPLES_PTYTEST_SERIALDEV "/dev/ttyS1"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO
|
||||
# define CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO SCHED_PRIORITY_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_PTYTEST_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_PTYTEST_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#define POLL_TIMEOUT 200
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct term_pair_s
|
||||
{
|
||||
int fd_uart;
|
||||
int fd_pty;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: serial_in
|
||||
*
|
||||
* Description:
|
||||
* Read data from serial and write to pts
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void serial_in(struct term_pair_s *tp)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
struct pollfd fdp;
|
||||
#endif
|
||||
char buffer[16];
|
||||
int ret;
|
||||
|
||||
if (!tp)
|
||||
{
|
||||
fprintf(stderr, "ERROR: terminal pair struct is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
fdp.fd = tp->fd_uart;
|
||||
fdp.events = POLLIN;
|
||||
#endif
|
||||
|
||||
/* Run forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||
if (ret > 0)
|
||||
{
|
||||
if ((fdp.revents & POLLIN) != 0)
|
||||
#endif
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
len = read(tp->fd_uart, buffer, 16);
|
||||
if (len < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR Failed to read from serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
else if (len > 0)
|
||||
{
|
||||
ret = write(tp->fd_pty, buffer, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Failed to write to serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
}
|
||||
|
||||
/* Timeout */
|
||||
|
||||
else if (ret == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Poll error */
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: serial_out
|
||||
*
|
||||
* Description:
|
||||
* Read data from pts and write to serial
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void serial_out(struct term_pair_s *tp)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
struct pollfd fdp;
|
||||
#endif
|
||||
char buffer[16];
|
||||
int ret;
|
||||
|
||||
if (!tp)
|
||||
{
|
||||
fprintf(stderr, "Error: terminal pair struct is NULL!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
fdp.fd = tp->fd_pty;
|
||||
fdp.events = POLLIN;
|
||||
#endif
|
||||
|
||||
/* Run forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||
if (ret > 0)
|
||||
{
|
||||
if ((fdp.revents & POLLIN != 0))
|
||||
#endif
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
len = read(tp->fd_pty, buffer, 16);
|
||||
if (len < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to read from pseudo-terminal: %d\n",
|
||||
errno);
|
||||
}
|
||||
else if (len > 0)
|
||||
{
|
||||
ret = write(tp->fd_uart, buffer, len);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: Failed to write to serial: %d\n",
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||
}
|
||||
|
||||
/* Timeout */
|
||||
|
||||
else if (ret == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* poll error */
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pty_test_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int pty_test_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
struct term_pair_s termpair;
|
||||
struct termios tio;
|
||||
pthread_t si_thread;
|
||||
pthread_t so_thread;
|
||||
char buffer[16];
|
||||
pid_t pid;
|
||||
int fd_pts;
|
||||
int ret;
|
||||
|
||||
printf("Create pseudo-terminal\n");
|
||||
|
||||
/* Open pseudo-terminal master (pts factory) */
|
||||
|
||||
termpair.fd_pty = open("/dev/ptmx", O_RDWR | O_NOCTTY);
|
||||
if (termpair.fd_pty < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to opening /dev/ptmx: %d\n",
|
||||
errno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Grant access and unlock the slave PTY */
|
||||
|
||||
ret = grantpt(termpair.fd_pty);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: grantpt() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
ret = unlockpt(termpair.fd_pty);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: unlockpt() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Get the create pts file-name */
|
||||
|
||||
ret = ptsname_r(termpair.fd_pty, buffer, 16);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: ptsname_r() failed: %d\n", errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Open the created pts */
|
||||
|
||||
fd_pts = open(buffer, O_RDWR | O_NONBLOCK);
|
||||
if (fd_pts < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Failed to open %s: %d\n", buffer, errno);
|
||||
goto error_pts;
|
||||
}
|
||||
|
||||
/* Open the second serial port to create a new console there */
|
||||
|
||||
termpair.fd_uart = open(CONFIG_EXAMPLES_PTYTEST_SERIALDEV,
|
||||
O_RDWR | O_NONBLOCK);
|
||||
if (termpair.fd_uart < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to open %s: %\n",
|
||||
CONFIG_EXAMPLES_PTYTEST_SERIALDEV, errno);
|
||||
goto error_serial;
|
||||
}
|
||||
|
||||
/* Enable \n -> \r\n conversion during write */
|
||||
|
||||
ret = tcgetattr(termpair.fd_uart, &tio);
|
||||
if (ret)
|
||||
{
|
||||
fprintf(stderr, "ERROR: tcgetattr() failed: %d\n", errno);
|
||||
goto error_serial;
|
||||
}
|
||||
|
||||
tio.c_oflag = OPOST | ONLCR;
|
||||
ret = tcsetattr(termpair.fd_uart, TCSANOW, &tio);
|
||||
if (ret)
|
||||
{
|
||||
fprintf(stderr, "ERROR: tcsetattr() failed: %d\n", errno);
|
||||
goto error_serial;
|
||||
}
|
||||
|
||||
printf("Starting a new NSH Session using %s\n", buffer);
|
||||
|
||||
/* Close default stdin, stdout and stderr */
|
||||
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
/* Use this pts file as stdin, stdout, and stderr */
|
||||
|
||||
(void)dup2(fd_pts, 0);
|
||||
(void)dup2(fd_pts, 1);
|
||||
(void)dup2(fd_pts, 2);
|
||||
|
||||
/* Create a new console using this /dev/pts/N */
|
||||
|
||||
pid = task_create("NSH Console", CONFIG_EXAMPLES_PTYTEST_DAEMONPRIO,
|
||||
CONFIG_EXAMPLES_PTYTEST_STACKSIZE, nsh_consolemain, NULL);
|
||||
if (pid < 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_console;
|
||||
}
|
||||
|
||||
/* Start a thread to read from serial */
|
||||
|
||||
ret = pthread_create(&si_thread, NULL,
|
||||
(pthread_startroutine_t)serial_in,
|
||||
(pthread_addr_t)&termpair);
|
||||
if (ret != 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_thread1;
|
||||
}
|
||||
|
||||
/* Start a thread to write to serial */
|
||||
|
||||
ret = pthread_create(&so_thread, NULL,
|
||||
(pthread_startroutine_t)serial_out,
|
||||
(pthread_addr_t)&termpair);
|
||||
if (ret != 0)
|
||||
{
|
||||
/* Can't do output because stdout and stderr are redirected */
|
||||
|
||||
goto error_thread2;
|
||||
}
|
||||
|
||||
/* Stay here to keep the threads running */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Nothing to do, then sleep to avoid eating all cpu time */
|
||||
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
error_thread2:
|
||||
error_thread1:
|
||||
error_console:
|
||||
close(termpair.fd_uart);
|
||||
error_serial:
|
||||
close(fd_pts);
|
||||
error_pts:
|
||||
close(termpair.fd_pty);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
config NETUTILS_ESP8266
|
||||
bool "ESP8266"
|
||||
select ARCH_HAVE_NET
|
||||
default n
|
||||
---help---
|
||||
Enable support for ESP8266 application interface.
|
||||
|
@ -235,7 +235,17 @@ static void nsh_parse_statusline(FAR char *line,
|
||||
}
|
||||
else if (strncmp(line, g_priority, strlen(g_priority)) == 0)
|
||||
{
|
||||
status->td_priority = nsh_trimspaces(&line[12]);
|
||||
FAR char *ptr = nsh_trimspaces(&line[12]);
|
||||
status->td_priority = ptr;
|
||||
|
||||
/* If priority inheritance is enabled, use current pri, ignore base */
|
||||
|
||||
while (isdigit(*ptr))
|
||||
{
|
||||
++ptr;
|
||||
}
|
||||
|
||||
*ptr = '\0';
|
||||
}
|
||||
else if (strncmp(line, g_scheduler, strlen(g_scheduler)) == 0)
|
||||
{
|
||||
@ -474,11 +484,11 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
|
||||
stack_filled = 10 * 100 * stack_used / stack_size;
|
||||
}
|
||||
|
||||
/* Additionally print a "!" if the stack is filled more than 80% */
|
||||
/* Additionally print a '!' if the stack is filled more than 80% */
|
||||
|
||||
nsh_output(vtbl, "%3d.%1d%%%s ",
|
||||
nsh_output(vtbl, "%3d.%1d%%%c ",
|
||||
stack_filled / 10, stack_filled % 10,
|
||||
(stack_filled >= 10 * 80 ? "!" : " "));
|
||||
(stack_filled >= 10 * 80 ? '!' : ' '));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user