You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/09/12 06:48:39 UTC

[GitHub] [incubator-nuttx] Donny9 opened a new pull request #1767: To better access host tty interface on sim platform

Donny9 opened a new pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767


   ## Summary
   
   1. To better access host tty interfaces on sim platform, modify nuttx termios based on linux and posix.
   2. Add the ability to access host tty intercaces for sim platform.
   ## Impact
   we can modify SIM_UART_NUMBER to add tty ports and use it to access host tty port on sim platform.
   ## Testing
   Built locally
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487632144



##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       Yes, I have finished the modification. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-713567071


   @davids5  I've commited and created a PR #2053 . 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487405817



##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] davids5 edited a comment on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
davids5 edited a comment on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712746236


   No. Unfortunately hat is not enough, There is a bigger problem with this change.  With this change NuttX can not support any baud rate.  This will break many real world radio protocols! 
   
   What was the problem this PR was trying to fix?  Can it be reworked to keep c_speed, accept any baud rate?
     


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691508533


   LGTM.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487628056



##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       Yes, I have finished the modification. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691888847


   @Donny9 already resolve all my concern, @v01d please merge it if you don't have more comment.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691508533


   LGTM.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] davids5 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
davids5 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712746236


   No. Unfortunately hat is not enough, There is a bigger problem with this change.  With this change NuttX can not support any baud rate.  This will break many real works radio protocols! 
   
   What was the problem this PR was trying to fix?  Can it be reworked to keep c_speed, accept any baud rate?
     


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] v01d commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
v01d commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691683689


   @Donny9 please indicate if you have address all comments outlined by Xiang (resolve each conversation) so that we know you took care of each one.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691508533






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] davids5 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
davids5 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712434684


   @btashton. @v01d,  @Donny9 @xiaoxiang781216 - I am testing 10.0.0 and ran into some really bad side affects of this change in the stm32f7 and I will assume all stm32xxx and possible a lot of other archs,
   
   Removing c_speed and folding the speed into the c_cflag breaks all the code that assumed these are separate. 
   
   Here is an example: https://github.com/apache/incubator-nuttx/blob/master/arch/arm/src/stm32/stm32_serial.c#L2022-L2038
   
   There are no not public macros either to isolate the fields and merge them. The published GPL code this copies has  https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/bits/termios-baud.h.html#25 
   
   I would not release 10.0.0 with this breakage.
    


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-691784497


   > @Donny9 please indicate if you have address all comments outlined by Xiang (resolve each conversation) so that we know you took care of each one.
   
   Okay. thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] davids5 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
davids5 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-713528432


   @Donny9 - Please ping me when you have the new PR. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487405817



##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487405817



##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712892207


   > 
   > 
   > @davids5 so PX4 use other baud rate? @Donny9 please add back the custorm baud rate like other OS done.
   
   yes, i do tomorrow.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-713321001


   Sure, the custom baud rate is used for many embeded case.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] Donny9 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
Donny9 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487628131



##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       Yes, I have finished the modification. Thanks!

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       Yes, I have finished the modification. Thanks!

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       Yes, I have finished the modification. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712884921


   @davids5 so PX4 use other baud rate? @Donny9 please add back the custorm baud rate like other OS done.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] v01d merged pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
v01d merged pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on a change in pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#discussion_r487405817



