subsys: console: Factor out fifo-based console input abstraction

Console subsystem is intended to be a layer between console drivers
and console clients, like e.g. shell. This change factors out code
from shell which dealed with individial console drivers and moves it
to console subsystem, under the name console_register_line_input().

To accommodate for this change, older console subsys Kconfig symbol
is changed from CONFIG_CONSOLE_PULL to CONFIG_CONSOLE_SUBSYS
(CONFIG_CONSOLE is already used by console drivers). This signifies
that console subsystem is intended to deal with all of console
aspects in Zephyr (existing and new), not just provide some "new"
functionality on top of raw console drivers, like it initially
started.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
This commit is contained in:
Paul Sokolovsky 2018-06-07 22:30:21 +03:00 committed by Anas Nashif
parent 54a5997f5c
commit f6d8ab8289
10 changed files with 80 additions and 37 deletions

View file

@ -77,6 +77,25 @@ void console_getline_init(void);
*/ */
char *console_getline(void); char *console_getline(void);
/** @brief Initialize legacy fifo-based line input
*
* Input processing is started when string is typed in the console.
* Carriage return is translated to NULL making string always NULL
* terminated. Application before calling register function need to
* initialize two fifo queues mentioned below.
*
* This is a special-purpose function, it's recommended to use
* console_getchar() or console_getline() functions instead.
*
* @param avail_queue k_fifo queue keeping available line buffers
* @param out_queue k_fifo queue of entered lines which to be processed
* in the application code.
* @param completion callback for tab completion of entered commands
*/
void console_register_line_input(struct k_fifo *avail_queue,
struct k_fifo *out_queue,
u8_t (*completion)(char *str, u8_t len));
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
CONFIG_CONSOLE_PULL=y CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y CONFIG_CONSOLE_GETCHAR=y
CONFIG_CONSOLE_GETCHAR_BUFSIZE=64 CONFIG_CONSOLE_GETCHAR_BUFSIZE=64
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=512 CONFIG_CONSOLE_PUTCHAR_BUFSIZE=512

View file

@ -1,2 +1,2 @@
CONFIG_CONSOLE_PULL=y CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y CONFIG_CONSOLE_GETCHAR=y

View file

@ -1,2 +1,2 @@
CONFIG_CONSOLE_PULL=y CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y CONFIG_CONSOLE_GETLINE=y

View file

@ -1,7 +1,7 @@
add_subdirectory(debug) add_subdirectory(debug)
add_subdirectory(logging) add_subdirectory(logging)
add_subdirectory_ifdef(CONFIG_BT bluetooth) add_subdirectory_ifdef(CONFIG_BT bluetooth)
add_subdirectory_ifdef(CONFIG_CONSOLE_PULL console) add_subdirectory_ifdef(CONFIG_CONSOLE_SUBSYS console)
add_subdirectory_ifdef(CONFIG_CONSOLE_SHELL shell) add_subdirectory_ifdef(CONFIG_CONSOLE_SHELL shell)
add_subdirectory_ifdef(CONFIG_CPLUSPLUS cpp) add_subdirectory_ifdef(CONFIG_CPLUSPLUS cpp)
add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk) add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk)

View file

@ -1,2 +1,3 @@
zephyr_sources(line_fifo.c)
zephyr_sources_ifdef(CONFIG_CONSOLE_GETCHAR getchar.c) zephyr_sources_ifdef(CONFIG_CONSOLE_GETCHAR getchar.c)
zephyr_sources_ifdef(CONFIG_CONSOLE_GETLINE getline.c) zephyr_sources_ifdef(CONFIG_CONSOLE_GETLINE getline.c)

View file

@ -4,16 +4,16 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
menu "Console (pull-style)" menu "Console"
config CONSOLE_PULL config CONSOLE_SUBSYS
bool bool
default n default n
prompt "Enable pull-style Console access" prompt "Console subsystem/support routines"
help help
Get data from console using getchar/getline calls Console subsystem and helper functions
if CONSOLE_PULL if CONSOLE_SUBSYS
choice choice
prompt "Console 'get' function selection" prompt "Console 'get' function selection"
@ -49,5 +49,5 @@ config CONSOLE_PUTCHAR_BUFSIZE
endif # CONSOLE_GETCHAR endif # CONSOLE_GETCHAR
endif # CONSOLE_PULL endif # CONSOLE_SUBSYS
endmenu endmenu

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2018 Linaro Limited.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Legacy fifo-based line input
*/
#include <zephyr.h>
#include <console.h>
#ifdef CONFIG_UART_CONSOLE
#include <drivers/console/uart_console.h>
#endif
#ifdef CONFIG_TELNET_CONSOLE
#include <drivers/console/telnet_console.h>
#endif
#ifdef CONFIG_NATIVE_POSIX_CONSOLE
#include <drivers/console/native_posix_console.h>
#endif
#ifdef CONFIG_WEBSOCKET_CONSOLE
#include <drivers/console/websocket_console.h>
#endif
void console_register_line_input(struct k_fifo *avail_queue,
struct k_fifo *out_queue,
u8_t (*completion)(char *str, u8_t len))
{
/* Register serial console handler */
#ifdef CONFIG_UART_CONSOLE
uart_register_input(avail_queue, out_queue, completion);
#endif
#ifdef CONFIG_TELNET_CONSOLE
telnet_register_input(avail_queue, out_queue, completion);
#endif
#ifdef CONFIG_NATIVE_POSIX_STDIN_CONSOLE
native_stdin_register_input(avail_queue, out_queue, completion);
#endif
#ifdef CONFIG_WEBSOCKET_CONSOLE
ws_register_input(avail_queue, out_queue, completion);
#endif
}

View file

@ -13,6 +13,7 @@ config CONSOLE_SHELL
prompt "Enable console input handler [ Experimental ]" prompt "Enable console input handler [ Experimental ]"
default n default n
select CONSOLE_HANDLER select CONSOLE_HANDLER
select CONSOLE_SUBSYS
help help
Shell implementation based on CONSOLE_HANDLER. Shell implementation based on CONSOLE_HANDLER.

View file

@ -14,24 +14,12 @@
#include <string.h> #include <string.h>
#include <version.h> #include <version.h>
#include <console/console.h> #include <console.h>
#include <drivers/console/console.h>
#include <misc/printk.h> #include <misc/printk.h>
#include <misc/util.h> #include <misc/util.h>
#include "mgmt/serial.h" #include "mgmt/serial.h"
#ifdef CONFIG_UART_CONSOLE
#include <console/uart_console.h>
#endif
#ifdef CONFIG_TELNET_CONSOLE
#include <console/telnet_console.h>
#endif
#ifdef CONFIG_NATIVE_POSIX_CONSOLE
#include <console/native_posix_console.h>
#endif
#ifdef CONFIG_WEBSOCKET_CONSOLE
#include <console/websocket_console.h>
#endif
#include <shell/shell.h> #include <shell/shell.h>
#define ARGC_MAX 10 #define ARGC_MAX 10
@ -631,19 +619,8 @@ void shell_init(const char *str)
k_thread_create(&shell_thread, stack, STACKSIZE, shell, NULL, NULL, k_thread_create(&shell_thread, stack, STACKSIZE, shell, NULL, NULL,
NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
/* Register serial console handler */ /* Register console handler */
#ifdef CONFIG_UART_CONSOLE console_register_line_input(&avail_queue, &cmds_queue, completion);
uart_register_input(&avail_queue, &cmds_queue, completion);
#endif
#ifdef CONFIG_TELNET_CONSOLE
telnet_register_input(&avail_queue, &cmds_queue, completion);
#endif
#ifdef CONFIG_NATIVE_POSIX_STDIN_CONSOLE
native_stdin_register_input(&avail_queue, &cmds_queue, completion);
#endif
#ifdef CONFIG_WEBSOCKET_CONSOLE
ws_register_input(&avail_queue, &cmds_queue, completion);
#endif
} }
/** @brief Optionally register an app default cmd handler. /** @brief Optionally register an app default cmd handler.