Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (CONFIG_ASAN)
zephyr_ld_options(-fsanitize=address)
endif ()

zephyr_compile_definitions(_POSIX_C_SOURCE=200809 _XOPEN_SOURCE _XOPEN_SOURCE_EXTENDED)
zephyr_compile_definitions(_POSIX_C_SOURCE=200809 _XOPEN_SOURCE=600 _XOPEN_SOURCE_EXTENDED)

zephyr_ld_options(
-ldl
Expand Down
19 changes: 18 additions & 1 deletion boards/posix/native_posix/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ endchoice

endif # BT_HCI

if SERIAL

config UART_NATIVE_POSIX
def_bool y

endif # SERIAL

if LOG

config LOG_BACKEND_NATIVE_POSIX
def_bool y
def_bool y if !SERIAL

# For native_posix we can log immediately without any problem
# Doing so will be nicer for debugging
Expand All @@ -55,4 +62,14 @@ config LOG_PROCESS_THREAD

endif # LOG

if CONSOLE

config NATIVE_POSIX_CONSOLE
def_bool y if !SERIAL

config UART_CONSOLE
def_bool y if SERIAL

endif #CONSOLE

endif # BOARD_NATIVE_POSIX
56 changes: 40 additions & 16 deletions boards/posix/native_posix/doc/board.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ you use native host tools for compiling, debugging, and analyzing your
Zephyr application, eliminating the need for architecture-specific
target hardware in the early phases of development.

This board provides a few peripherals such as an Ethernet driver and UART.
See `Peripherals`_ for more information.

Host system dependencies
========================

Expand Down Expand Up @@ -458,8 +461,8 @@ The following peripherals are currently provided with this board:
``stdout``.

- Feed any input from the native application ``stdin`` to a possible
running :ref:`Shell`. For more information refer to the section
`Shell support`_.
running legacy shell. For more information refer to the section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the new shell, eh? Will the new and legacy shells work together or are they mutually exclusive?

Copy link
Member Author

@aescolar aescolar Sep 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the new shell, eh?

Not with that console driver. The new shell is not using CONSOLE , but hooks directly into the UART driver. So the CONSOLE/old shell backends we had are of no use with the new shell.

Will the new and legacy shells work together or are they mutually exclusive?

I guess the question should be for the new shell developers. But my understanding is that, today:

  • The modules using the legacy shell are being ported to use the new shell. So the legacy shell will be purposeless quite soon (unless some old app uses it).
  • The new shell does not know or care about the old shell, and does not intend to avoid any conflict with it. If the old shell was driven thru UART they will certainly conflict if compiled together.
  • In case of native_posix, I think you may still be able to compile the old shell in parallel with the new one by using this native console driver for the old shell, and the new UART driver for the new shell.

Copy link
Contributor

@jakub-uC jakub-uC Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK legacy shell will be removed completely

`Legacy shell support`_.

**Clock, timer and system tick model**
This model provides the system tick timer. By default
Expand Down Expand Up @@ -538,11 +541,40 @@ The following peripherals are currently provided with this board:
must be powered down and support Bluetooth Low Energy (i.e. support the
Bluetooth specification version 4.0 or greater).

Shell support
*************
**UART**
An optional UART driver can be compiled with native_posix.
For more information refer to the section `UART`_.


UART
*****

This driver can be configured to either create and link the UART to a new
pseudoterminal (i.e. ``/dev/pts<nbr>``), or to map the UART input and
output to the executable's ``stdin`` and ``stdout``.
This is chosen by selecting either
:option:`CONFIG_NATIVE_UART_0_ON_OWN_PTY` or
:option:`CONFIG_NATIVE_UART_0_ON_STDINOUT`
Note that for interactive use, the first option should be chosen. The
second option is only intended for automated testing or feeding/piping other
processes output to the UART.

When :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.
You may also chose to automatically attach a terminal emulator to it 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
:option:`CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD`.
Note that the default command assumes both ``xterm`` and ``screen`` are
installed in the system.


Legacy shell support
********************

When the :ref:`Shell` subsystem is compiled with your application, the native
standard input (``stdin``) will be redirected to the shell.
When the legacy :ref:`Shell` subsystem is compiled with your application,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:ref:`shell` will be a reference to the new shell documentation and not to the legacy shell subsystem. The shell documentation is changing with PR #10216, so your PR's references may break when 10216 is merged (or not work until it is). This should probably change to:

When the :ref:`legacy shell` subsystem is compiled ...

Copy link
Member Author

@aescolar aescolar Sep 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.. I saw that PR coming after I sent mine. So I guess my options are
a. to leave the old link which is correct today, and if that PR is merged before this, correct it. If this PR is merged before, the other PR author should correct the references to the old shell page around, OR, I can send a new PR after 10216 is merged.
b. remove all links to Shell all together, and add them back in a new PR after both are merged.
c. Point to the new shell doc and stall this PR.. => don't like this one.

the native standard input (``stdin``) will be redirected to the shell.
You may use the shell interactively through the console,
by piping another process output to it, or by feeding it a file.

Expand Down Expand Up @@ -580,16 +612,8 @@ These directives are:
Use example
===========

For example, you can build the shell sample app:

.. zephyr-app-commands::
:zephyr-app: samples/subsys/shell/shell_module
:host-os: unix
:board: native_posix
:goals: build
:compact:

And feed it the following set of commands through a pipe:
For example, after you have built an application with the legacy shell, you
can feed it the following set of commands through a pipe:

.. code-block:: console

Expand Down
1 change: 0 additions & 1 deletion boards/posix/native_posix/native_posix_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ CONFIG_ARCH_POSIX=y
CONFIG_SOC_POSIX=y
CONFIG_BOARD_NATIVE_POSIX=y
CONFIG_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000
3 changes: 1 addition & 2 deletions drivers/console/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,14 @@ config NATIVE_POSIX_CONSOLE
bool "Use the host terminal for console"
depends on ARCH_POSIX
select CONSOLE_HAS_DRIVER
default y
help
Use the host terminal (where the native_posix binary was launched) for the
Zephyr console

config NATIVE_POSIX_STDIN_CONSOLE
bool "Use the host terminal stdin"
depends on NATIVE_POSIX_CONSOLE
default y
default y if !NATIVE_UART_0_ON_STDINOUT
help
Feed the host terminal stdin to the Zephyr console/shell.

Expand Down
5 changes: 5 additions & 0 deletions drivers/serial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ zephyr_library_sources_if_kconfig(usart_mcux_lpc.c)
zephyr_library_sources_if_kconfig(uart_psoc6.c)

zephyr_library_sources_ifdef(CONFIG_USERSPACE uart_handlers.c)

if(CONFIG_UART_NATIVE_POSIX)
zephyr_library_compile_definitions(NO_POSIX_CHEATS)
zephyr_library_sources(uart_native_posix.c)
endif()
2 changes: 2 additions & 0 deletions drivers/serial/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ source "drivers/serial/Kconfig.imx"

source "drivers/serial/Kconfig.stellaris"

source "drivers/serial/Kconfig.native_posix"

source "drivers/serial/Kconfig.nsim"

source "drivers/serial/Kconfig.usart_sam"
Expand Down
59 changes: 59 additions & 0 deletions drivers/serial/Kconfig.native_posix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
config UART_NATIVE_POSIX
bool "UART driver for native_posix"
select SERIAL_HAS_DRIVER
depends on ARCH_POSIX
help
This enables a UART driver for the POSIX ARCH. The driver can be configured
to either connect to the terminal from which native_posix was run, or into
one decicated pseudoterminal for this UART.

if UART_NATIVE_POSIX

config UART_NATIVE_POSIX_PORT_0_NAME
string "Port 0 Device Name"
default "UART_0"
depends on UART_NATIVE_POSIX
help
This is the device name for UART, and is included in the device
struct.

choice
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 the 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_posix backend
which may use the calling shell standard input/output.

config NATIVE_UART_0_ON_STDINOUT
bool "Connect the UART to the invoking shell stdin/stdout"
help
Connect the UART to the stdin & stdout of the calling shell/terminal which
invoked the native_posix 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.
This option should NOT be used in conjunction with the legacy shell
native_posix backend (NATIVE_POSIX_STDIN_CONSOLE)
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 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_posix 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 it.
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 a UART is configured to use its own PTY with
NATIVE_UART_x_ON_OWN_PTY.

endif #UART_NATIVE_POSIX
Loading