##########
File path: libs/libc/termios/lib_cfspeed.c
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * libs/libc/termios/lib_cfspeed.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <termios.h>
+#include <assert.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
+#define CBAUDEX        0010000  /* Extra baud speed mask, included in CBAUD.
+                                 * (not in POSIX) */
+
+#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Routine which returns the baud rate of the tty
+ *
+ * Note that the baud_table needs to be kept in sync with the
+ * include/termios.h file.
+ */
+
+static const speed_t g_baud_table[] =
+{
+  0,       50,      75,      110,     134,
+  150,     200,     300,     600,     1200,
+  1800,    2400,    4800,    9600,    19200,
+  38400,   57600,   115200,  230400,  460800,
+  500000,  576000,  921600,  1000000, 1152000,
+  1500000, 2000000, 2500000, 3000000, 3500000,
+  4000000
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int baud_mask(speed_t speed)
+{
+  speed_t idx = 0;
+
+  for (; idx < ARRAYSIZE(g_baud_table); idx++)
+    {
+      if (speed == g_baud_table[idx])
+        {
+          break;
+        }
+    }
+
+  /* we don't find the speed value, it could be mask */
+
+  if (idx == ARRAYSIZE(g_baud_table))
+    {
+      return (speed & ~CBAUD) ? -1 : speed;
+    }
+
+  /* If idx > B38400, we should will idx minus 15, and or CBAUDEX */
+
+  if (idx > B38400)
+    {
+      idx -= B38400;
+      idx |= CBAUDEX;
+    }
+
+  return idx;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cfsetspeed
+ *
+ * Description:
+ *   The cfsetspeed() function is a non-POSIX function that sets the baud
+ *   stored in the structure pointed to by termiosp to speed.
+ *
+ *   There is no effect on the baud set in the hardware until a subsequent
+ *   successful call to tcsetattr() on the same termios structure.
+ *
+ *   NOTE 1: NuttX does not control input/output baud independently.  Both
+ *   must be the same.  The POSIX standard interfaces, cfisetispeed() and
+ *   cfisetospeed() are defined to be cfsetspeed() in termios.h.
+ *
+ *   NOTE 3: A consequence of NOTE 1 is that you should never attempt to
+ *   set the input and output baud to different values.
+ *
+ *   Also, the following POSIX requirement cannot be supported: "If the input
+ *   baud rate stored in the termios structure pointed to by termios_p is 0,
+ *   the input baud rate given to the hardware will be the same as the output
+ *   baud rate stored in the termios structure."
+ *
+ *   NOTE 2. In Nuttx, the speed_t is defined to be unsigned int and the baud
+ *   encodings of termios.h are baud value mask. And their corresponding
+ *   values are in array g_baud_table. However, if you do so, your code will
+ *   *NOT* be portable to other environments where speed_t is smaller and
+ *   where the termios.h baud values are encoded! To avoid portability
+ *   issues, use the baud definitions in termios.h!
+ *
+ *   Linux, for example, would require this (also non-portable) sequence:
+ *
+ *     cfsetispeed(termiosp, BOTHER);
+ *     termiosp->c_ispeed = baud;
+ *
+ *     cfsetospeed(termiosp, BOTHER);
+ *     termiosp->c_ospeed = baud;
+ *
+ * Input Parameters:
+ *   termiosp - The termiosp argument is a pointer to a termios structure.
+ *   speed - The new input speed. It could be baud rate or could be mask.
+ *
+ * Returned Value:
+ *   Baud is returned. If speed don't match g_baud_table and mask in
+ *   termios.h, -1 is returned and set errno EINVAL.
+ *
+ ****************************************************************************/
+
+int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
+{
+  int mask = baud_mask(speed);
+
+  DEBUGASSERT(termiosp);
+  if (mask == -1)
+    {
+      set_errno(-EINVAL);

Review comment:
       remove -

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0

Review comment:
       move before line 49

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);
+
+      case TCSETS:
+        return simuart_setcflag(priv->fd, termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?

##########
File path: arch/sim/src/sim/up_internal.h
##########
@@ -259,17 +259,22 @@ void up_timer_update(void);
 void rpmsg_serialinit(void);
 #endif
 
-/* up_devconsole.c **********************************************************/
+/* up_uart.c ****************************************************************/
 
-void up_devconsole(void);
-void up_devconloop(void);
+void up_uartinit(void);
+void up_uartloop(void);
 
 /* up_simuart.c *************************************************************/
 
 void simuart_start(void);
-int  simuart_putc(int ch);
-int  simuart_getc(void);
-bool simuart_checkc(void);
+int  simuart_open(const char *pathname);
+void simuart_close(int fd);
+int  simuart_putc(int fd, int ch);
+int  simuart_getc(int fd);
+bool simuart_checkc(int fd);
+void simuart_restoremode(void);

Review comment:
       remove which is the static function

##########
File path: arch/sim/src/sim/up_uart.c
##########
@@ -0,0 +1,570 @@
+/****************************************************************************
+ * arch/sim/src/sim/up_uart.c
+ *
+ *   Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <gn...@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 <nuttx/serial/serial.h>
+#include <nuttx/fs/ioctl.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "up_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BUFSIZE 256
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct tty_priv_s
+{
+  /* tty-port path name */
+
+  FAR const char *path;
+
+  /* The file descriptor. It is returned by open */
+
+  int             fd;
+};
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int  tty_setup(FAR struct uart_dev_s *dev);
+static void tty_shutdown(FAR struct uart_dev_s *dev);
+static int  tty_attach(FAR struct uart_dev_s *dev);
+static void tty_detach(FAR struct uart_dev_s *dev);
+static int  tty_ioctl(FAR struct file *filep, int cmd,
+                      unsigned long arg);
+static int  tty_receive(FAR struct uart_dev_s *dev, uint32_t *status);
+static void tty_rxint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_rxavailable(FAR struct uart_dev_s *dev);
+static void tty_send(FAR struct uart_dev_s *dev, int ch);
+static void tty_txint(FAR struct uart_dev_s *dev, bool enable);
+static bool tty_txready(FAR struct uart_dev_s *dev);
+static bool tty_txempty(FAR struct uart_dev_s *dev);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct uart_ops_s g_tty_ops =
+{
+  .setup          = tty_setup,
+  .shutdown       = tty_shutdown,
+  .attach         = tty_attach,
+  .detach         = tty_detach,
+  .ioctl          = tty_ioctl,
+  .receive        = tty_receive,
+  .rxint          = tty_rxint,
+  .rxavailable    = tty_rxavailable,
+  .send           = tty_send,
+  .txint          = tty_txint,
+  .txready        = tty_txready,
+  .txempty        = tty_txempty,
+};
+#endif
+
+#ifdef USE_DEVCONSOLE
+static char g_console_rxbuf[BUFSIZE];
+static char g_console_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static char g_tty0_rxbuf[BUFSIZE];
+static char g_tty0_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static char g_tty1_rxbuf[BUFSIZE];
+static char g_tty1_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static char g_tty2_rxbuf[BUFSIZE];
+static char g_tty2_txbuf[BUFSIZE];
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static char g_tty3_rxbuf[BUFSIZE];
+static char g_tty3_txbuf[BUFSIZE];
+#endif
+
+#ifdef USE_DEVCONSOLE
+static struct uart_dev_s g_console_dev =
+{
+  .isconsole      = true,
+  .ops            = &g_tty_ops,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_console_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART0_NAME
+static struct tty_priv_s g_tty0_priv =
+{
+  .path           = CONFIG_SIM_UART0_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty0_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty0_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty0_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART1_NAME
+static struct tty_priv_s g_tty1_priv =
+{
+  .path           = CONFIG_SIM_UART1_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty1_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty1_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty1_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART2_NAME
+static struct tty_priv_s g_tty2_priv =
+{
+  .path           = CONFIG_SIM_UART2_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty2_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty2_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty2_rxbuf,
+  },
+};
+#endif
+
+#ifdef CONFIG_SIM_UART3_NAME
+static struct tty_priv_s g_tty3_priv =
+{
+  .path           = CONFIG_SIM_UART3_NAME,
+  .fd             = -1,
+};
+
+static struct uart_dev_s g_tty3_dev =
+{
+  .ops            = &g_tty_ops,
+  .priv           = &g_tty3_priv,
+  .xmit =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_txbuf,
+  },
+  .recv =
+  {
+    .size         = BUFSIZE,
+    .buffer       = g_tty3_rxbuf,
+  },
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: tty_setup
+ *
+ * Description:
+ *   Configure the UART baud, bits, parity, fifos, etc. This
+ *   method is called the first time that the serial port is
+ *   opened.
+ *
+ ****************************************************************************/
+
+static int tty_setup(FAR struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd < 0)
+    {
+      priv->fd = simuart_open(priv->path);
+      if (priv->fd < 0)
+        {
+          return priv->fd;
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_shutdown
+ *
+ * Description:
+ *   Disable the UART.  This method is called when the serial
+ *   port is closed
+ *
+ ****************************************************************************/
+
+static void tty_shutdown(struct uart_dev_s *dev)
+{
+  FAR struct tty_priv_s *priv = dev->priv;
+
+  if (!dev->isconsole && priv->fd >= 0)
+    {
+      /* close file Description and reset fd */
+
+      simuart_close(priv->fd);
+      priv->fd = -1;
+    }
+}
+
+/****************************************************************************
+ * Name: tty_attach
+ *
+ * Description:
+ *   Configure the UART to operation in interrupt driven mode.  This method
+ *   is called when the serial port is opened.  Normally, this is just after
+ *   the setup() method is called, however, the serial console may operate in
+ *   a non-interrupt driven mode during the boot phase.
+ *
+ *   RX and TX interrupts are not enabled when by the attach method (unless
+ *   the hardware supports multiple levels of interrupt enabling).  The RX
+ *   and TX interrupts are not enabled until the txint() and rxint() methods
+ *   are called.
+ *
+ ****************************************************************************/
+
+static int tty_attach(struct uart_dev_s *dev)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Name: tty_detach
+ *
+ * Description:
+ *   Detach UART interrupts.  This method is called when the serial port is
+ *   closed normally just before the shutdown method is called.  The
+ *   exception is the serial console which is never shutdown.
+ *
+ ****************************************************************************/
+
+static void tty_detach(FAR struct uart_dev_s *dev)
+{
+}
+
+/****************************************************************************
+ * Name: tty_ioctl
+ *
+ * Description:
+ *   All ioctl calls will be routed through this method
+ *
+ ****************************************************************************/
+
+static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
+{
+#ifdef CONFIG_SERIAL_TERMIOS
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct uart_dev_s *dev = inode->i_private;
+  FAR struct tty_priv_s *priv = dev->priv;
+  FAR struct termios *termiosp = (FAR struct termios *)(uintptr_t)arg;
+
+  if (!termiosp)
+    {
+      return -EINVAL;
+    }
+
+  switch (cmd)
+    {
+      case TCGETS:
+        return simuart_getcflag(priv->fd, &termiosp->c_cflag);

Review comment:
       should we check dev->isconsole?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712542857


   @davids5 how about we apply #2040 which should fix the problem?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] davids5 commented on pull request #1767: To better access host tty interface on sim platform

Posted by GitBox <gi...@apache.org>.
davids5 commented on pull request #1767:
URL: https://github.com/apache/incubator-nuttx/pull/1767#issuecomment-712937780


   @xiaoxiang781216 & @Donny9  - thank you! 
   
   @xiaoxiang781216. I it is not just PX4 use case.  It is more things NuttX would be used for: Like profibus, radios, RS-485 networks, custom scada equipment, series of events recorders etc.  


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org