drivers uart_native_posix: rename to native_pty and support N instances
Rename the driver from uart_native_posix to uart_native_pty. Including renaming the DTS compatible, and kconfig options, deprecating the old ones. And refactor the driver, generalizing it, so we can have any number of instances. Note that, unfortunately generalizing to N instances cannot be done without a degree of backwards compatibility breakage: This driver was born with all its configuration and selection of the instances based on kconfig. When the driver was made to use DT, it was done in a way that required both DT and kconfig needing to manually coherently enable the 2nd UART. This has now been fixed, which it means only DT is used to decide how many instances are avaliable, and UART_NATIVE_POSIX_PORT_1_ENABLE is just ignored. Including: * Deprecate UART_NATIVE_WAIT_PTS_READY_ENABLE: the options is always on now as it has no practical drawbacks. * Deprecate UART_NATIVE_POSIX_PORT_1_ENABLE: DTS intanciation defines it being available now. * Rename a few functions and in general shorten pseudo-tty/pseudo- terminal to PTY instead of PTTY. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
d811f6921c
commit
cb53e40ff9
37 changed files with 537 additions and 434 deletions
|
@ -310,10 +310,10 @@ The following peripherals are currently provided with this board:
|
|||
**UART/Serial**
|
||||
Two optional native UART drivers are available:
|
||||
|
||||
**PTTY driver (UART_NATIVE_POSIX)**
|
||||
With this driver, one or two Zephyr UART devices can be created. These
|
||||
**PTY driver (UART_NATIVE_PTY)**
|
||||
With this driver, Zephyr UART devices can be created. These
|
||||
can be connected to the Linux process stdin/stdout or a newly created
|
||||
pseudo-tty. For more information refer to the section `PTTY UART`_.
|
||||
pseudo-tty. For more information refer to the section `PTY UART`_.
|
||||
|
||||
**TTY driver (UART_NATIVE_TTY)**
|
||||
An UART driver for interacting with host-attached serial port devices
|
||||
|
@ -510,44 +510,46 @@ The following peripherals are currently provided with this board:
|
|||
|
||||
.. _native_ptty_uart:
|
||||
|
||||
PTTY UART
|
||||
PTY UART
|
||||
=========
|
||||
|
||||
This driver can be configured with :kconfig:option:`CONFIG_UART_NATIVE_POSIX`
|
||||
to instantiate up to two UARTs. By default only one UART is enabled.
|
||||
With :kconfig:option:`CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE`
|
||||
you can enable the second one.
|
||||
This driver is automatically enabled when devicetree contains nodes with the
|
||||
``"zephyr,native-pty-uart"`` compatible property and ``okay`` status and
|
||||
:kconfig:option:`CONFIG_SERIAL` is set.
|
||||
By default one ready UART of this type is setup in DTS, but any number can be enabled as desired.
|
||||
|
||||
For the first UART, it can link it to a new
|
||||
pseudoterminal (i.e. :file:`/dev/pts{<nbr>}`), or map the UART input and
|
||||
output to the executable's ``stdin`` and ``stdout``.
|
||||
This is chosen by selecting either
|
||||
:kconfig:option:`CONFIG_NATIVE_UART_0_ON_OWN_PTY` or
|
||||
:kconfig:option:`CONFIG_NATIVE_UART_0_ON_STDINOUT`
|
||||
For interactive use with the :ref:`shell_api`, choose the first (OWN_PTY) option.
|
||||
The second (STDINOUT) option can be used with the shell for automated
|
||||
testing, such as when piping other processes' output to control it.
|
||||
This is because the shell subsystem expects access to a raw terminal,
|
||||
Normally these UARTs are connected to new pseudoterminals PTYs, i.e. :file:`/dev/pts{<nbr>}`,
|
||||
but it is also possible to map one of them to the executable's ``stdin`` and ``stdout``.
|
||||
This can be done in two ways, either with the command line option ``--<uart_name>_stdinout``
|
||||
(where ``<uart_name>`` is the UART DTS node name), or, for the first PTY UART instance by chosing
|
||||
:kconfig:option:`CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT` instead of the default
|
||||
:kconfig:option:`CONFIG_UART_NATIVE_PTY_0_ON_OWN_PTY`.
|
||||
For interactive use with the :ref:`shell_api`, it is recommended to choose the PTY option.
|
||||
The ``STDINOUT`` option can be used for automated testing, such as when piping other processes'
|
||||
output to control it. This is because the shell subsystem expects access to a raw terminal,
|
||||
which (by default) a normal Linux terminal is not.
|
||||
|
||||
When :kconfig:option:`CONFIG_NATIVE_UART_0_ON_OWN_PTY` is chosen, the name of the
|
||||
newly created UART pseudo-terminal will be displayed in the console.
|
||||
If you want to interact with it manually, you should attach a terminal emulator
|
||||
to it. This can be done, for example with the command:
|
||||
When a UART is connected to a new PTY, the name of the newly created UART pseudo-terminal will be
|
||||
displayed in the console.
|
||||
If you want to interact with it manually, you should attach a terminal emulator to it.
|
||||
This can be done, for example with the command:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ xterm -e screen /dev/<ttyn> &
|
||||
$ xterm -e screen /dev/<ptyn> &
|
||||
# Or if you prefer gnome-terminal:
|
||||
$ gnome-terminal -- screen /dev/<ptyn> &
|
||||
|
||||
where :file:`/dev/tty{<n>}` should be replaced with the actual TTY device.
|
||||
where :file:`/dev/{<ptyn>}` should be replaced with the actual PTY device.
|
||||
|
||||
You may also chose to automatically attach a terminal emulator to the first UART
|
||||
by passing the command line option ``-attach_uart`` to the executable.
|
||||
The command used for attaching to the new shell can be set with the command line
|
||||
option ``-attach_uart_cmd=<"cmd">``. Where the default command is given by
|
||||
:kconfig:option:`CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD`.
|
||||
Note that the default command assumes both ``xterm`` and ``screen`` are
|
||||
installed in the system.
|
||||
You may also chose to automatically attach a terminal emulator to any of these UARTs.
|
||||
To automatically attach one to all these UARTs, pass the command line option ``-attach_uart`` to the
|
||||
executable. To automatically attach one to a single UART use ``-<uart_name>_attach_uart``
|
||||
The command used for attaching to the new shell can be set for all UARTs with the command line
|
||||
option ``-attach_uart_cmd=<"cmd">``, or for each individual UART with
|
||||
``-<uart_name>_attach_uart_cmd``. Where the default command is given by
|
||||
:kconfig:option:`CONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD`.
|
||||
Note that the default command assumes both ``xterm`` and ``screen`` are installed in the system.
|
||||
|
||||
This driver only supports poll mode. Interrupt and async mode are not supported.
|
||||
Neither runtime configuration or line control are supported.
|
||||
|
@ -713,7 +715,7 @@ host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`):
|
|||
Logger backend, :ref:`Native backend <nsim_back_logger>`, :kconfig:option:`CONFIG_LOG_BACKEND_NATIVE_POSIX`, All
|
||||
Offloaded sockets, :ref:`nsim_per_offloaded_sockets`, :kconfig:option:`CONFIG_NET_NATIVE_OFFLOADED_SOCKETS`, All
|
||||
RTC, RTC emul, :kconfig:option:`CONFIG_RTC_EMUL`, All
|
||||
Serial, :ref:`UART native posix/PTTY <native_ptty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_POSIX`, All
|
||||
Serial, :ref:`UART native PTY <native_ptty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_PTY`, All
|
||||
Serial, :ref:`UART native TTY <native_tty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_TTY`, All
|
||||
SPI, SPI emul, :kconfig:option:`CONFIG_SPI_EMUL`, All
|
||||
System tick, Native_posix timer, :kconfig:option:`CONFIG_NATIVE_POSIX_TIMER`, All
|
||||
|
|
|
@ -147,7 +147,7 @@
|
|||
|
||||
uart0: uart {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/* Dummy current-speed entry to comply with serial
|
||||
* DTS binding
|
||||
*/
|
||||
|
@ -155,8 +155,8 @@
|
|||
};
|
||||
|
||||
uart1: uart_1 {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
status = "disabled";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/* Dummy current-speed entry to comply with serial
|
||||
* DTS binding
|
||||
*/
|
||||
|
|
|
@ -58,7 +58,7 @@ Then create a sample and enable Ethernet bridging support. In this example we cr
|
|||
|
||||
west build -p -b native_sim -d ../build/echo-server \
|
||||
samples/net/sockets/echo_server -- \
|
||||
-DCONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD="\"gnome-terminal -- screen %s\"" \
|
||||
-DCONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD="\"gnome-terminal -- screen %s\"" \
|
||||
-DCONFIG_NET_ETHERNET_BRIDGE=y \
|
||||
-DCONFIG_NET_ETHERNET_BRIDGE_SHELL=y \
|
||||
-DCONFIG_ETH_NATIVE_TAP_INTERFACE_COUNT=2 \
|
||||
|
|
|
@ -117,7 +117,7 @@ In terminal #3, type:
|
|||
:zephyr-app: samples/net/capture
|
||||
:host-os: unix
|
||||
:board: native_sim
|
||||
:gen-args: -DCONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD=\""gnome-terminal -- screen %s"\"
|
||||
:gen-args: -DCONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD=\""gnome-terminal -- screen %s"\"
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
|
|
|
@ -103,13 +103,13 @@ if (CONFIG_UART_NRFX_UARTE)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_UART_NATIVE_POSIX)
|
||||
if(CONFIG_UART_NATIVE_PTY)
|
||||
zephyr_library_compile_definitions(NO_POSIX_CHEATS)
|
||||
zephyr_library_sources(uart_native_ptty.c)
|
||||
zephyr_library_sources(uart_native_pty.c)
|
||||
if (CONFIG_NATIVE_APPLICATION)
|
||||
zephyr_library_sources(uart_native_ptty_bottom.c)
|
||||
zephyr_library_sources(uart_native_pty_bottom.c)
|
||||
else()
|
||||
target_sources(native_simulator INTERFACE uart_native_ptty_bottom.c)
|
||||
target_sources(native_simulator INTERFACE uart_native_pty_bottom.c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ rsource "Kconfig.mcux_lpuart"
|
|||
rsource "Kconfig.mec5"
|
||||
rsource "Kconfig.miv"
|
||||
rsource "Kconfig.msp432p4xx"
|
||||
rsource "Kconfig.native_posix"
|
||||
rsource "Kconfig.native_pty"
|
||||
rsource "Kconfig.native_tty"
|
||||
rsource "Kconfig.neorv32"
|
||||
rsource "Kconfig.npcx"
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config UART_NATIVE_POSIX
|
||||
bool "UART driver for native_sim/posix"
|
||||
default y
|
||||
depends on DT_HAS_ZEPHYR_NATIVE_POSIX_UART_ENABLED
|
||||
select SERIAL_HAS_DRIVER
|
||||
help
|
||||
This enables a UART driver for the POSIX ARCH with up to 2 UARTs.
|
||||
For the first UART port, the driver can be configured
|
||||
to either connect to the terminal from which the executable was run, or into
|
||||
one dedicated pseudoterminal for that UART.
|
||||
|
||||
if UART_NATIVE_POSIX
|
||||
|
||||
choice NATIVE_UART_0
|
||||
prompt "Native UART Port 0 connection"
|
||||
default NATIVE_UART_0_ON_OWN_PTY
|
||||
|
||||
config NATIVE_UART_0_ON_OWN_PTY
|
||||
bool "Connect the UART to its own pseudo terminal"
|
||||
help
|
||||
Connect this UART to its own pseudoterminal. This is the preferred
|
||||
option for users who want to use Zephyr's shell.
|
||||
Moreover this option does not conflict with any other native
|
||||
backend which may use the invoking shell standard input/output.
|
||||
|
||||
config NATIVE_UART_0_ON_STDINOUT
|
||||
bool "Connect the UART to the invoking shell stdin/stdout"
|
||||
help
|
||||
Connect this UART to the stdin & stdout of the calling shell/terminal
|
||||
which invoked the native executable. This is good enough for
|
||||
automated testing, or when feeding from a file/pipe.
|
||||
Note that other, non UART messages, will also be printed to the
|
||||
terminal.
|
||||
It is strongly discouraged to try to use this option with the new
|
||||
shell interactively, as the default terminal configuration is NOT
|
||||
appropriate for interactive use.
|
||||
|
||||
endchoice
|
||||
|
||||
config UART_NATIVE_WAIT_PTS_READY_ENABLE
|
||||
bool "Support waiting for pseudo terminal client readiness"
|
||||
depends on NATIVE_UART_0_ON_OWN_PTY || UART_NATIVE_POSIX_PORT_1_ENABLE
|
||||
help
|
||||
When this option is selected a new command line switch is provided:
|
||||
``--wait_uart``
|
||||
When ``--wait_uart`` is used, writes to the UART will be held until a
|
||||
client has connected to the slave side of the pseudoterminal.
|
||||
Otherwise writes are sent irrespectively.
|
||||
|
||||
config UART_NATIVE_POSIX_PORT_1_ENABLE
|
||||
bool "Second UART port"
|
||||
help
|
||||
Useful if you need to have another serial connection to host.
|
||||
This is used for example in PPP (Point-to-Point Protocol)
|
||||
implementation.
|
||||
|
||||
config NATIVE_UART_AUTOATTACH_DEFAULT_CMD
|
||||
string "Default command to attach the UART to a new terminal"
|
||||
default "xterm -e screen %s &"
|
||||
help
|
||||
If the native executable is called with the --attach_uart
|
||||
command line option, this will be the default command which will be
|
||||
run to attach a new terminal to the 1st UART.
|
||||
Note that this command must have one, and only one, '%s' as
|
||||
placeholder for the pseudoterminal device name (e.g. /dev/pts/35)
|
||||
This is only applicable if the UART_0 is configured to use its own
|
||||
PTY with NATIVE_UART_0_ON_OWN_PTY.
|
||||
The 2nd UART will not be affected by this option.
|
||||
If you are using GNOME, then you can use this command string
|
||||
'gnome-terminal -- screen %s'
|
||||
|
||||
endif # UART_NATIVE_POSIX
|
105
drivers/serial/Kconfig.native_pty
Normal file
105
drivers/serial/Kconfig.native_pty
Normal file
|
@ -0,0 +1,105 @@
|
|||
# Copyright (c) 2025, Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config UART_NATIVE_PTY
|
||||
bool "PTY based UART driver for native_sim"
|
||||
default y
|
||||
depends on (DT_HAS_ZEPHYR_NATIVE_PTY_UART_ENABLED || DT_HAS_ZEPHYR_NATIVE_POSIX_UART_ENABLED)
|
||||
select SERIAL_HAS_DRIVER
|
||||
help
|
||||
This enables a PTY based UART driver for the POSIX ARCH with up to 2 UARTs.
|
||||
For the first UART port, the driver can be configured
|
||||
to either connect to the terminal from which the executable was run, or into
|
||||
one dedicated pseudoterminal for that UART.
|
||||
|
||||
config UART_NATIVE_POSIX
|
||||
bool "UART driver for native_sim (deprecated)"
|
||||
select SERIAL_HAS_DRIVER
|
||||
select DEPRECATED
|
||||
select UART_NATIVE_PTY
|
||||
help
|
||||
Deprecated option, use UART_NATIVE_PTY instead
|
||||
|
||||
if (UART_NATIVE_PTY || UART_NATIVE_POSIX)
|
||||
|
||||
choice UART_NATIVE_PTY_0
|
||||
prompt "Native PTY Port 0 connection"
|
||||
default UART_NATIVE_PTY_0_ON_STDINOUT if NATIVE_UART_0_ON_STDINOUT
|
||||
default UART_NATIVE_PTY_0_ON_OWN_PTY
|
||||
|
||||
config UART_NATIVE_PTY_0_ON_OWN_PTY
|
||||
bool "Connect the first PTY UART to its own pseudo terminal"
|
||||
help
|
||||
Connect this UART to its own pseudoterminal. This is the preferred
|
||||
option for users who want to use Zephyr's shell.
|
||||
Moreover this option does not conflict with any other native
|
||||
backend which may use the invoking shell standard input/output.
|
||||
Note it can be overridden from command line
|
||||
|
||||
config UART_NATIVE_PTY_0_ON_STDINOUT
|
||||
bool "Connect the first PTY UART to the invoking shell stdin/stdout"
|
||||
help
|
||||
Connect this UART to the stdin & stdout of the calling shell/terminal
|
||||
which invoked the native executable. This is good enough for
|
||||
automated testing, or when feeding from a file/pipe.
|
||||
Note that other, non UART messages, will also be printed to the
|
||||
terminal.
|
||||
It is strongly discouraged to try to use this option with the new
|
||||
shell interactively, as the default terminal configuration is NOT
|
||||
appropriate for interactive use.
|
||||
|
||||
endchoice
|
||||
|
||||
choice NATIVE_UART_0
|
||||
prompt "Native UART Port 0 connection (deprecated)"
|
||||
default NATIVE_UART_0_ON_OWN_PTY
|
||||
|
||||
config NATIVE_UART_0_ON_OWN_PTY
|
||||
bool "Connect the UART to its own pseudo terminal (deprecated)"
|
||||
help
|
||||
Deprecated, use UART_NATIVE_PTY_0_ON_OWN_PTY instead.
|
||||
|
||||
config NATIVE_UART_0_ON_STDINOUT
|
||||
bool "Connect the UART to the invoking shell stdin/stdout (deprecated)"
|
||||
select DEPRECATED
|
||||
help
|
||||
Deprecated, use UART_NATIVE_PTY_0_ON_STDINOUT instead.
|
||||
|
||||
endchoice
|
||||
|
||||
config UART_NATIVE_WAIT_PTS_READY_ENABLE
|
||||
bool "Support waiting for pseudo terminal client readiness (deprecated)"
|
||||
select DEPRECATED
|
||||
help
|
||||
This option is deprecated and does not do anything anymore. (The command line
|
||||
option --wait_uart is always available).
|
||||
|
||||
config UART_NATIVE_POSIX_PORT_1_ENABLE
|
||||
bool "Second UART port (deprecated)"
|
||||
select DEPRECATED
|
||||
help
|
||||
This option does not do anything anymore. Use DTS to instantiate as many
|
||||
"zephyr,native-pty-uart" compatible nodes as you want.
|
||||
|
||||
config UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD
|
||||
string "Default command to attach a PTY UART to a new terminal"
|
||||
default NATIVE_UART_AUTOATTACH_DEFAULT_CMD
|
||||
help
|
||||
If the native executable is called with the --attach_uart
|
||||
command line option, this will be the default command which will be
|
||||
run to attach a new terminal to the 1st UART.
|
||||
Note that this command must have one, and only one, '%s' as
|
||||
placeholder for the pseudoterminal device name (e.g. /dev/pts/35)
|
||||
This is only applicable if the UART_0 is configured to use its own
|
||||
PTY with NATIVE_UART_0_ON_OWN_PTY.
|
||||
The 2nd UART will not be affected by this option.
|
||||
If you are using GNOME, then you can use this command string
|
||||
'gnome-terminal -- screen %s'
|
||||
|
||||
config NATIVE_UART_AUTOATTACH_DEFAULT_CMD
|
||||
string "Default command to attach the UART to a new terminal (deprecated)"
|
||||
default "xterm -e screen %s &"
|
||||
help
|
||||
Deprecated. Use UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD instead
|
||||
|
||||
endif # UART_NATIVE_PTY || UART_NATIVE_POSIX
|
|
@ -1,279 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oticon A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_native_posix_uart
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include "cmdline.h" /* native_posix command line options header */
|
||||
#include "posix_native_task.h"
|
||||
#include "uart_native_ptty_bottom.h"
|
||||
#include "nsi_host_trampolines.h"
|
||||
|
||||
/*
|
||||
* UART driver for POSIX ARCH based boards.
|
||||
* It can support up to two UARTs.
|
||||
*
|
||||
* For the first UART:
|
||||
*
|
||||
* It can either be connected to the process STDIN+STDOUT
|
||||
* OR
|
||||
* to a dedicated pseudo terminal
|
||||
*
|
||||
* The 2nd option is the recommended one for interactive use, as the pseudo
|
||||
* terminal driver will be configured in "raw" mode, and will therefore behave
|
||||
* more like a real UART.
|
||||
*
|
||||
* When connected to its own pseudo terminal, it may also auto attach a terminal
|
||||
* emulator to it, if set so from command line.
|
||||
*/
|
||||
|
||||
static int np_uart_stdin_poll_in(const struct device *dev,
|
||||
unsigned char *p_char);
|
||||
static int np_uart_tty_poll_in(const struct device *dev,
|
||||
unsigned char *p_char);
|
||||
static void np_uart_poll_out(const struct device *dev,
|
||||
unsigned char out_char);
|
||||
|
||||
static bool auto_attach;
|
||||
static bool wait_pts;
|
||||
static char *auto_attach_cmd = CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD;
|
||||
|
||||
struct native_uart_status {
|
||||
int out_fd; /* File descriptor used for output */
|
||||
int in_fd; /* File descriptor used for input */
|
||||
};
|
||||
|
||||
static struct native_uart_status native_uart_status_0;
|
||||
|
||||
static DEVICE_API(uart, np_uart_driver_api_0) = {
|
||||
.poll_out = np_uart_poll_out,
|
||||
#if defined(CONFIG_NATIVE_UART_0_ON_OWN_PTY)
|
||||
.poll_in = np_uart_tty_poll_in,
|
||||
#else
|
||||
.poll_in = np_uart_stdin_poll_in,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE)
|
||||
static struct native_uart_status native_uart_status_1;
|
||||
|
||||
static DEVICE_API(uart, np_uart_driver_api_1) = {
|
||||
.poll_out = np_uart_poll_out,
|
||||
.poll_in = np_uart_tty_poll_in,
|
||||
};
|
||||
#endif /* CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE */
|
||||
|
||||
#define ERROR posix_print_error_and_exit
|
||||
#define WARN posix_print_warning
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the first native_posix serial port
|
||||
*
|
||||
* @param dev UART_0 device struct
|
||||
*
|
||||
* @return 0 (if it fails catastrophically, the execution is terminated)
|
||||
*/
|
||||
static int np_uart_0_init(const struct device *dev)
|
||||
{
|
||||
struct native_uart_status *d;
|
||||
|
||||
d = (struct native_uart_status *)dev->data;
|
||||
|
||||
if (IS_ENABLED(CONFIG_NATIVE_UART_0_ON_OWN_PTY)) {
|
||||
int tty_fn = np_uart_open_ptty(dev->name, auto_attach_cmd, auto_attach, wait_pts);
|
||||
|
||||
d->in_fd = tty_fn;
|
||||
d->out_fd = tty_fn;
|
||||
} else { /* NATIVE_UART_0_ON_STDINOUT */
|
||||
d->in_fd = np_uart_ptty_get_stdin_fileno();
|
||||
d->out_fd = np_uart_ptty_get_stdout_fileno();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE)
|
||||
/*
|
||||
* Initialize the 2nd UART port.
|
||||
* This port will be always attached to its own new pseudoterminal.
|
||||
*/
|
||||
static int np_uart_1_init(const struct device *dev)
|
||||
{
|
||||
struct native_uart_status *d;
|
||||
int tty_fn;
|
||||
|
||||
d = (struct native_uart_status *)dev->data;
|
||||
|
||||
tty_fn = np_uart_open_ptty(dev->name, NULL, false, wait_pts);
|
||||
|
||||
d->in_fd = tty_fn;
|
||||
d->out_fd = tty_fn;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @brief Output a character towards the serial port
|
||||
*
|
||||
* @param dev UART device struct
|
||||
* @param out_char Character to send.
|
||||
*/
|
||||
static void np_uart_poll_out(const struct device *dev,
|
||||
unsigned char out_char)
|
||||
{
|
||||
int ret;
|
||||
struct native_uart_status *d = (struct native_uart_status *)dev->data;
|
||||
|
||||
if (wait_pts) {
|
||||
|
||||
while (1) {
|
||||
int rc = np_uart_slave_connected(d->out_fd);
|
||||
|
||||
if (rc == 1) {
|
||||
break;
|
||||
}
|
||||
k_sleep(K_MSEC(100));
|
||||
}
|
||||
}
|
||||
|
||||
/* The return value of write() cannot be ignored (there is a warning)
|
||||
* but we do not need the return value for anything.
|
||||
*/
|
||||
ret = nsi_host_write(d->out_fd, &out_char, 1);
|
||||
(void) ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll the device for input.
|
||||
*
|
||||
* @param dev UART device structure.
|
||||
* @param p_char Pointer to character.
|
||||
*
|
||||
* @retval 0 If a character arrived and was stored in p_char
|
||||
* @retval -1 If no character was available to read
|
||||
*/
|
||||
static int __maybe_unused np_uart_stdin_poll_in(const struct device *dev, unsigned char *p_char)
|
||||
{
|
||||
int in_f = ((struct native_uart_status *)dev->data)->in_fd;
|
||||
static bool disconnected;
|
||||
int rc;
|
||||
|
||||
if (disconnected == true) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = np_uart_stdin_poll_in_bottom(in_f, p_char);
|
||||
if (rc == -2) {
|
||||
disconnected = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll the device for input.
|
||||
*
|
||||
* @param dev UART device structure.
|
||||
* @param p_char Pointer to character.
|
||||
*
|
||||
* @retval 0 If a character arrived and was stored in p_char
|
||||
* @retval -1 If no character was available to read
|
||||
*/
|
||||
static int __maybe_unused np_uart_tty_poll_in(const struct device *dev, unsigned char *p_char)
|
||||
{
|
||||
int n = -1;
|
||||
int in_f = ((struct native_uart_status *)dev->data)->in_fd;
|
||||
|
||||
n = nsi_host_read(in_f, p_char, 1);
|
||||
if (n == -1) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0,
|
||||
np_uart_0_init, NULL,
|
||||
(void *)&native_uart_status_0, NULL,
|
||||
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
|
||||
&np_uart_driver_api_0);
|
||||
|
||||
#if defined(CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE)
|
||||
DEVICE_DT_INST_DEFINE(1,
|
||||
np_uart_1_init, NULL,
|
||||
(void *)&native_uart_status_1, NULL,
|
||||
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
|
||||
&np_uart_driver_api_1);
|
||||
#endif /* CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE */
|
||||
|
||||
static void auto_attach_cmd_cb(char *argv, int offset)
|
||||
{
|
||||
auto_attach_cmd = &argv[offset];
|
||||
auto_attach = true;
|
||||
}
|
||||
|
||||
static void np_add_uart_options(void)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_NATIVE_UART_0_ON_OWN_PTY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
static struct args_struct_t uart_options[] = {
|
||||
{
|
||||
.is_switch = true,
|
||||
.option = "attach_uart",
|
||||
.type = 'b',
|
||||
.dest = (void *)&auto_attach,
|
||||
.descript = "Automatically attach to the UART terminal"
|
||||
},
|
||||
{
|
||||
.option = "attach_uart_cmd",
|
||||
.name = "\"cmd\"",
|
||||
.type = 's',
|
||||
.call_when_found = auto_attach_cmd_cb,
|
||||
.descript = "Command used to automatically attach to the terminal (implies "
|
||||
"auto_attach), by default: "
|
||||
"'" CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD "'"
|
||||
},
|
||||
IF_ENABLED(CONFIG_UART_NATIVE_WAIT_PTS_READY_ENABLE, (
|
||||
{
|
||||
.is_switch = true,
|
||||
.option = "wait_uart",
|
||||
.type = 'b',
|
||||
.dest = (void *)&wait_pts,
|
||||
.descript = "Hold writes to the uart/pts until a client is connected/ready"
|
||||
},
|
||||
))
|
||||
ARG_TABLE_ENDMARKER
|
||||
};
|
||||
|
||||
native_add_command_line_opts(uart_options);
|
||||
}
|
||||
|
||||
static void np_cleanup_uart(void)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_NATIVE_UART_0_ON_OWN_PTY)) {
|
||||
if (native_uart_status_0.in_fd != 0) {
|
||||
nsi_host_close(native_uart_status_0.in_fd);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE)
|
||||
if (native_uart_status_1.in_fd != 0) {
|
||||
nsi_host_close(native_uart_status_1.in_fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
NATIVE_TASK(np_add_uart_options, PRE_BOOT_1, 11);
|
||||
NATIVE_TASK(np_cleanup_uart, ON_EXIT, 99);
|
323
drivers/serial/uart_native_pty.c
Normal file
323
drivers/serial/uart_native_pty.c
Normal file
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oticon A/S
|
||||
* Copyright (c) 2025, Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/devicetree.h>
|
||||
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_native_posix_uart)
|
||||
#define DT_DRV_COMPAT zephyr_native_posix_uart
|
||||
#warning "zephyr,native-posix-uart is deprecated in favor of zephyr,native-pty-uart"
|
||||
#else
|
||||
#define DT_DRV_COMPAT zephyr_native_pty_uart
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <cmdline.h> /* native_sim command line options header */
|
||||
#include <posix_native_task.h>
|
||||
#include <nsi_host_trampolines.h>
|
||||
#include <nsi_tracing.h>
|
||||
#include "uart_native_pty_bottom.h"
|
||||
|
||||
#define ERROR posix_print_error_and_exit
|
||||
#define WARN posix_print_warning
|
||||
|
||||
/*
|
||||
* UART driver for native simulator based boards.
|
||||
* It can support a configurable number of UARTs.
|
||||
*
|
||||
* One (and only one) of this can be connected to the process STDIN+STDOUT otherwise, they are
|
||||
* connected to a dedicated pseudo terminal.
|
||||
*
|
||||
* Connecting to a dedicated PTY is the recommended option for interactive use, as the pseudo
|
||||
* terminal driver will be configured in "raw" mode and will therefore behave more like a real UART.
|
||||
*
|
||||
* When connected to its own pseudo terminal, it may also auto attach a terminal emulator to it,
|
||||
* if set so from command line.
|
||||
*/
|
||||
|
||||
struct native_pty_status {
|
||||
int out_fd; /* File descriptor used for output */
|
||||
int in_fd; /* File descriptor used for input */
|
||||
bool on_stdinout; /* This UART is connected to a PTY and not STDIN/OUT */
|
||||
|
||||
bool auto_attach; /* For PTY, attach a terminal emulator automatically */
|
||||
char *auto_attach_cmd; /* If auto_attach, which command to launch the terminal emulator */
|
||||
bool wait_pts; /* Hold writes to the uart/pts until a client is connected/ready */
|
||||
bool cmd_request_stdinout; /* User requested to connect this UART to the stdin/out */
|
||||
};
|
||||
|
||||
static void np_uart_poll_out(const struct device *dev, unsigned char out_char);
|
||||
static int np_uart_poll_in(const struct device *dev, unsigned char *p_char);
|
||||
static int np_uart_init(const struct device *dev);
|
||||
|
||||
static DEVICE_API(uart, np_uart_driver_api) = {
|
||||
.poll_out = np_uart_poll_out,
|
||||
.poll_in = np_uart_poll_in,
|
||||
};
|
||||
|
||||
#define NATIVE_PTY_INSTANCE(inst) \
|
||||
static struct native_pty_status native_pty_status_##inst; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, np_uart_init, NULL, \
|
||||
(void *)&native_pty_status_##inst, NULL, \
|
||||
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
|
||||
&np_uart_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(NATIVE_PTY_INSTANCE);
|
||||
|
||||
/**
|
||||
* @brief Initialize a native_pty serial port
|
||||
*
|
||||
* @param dev uart device struct
|
||||
*
|
||||
* @return 0 (if it fails catastrophically, the execution is terminated)
|
||||
*/
|
||||
static int np_uart_init(const struct device *dev)
|
||||
{
|
||||
|
||||
static bool stdinout_used;
|
||||
struct native_pty_status *d;
|
||||
|
||||
d = (struct native_pty_status *)dev->data;
|
||||
|
||||
if (IS_ENABLED(CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT)) {
|
||||
static bool first_node = true;
|
||||
|
||||
if (first_node) {
|
||||
d->on_stdinout = true;
|
||||
}
|
||||
first_node = false;
|
||||
}
|
||||
|
||||
if (d->cmd_request_stdinout) {
|
||||
if (stdinout_used) {
|
||||
nsi_print_warning("%s requested to connect to STDIN/OUT, but another UART"
|
||||
" is already connected to it => ignoring request.\n",
|
||||
dev->name);
|
||||
} else {
|
||||
d->on_stdinout = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (d->on_stdinout == true) {
|
||||
d->in_fd = np_uart_pty_get_stdin_fileno();
|
||||
d->out_fd = np_uart_pty_get_stdout_fileno();
|
||||
stdinout_used = true;
|
||||
} else {
|
||||
if (d->auto_attach_cmd == NULL) {
|
||||
d->auto_attach_cmd = CONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD;
|
||||
} else { /* Running with --attach_uart_cmd, implies --attach_uart */
|
||||
d->auto_attach = true;
|
||||
}
|
||||
int tty_fn = np_uart_open_pty(dev->name, d->auto_attach_cmd, d->auto_attach,
|
||||
d->wait_pts);
|
||||
d->in_fd = tty_fn;
|
||||
d->out_fd = tty_fn;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Output a character towards the serial port
|
||||
*
|
||||
* @param dev UART device struct
|
||||
* @param out_char Character to send.
|
||||
*/
|
||||
static void np_uart_poll_out(const struct device *dev, unsigned char out_char)
|
||||
{
|
||||
int ret;
|
||||
struct native_pty_status *d = (struct native_pty_status *)dev->data;
|
||||
|
||||
if (d->wait_pts) {
|
||||
while (1) {
|
||||
int rc = np_uart_slave_connected(d->out_fd);
|
||||
|
||||
if (rc == 1) {
|
||||
break;
|
||||
}
|
||||
k_sleep(K_MSEC(100));
|
||||
}
|
||||
}
|
||||
|
||||
/* The return value of write() cannot be ignored (there is a warning)
|
||||
* but we do not need the return value for anything.
|
||||
*/
|
||||
ret = nsi_host_write(d->out_fd, &out_char, 1);
|
||||
(void) ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll the device for input.
|
||||
*
|
||||
* @param dev UART device structure.
|
||||
* @param p_char Pointer to character.
|
||||
*
|
||||
* @retval 0 If a character arrived and was stored in p_char
|
||||
* @retval -1 If no character was available to read
|
||||
*/
|
||||
static int np_uart_stdin_poll_in(const struct device *dev, unsigned char *p_char)
|
||||
{
|
||||
int in_f = ((struct native_pty_status *)dev->data)->in_fd;
|
||||
static bool disconnected;
|
||||
int rc;
|
||||
|
||||
if (disconnected == true) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = np_uart_stdin_poll_in_bottom(in_f, p_char);
|
||||
if (rc == -2) {
|
||||
disconnected = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll the device for input.
|
||||
*
|
||||
* @param dev UART device structure.
|
||||
* @param p_char Pointer to character.
|
||||
*
|
||||
* @retval 0 If a character arrived and was stored in p_char
|
||||
* @retval -1 If no character was available to read
|
||||
*/
|
||||
static int np_uart_pty_poll_in(const struct device *dev, unsigned char *p_char)
|
||||
{
|
||||
int n = -1;
|
||||
int in_f = ((struct native_pty_status *)dev->data)->in_fd;
|
||||
|
||||
n = nsi_host_read(in_f, p_char, 1);
|
||||
if (n == -1) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int np_uart_poll_in(const struct device *dev, unsigned char *p_char)
|
||||
{
|
||||
if (((struct native_pty_status *)dev->data)->on_stdinout) {
|
||||
return np_uart_stdin_poll_in(dev, p_char);
|
||||
} else {
|
||||
return np_uart_pty_poll_in(dev, p_char);
|
||||
}
|
||||
}
|
||||
|
||||
#define NATIVE_PTY_SET_AUTO_ATTACH_CMD(inst, cmd) \
|
||||
native_pty_status_##inst.auto_attach_cmd = cmd;
|
||||
#define NATIVE_PTY_SET_AUTO_ATTACH(inst, value) \
|
||||
native_pty_status_##inst.auto_attach = value;
|
||||
#define NATIVE_PTY_SET_WAIT_PTS(inst, value) \
|
||||
native_pty_status_##inst.wait_pts = value;
|
||||
|
||||
static void auto_attach_cmd_cb(char *argv, int offset)
|
||||
{
|
||||
DT_INST_FOREACH_STATUS_OKAY_VARGS(NATIVE_PTY_SET_AUTO_ATTACH_CMD, &argv[offset]);
|
||||
DT_INST_FOREACH_STATUS_OKAY_VARGS(NATIVE_PTY_SET_AUTO_ATTACH, true);
|
||||
}
|
||||
|
||||
static void auto_attach_cb(char *argv, int offset)
|
||||
{
|
||||
DT_INST_FOREACH_STATUS_OKAY_VARGS(NATIVE_PTY_SET_AUTO_ATTACH, true);
|
||||
}
|
||||
|
||||
static void wait_pts_cb(char *argv, int offset)
|
||||
{
|
||||
DT_INST_FOREACH_STATUS_OKAY_VARGS(NATIVE_PTY_SET_WAIT_PTS, true);
|
||||
}
|
||||
|
||||
#define INST_NAME(inst) DEVICE_DT_NAME(DT_DRV_INST(inst))
|
||||
|
||||
#define NATIVE_PTY_COMMAND_LINE_OPTS(inst) \
|
||||
{ \
|
||||
.is_switch = true, \
|
||||
.option = INST_NAME(inst) "_stdinout", \
|
||||
.type = 'b', \
|
||||
.dest = &native_pty_status_##inst.cmd_request_stdinout, \
|
||||
.descript = "Connect "INST_NAME(inst)" to STDIN/OUT instead of a PTY" \
|
||||
" (can only be done for one UART)" \
|
||||
}, \
|
||||
{ \
|
||||
.is_switch = true, \
|
||||
.option = INST_NAME(inst) "_attach_uart", \
|
||||
.type = 'b', \
|
||||
.dest = &native_pty_status_##inst.auto_attach, \
|
||||
.descript = "Automatically attach "INST_NAME(inst)" to a terminal emulator." \
|
||||
" (only applicable when connected to PTYs)" \
|
||||
}, \
|
||||
{ \
|
||||
.option = INST_NAME(inst) "_attach_uart_cmd", \
|
||||
.name = "\"cmd\"", \
|
||||
.type = 's', \
|
||||
.dest = &native_pty_status_##inst.auto_attach_cmd, \
|
||||
.descript = "Command used to automatically attach to the terminal "INST_NAME(inst) \
|
||||
" (implies "INST_NAME(inst)"_auto_attach), by default: " \
|
||||
"'" CONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD "'" \
|
||||
" (only applicable when connected to PTYs)" \
|
||||
}, \
|
||||
{ \
|
||||
.is_switch = true, \
|
||||
.option = INST_NAME(inst) "_wait_uart", \
|
||||
.type = 'b', \
|
||||
.dest = &native_pty_status_##inst.wait_pts, \
|
||||
.descript = "Hold writes to "INST_NAME(inst)" until a client is connected/ready" \
|
||||
" (only applicable when connected to PTYs)" \
|
||||
},
|
||||
|
||||
static void np_add_uart_options(void)
|
||||
{
|
||||
static struct args_struct_t uart_options[] = {
|
||||
/* Set of parameters that apply to all PTY UARTs: */
|
||||
{
|
||||
.is_switch = true,
|
||||
.option = "attach_uart",
|
||||
.type = 'b',
|
||||
.call_when_found = auto_attach_cb,
|
||||
.descript = "Automatically attach all PTY UARTs to a terminal emulator."
|
||||
" (only applicable when connected to PTYs)"
|
||||
},
|
||||
{
|
||||
.option = "attach_uart_cmd",
|
||||
.name = "\"cmd\"",
|
||||
.type = 's',
|
||||
.call_when_found = auto_attach_cmd_cb,
|
||||
.descript = "Command used to automatically attach all PTY UARTs to a terminal "
|
||||
"emulator (implies auto_attach), by default: "
|
||||
"'" CONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD "'"
|
||||
" (only applicable when connected to PTYs)"
|
||||
},
|
||||
{
|
||||
.is_switch = true,
|
||||
.option = "wait_uart",
|
||||
.type = 'b',
|
||||
.call_when_found = wait_pts_cb,
|
||||
.descript = "Hold writes to all PTY UARTs until a client is connected/ready"
|
||||
" (only applicable when connected to PTYs)"
|
||||
},
|
||||
/* Set of parameters that apply to each individual PTY UART: */
|
||||
DT_INST_FOREACH_STATUS_OKAY(NATIVE_PTY_COMMAND_LINE_OPTS)
|
||||
ARG_TABLE_ENDMARKER
|
||||
};
|
||||
|
||||
native_add_command_line_opts(uart_options);
|
||||
}
|
||||
|
||||
#define NATIVE_PTY_CLEANUP(inst) \
|
||||
if ((!native_pty_status_##inst.on_stdinout) && (native_pty_status_##inst.in_fd != 0)) { \
|
||||
nsi_host_close(native_pty_status_##inst.in_fd); \
|
||||
native_pty_status_##inst.in_fd = 0; \
|
||||
}
|
||||
|
||||
static void np_cleanup_uart(void)
|
||||
{
|
||||
DT_INST_FOREACH_STATUS_OKAY(NATIVE_PTY_CLEANUP);
|
||||
}
|
||||
|
||||
NATIVE_TASK(np_add_uart_options, PRE_BOOT_1, 11);
|
||||
NATIVE_TASK(np_cleanup_uart, ON_EXIT, 99);
|
|
@ -112,11 +112,11 @@ int np_uart_slave_connected(int fd)
|
|||
* used. Otherwise, the default command,
|
||||
* CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD, will be used instead
|
||||
*/
|
||||
static void attach_to_tty(const char *slave_tty, const char *auto_attach_cmd)
|
||||
static void attach_to_pty(const char *slave_pty, const char *auto_attach_cmd)
|
||||
{
|
||||
char command[strlen(auto_attach_cmd) + strlen(slave_tty) + 1];
|
||||
char command[strlen(auto_attach_cmd) + strlen(slave_pty) + 1];
|
||||
|
||||
sprintf(command, auto_attach_cmd, slave_tty);
|
||||
sprintf(command, auto_attach_cmd, slave_pty);
|
||||
|
||||
int ret = system(command);
|
||||
|
||||
|
@ -132,7 +132,7 @@ static void attach_to_tty(const char *slave_tty, const char *auto_attach_cmd)
|
|||
* If auto_attach was set, it will also attempt to connect a new terminal
|
||||
* emulator to its slave side.
|
||||
*/
|
||||
int np_uart_open_ptty(const char *uart_name, const char *auto_attach_cmd,
|
||||
int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
|
||||
bool do_auto_attach, bool wait_pts)
|
||||
{
|
||||
int master_pty;
|
||||
|
@ -144,7 +144,7 @@ int np_uart_open_ptty(const char *uart_name, const char *auto_attach_cmd,
|
|||
|
||||
master_pty = posix_openpt(O_RDWR | O_NOCTTY);
|
||||
if (master_pty == -1) {
|
||||
ERROR("Could not open a new TTY for the UART\n");
|
||||
ERROR("Could not open a new PTY for the UART\n");
|
||||
}
|
||||
ret = grantpt(master_pty);
|
||||
if (ret == -1) {
|
||||
|
@ -212,7 +212,7 @@ int np_uart_open_ptty(const char *uart_name, const char *auto_attach_cmd,
|
|||
|
||||
if (wait_pts) {
|
||||
/*
|
||||
* This trick sets the HUP flag on the tty master, making it
|
||||
* This trick sets the HUP flag on the pty master, making it
|
||||
* possible to detect a client connection using poll.
|
||||
* The connection of the client would cause the HUP flag to be
|
||||
* cleared, and in turn set again at disconnect.
|
||||
|
@ -231,18 +231,18 @@ int np_uart_open_ptty(const char *uart_name, const char *auto_attach_cmd,
|
|||
}
|
||||
}
|
||||
if (do_auto_attach) {
|
||||
attach_to_tty(slave_pty_name, auto_attach_cmd);
|
||||
attach_to_pty(slave_pty_name, auto_attach_cmd);
|
||||
}
|
||||
|
||||
return master_pty;
|
||||
}
|
||||
|
||||
int np_uart_ptty_get_stdin_fileno(void)
|
||||
int np_uart_pty_get_stdin_fileno(void)
|
||||
{
|
||||
return STDIN_FILENO;
|
||||
}
|
||||
|
||||
int np_uart_ptty_get_stdout_fileno(void)
|
||||
int np_uart_pty_get_stdout_fileno(void)
|
||||
{
|
||||
return STDOUT_FILENO;
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* "Bottom" of native ptty uart driver
|
||||
* "Bottom" of native PTY UART driver
|
||||
* When built with the native_simulator this will be built in the runner context,
|
||||
* that is, with the host C library, and with the host include paths.
|
||||
*/
|
||||
|
@ -22,10 +22,10 @@ extern "C" {
|
|||
|
||||
int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char);
|
||||
int np_uart_slave_connected(int fd);
|
||||
int np_uart_open_ptty(const char *uart_name, const char *auto_attach_cmd,
|
||||
int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
|
||||
bool do_auto_attach, bool wait_pts);
|
||||
int np_uart_ptty_get_stdin_fileno(void);
|
||||
int np_uart_ptty_get_stdout_fileno(void);
|
||||
int np_uart_pty_get_stdin_fileno(void);
|
||||
int np_uart_pty_get_stdout_fileno(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -6,3 +6,5 @@ description: Native POSIX UART
|
|||
compatible: "zephyr,native-posix-uart"
|
||||
|
||||
include: uart-controller.yaml
|
||||
|
||||
# This binding is deprecated in favor of zephyr,native-pty-uart
|
||||
|
|
8
dts/bindings/serial/zephyr,native-pty-uart.yaml
Normal file
8
dts/bindings/serial/zephyr,native-pty-uart.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) 2019, Jan Van Winkel (jan.van_winkel@dxplore.eu)
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: Native PTY UART
|
||||
|
||||
compatible: "zephyr,native-pty-uart"
|
||||
|
||||
include: uart-controller.yaml
|
|
@ -13,7 +13,7 @@ tests:
|
|||
- gd32f350r_eval
|
||||
harness: shell
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
min_ram: 12
|
||||
integration_platforms:
|
||||
- qemu_x86
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CONFIG_NET_L2_ETHERNET=y
|
||||
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y
|
||||
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
CONFIG_PICOLIBC=y
|
||||
|
|
|
@ -21,7 +21,7 @@ tests:
|
|||
harness: pytest
|
||||
timeout: 180
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
extra_args: DTC_OVERLAY_FILE=fake_sensor.overlay
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
|
|
|
@ -11,7 +11,7 @@ tests:
|
|||
integration_platforms:
|
||||
- native_sim
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
sample.shell.shell_module.usb:
|
||||
depends_on: usb_device
|
||||
tags:
|
||||
|
|
|
@ -5,7 +5,7 @@ common:
|
|||
- shell
|
||||
filter: CONFIG_SERIAL and not CONFIG_SMP and dt_chosen_enabled("zephyr,shell-uart")
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
min_ram: 40
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y
|
||||
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
&uart1 {
|
||||
status = "okay";
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y
|
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
&uart1 {
|
||||
status = "okay";
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "native_sim.overlay"
|
|
@ -35,7 +35,7 @@ or build shell application by west and call pytest directly:
|
|||
cd ${ZEPHYR_BASE}/samples/subsys/testsuite/pytest/shell
|
||||
|
||||
# native_sim
|
||||
west build -p -b native_sim -- -DCONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
west build -p -b native_sim -- -DCONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
pytest --twister-harness --device-type=native --build-dir=build -p twister_harness.plugin
|
||||
|
||||
# QEMU
|
||||
|
|
|
@ -4,7 +4,7 @@ tests:
|
|||
min_ram: 40
|
||||
harness: pytest
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
- qemu_cortex_m3
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
CONFIG_NATIVE_UART_0_ON_OWN_PTY=y
|
||||
CONFIG_UART_NATIVE_WAIT_PTS_READY_ENABLE=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
CONFIG_SHELL_CMD_BUFF_SIZE=8192
|
||||
CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=8192
|
||||
CONFIG_LOG_PRINTK=n
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
&uart1 {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/delete-property/ pinctrl-0;
|
||||
/delete-property/ pinctrl-1;
|
||||
/delete-property/ pinctrl-names;
|
||||
|
@ -23,7 +23,7 @@
|
|||
|
||||
&uart0 {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/delete-property/ pinctrl-0;
|
||||
/delete-property/ pinctrl-1;
|
||||
/delete-property/ pinctrl-names;
|
||||
|
|
|
@ -7,7 +7,7 @@ common:
|
|||
tests:
|
||||
bluetooth.shell.main:
|
||||
extra_configs:
|
||||
- CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
platform_allow:
|
||||
- qemu_x86
|
||||
- native_sim
|
||||
|
@ -55,7 +55,7 @@ tests:
|
|||
min_flash: 350
|
||||
bluetooth.shell.shell_br:
|
||||
extra_configs:
|
||||
- CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
extra_args: CONF_FILE="prj_br.conf"
|
||||
platform_allow:
|
||||
- qemu_cortex_m3
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
CONFIG_UART_PIPE=n
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_NATIVE_POSIX=y
|
||||
CONFIG_UART_NATIVE_PTY=y
|
||||
|
|
|
@ -135,7 +135,7 @@
|
|||
|
||||
uart0: uart {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/* Dummy current-speed entry to comply with serial
|
||||
* DTS binding
|
||||
*/
|
||||
|
@ -144,7 +144,7 @@
|
|||
|
||||
uart1: uart_1 {
|
||||
status = "okay";
|
||||
compatible = "zephyr,native-posix-uart";
|
||||
compatible = "zephyr,native-pty-uart";
|
||||
/* Dummy current-speed entry to comply with serial
|
||||
* DTS binding
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,7 @@ tests:
|
|||
pytest_dut_scope: session
|
||||
fixture: can
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- arch:posix:CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
- native_sim/native/64
|
||||
|
|
|
@ -2,4 +2,4 @@ CONFIG_SERIAL=y
|
|||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
CONFIG_UART_USE_RUNTIME_CONFIGURE=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_USE_RUNTIME_CONFIGURE=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
|
|
|
@ -4,4 +4,4 @@ CONFIG_UART_USE_RUNTIME_CONFIGURE=y
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_SHELL_CMD_BUFF_SIZE=90
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
|
|
|
@ -4,7 +4,7 @@ CONFIG_DNS_SERVER1="192.0.2.2"
|
|||
CONFIG_LWM2M_DNS_SUPPORT=y
|
||||
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
|
||||
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y
|
||||
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
|
||||
CONFIG_ASAN=y
|
||||
CONFIG_NATIVE_EXTRA_CMDLINE_ARGS="--seed-random"
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=32768
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue