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:
parent
54a5997f5c
commit
f6d8ab8289
|
@ -77,6 +77,25 @@ void console_getline_init(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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CONFIG_CONSOLE_PULL=y
|
||||
CONFIG_CONSOLE_SUBSYS=y
|
||||
CONFIG_CONSOLE_GETCHAR=y
|
||||
CONFIG_CONSOLE_GETCHAR_BUFSIZE=64
|
||||
CONFIG_CONSOLE_PUTCHAR_BUFSIZE=512
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
CONFIG_CONSOLE_PULL=y
|
||||
CONFIG_CONSOLE_SUBSYS=y
|
||||
CONFIG_CONSOLE_GETCHAR=y
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
CONFIG_CONSOLE_PULL=y
|
||||
CONFIG_CONSOLE_SUBSYS=y
|
||||
CONFIG_CONSOLE_GETLINE=y
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
add_subdirectory(debug)
|
||||
add_subdirectory(logging)
|
||||
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_CPLUSPLUS cpp)
|
||||
add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
zephyr_sources(line_fifo.c)
|
||||
zephyr_sources_ifdef(CONFIG_CONSOLE_GETCHAR getchar.c)
|
||||
zephyr_sources_ifdef(CONFIG_CONSOLE_GETLINE getline.c)
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
menu "Console (pull-style)"
|
||||
menu "Console"
|
||||
|
||||
config CONSOLE_PULL
|
||||
config CONSOLE_SUBSYS
|
||||
bool
|
||||
default n
|
||||
prompt "Enable pull-style Console access"
|
||||
prompt "Console subsystem/support routines"
|
||||
help
|
||||
Get data from console using getchar/getline calls
|
||||
Console subsystem and helper functions
|
||||
|
||||
if CONSOLE_PULL
|
||||
if CONSOLE_SUBSYS
|
||||
choice
|
||||
prompt "Console 'get' function selection"
|
||||
|
||||
|
@ -49,5 +49,5 @@ config CONSOLE_PUTCHAR_BUFSIZE
|
|||
|
||||
endif # CONSOLE_GETCHAR
|
||||
|
||||
endif # CONSOLE_PULL
|
||||
endif # CONSOLE_SUBSYS
|
||||
endmenu
|
||||
|
|
45
subsys/console/line_fifo.c
Normal file
45
subsys/console/line_fifo.c
Normal 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
|
||||
}
|
|
@ -13,6 +13,7 @@ config CONSOLE_SHELL
|
|||
prompt "Enable console input handler [ Experimental ]"
|
||||
default n
|
||||
select CONSOLE_HANDLER
|
||||
select CONSOLE_SUBSYS
|
||||
help
|
||||
Shell implementation based on CONSOLE_HANDLER.
|
||||
|
||||
|
|
|
@ -14,24 +14,12 @@
|
|||
#include <string.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <console/console.h>
|
||||
#include <console.h>
|
||||
#include <drivers/console/console.h>
|
||||
#include <misc/printk.h>
|
||||
#include <misc/util.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>
|
||||
|
||||
#define ARGC_MAX 10
|
||||
|
@ -631,19 +619,8 @@ void shell_init(const char *str)
|
|||
k_thread_create(&shell_thread, stack, STACKSIZE, shell, NULL, NULL,
|
||||
NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||
|
||||
/* Register serial console handler */
|
||||
#ifdef CONFIG_UART_CONSOLE
|
||||
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
|
||||
/* Register console handler */
|
||||
console_register_line_input(&avail_queue, &cmds_queue, completion);
|
||||
}
|
||||
|
||||
/** @brief Optionally register an app default cmd handler.
|
||||
|
|
Loading…
Reference in a new issue