diff --git a/include/console.h b/include/console.h index 1f4445970f6..9a36fe5dde2 100644 --- a/include/console.h +++ b/include/console.h @@ -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 } diff --git a/samples/subsys/console/echo/prj.conf b/samples/subsys/console/echo/prj.conf index 3d80dfbdfc7..4dd0a714cff 100644 --- a/samples/subsys/console/echo/prj.conf +++ b/samples/subsys/console/echo/prj.conf @@ -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 diff --git a/samples/subsys/console/getchar/prj.conf b/samples/subsys/console/getchar/prj.conf index 90a02147a61..74e42c58776 100644 --- a/samples/subsys/console/getchar/prj.conf +++ b/samples/subsys/console/getchar/prj.conf @@ -1,2 +1,2 @@ -CONFIG_CONSOLE_PULL=y +CONFIG_CONSOLE_SUBSYS=y CONFIG_CONSOLE_GETCHAR=y diff --git a/samples/subsys/console/getline/prj.conf b/samples/subsys/console/getline/prj.conf index a939f43cbbb..013a5d1be39 100644 --- a/samples/subsys/console/getline/prj.conf +++ b/samples/subsys/console/getline/prj.conf @@ -1,2 +1,2 @@ -CONFIG_CONSOLE_PULL=y +CONFIG_CONSOLE_SUBSYS=y CONFIG_CONSOLE_GETLINE=y diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index 11a45a017de..c76dadd3241 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -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) diff --git a/subsys/console/CMakeLists.txt b/subsys/console/CMakeLists.txt index 6a54379e96e..f56de0b0db9 100644 --- a/subsys/console/CMakeLists.txt +++ b/subsys/console/CMakeLists.txt @@ -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) diff --git a/subsys/console/Kconfig b/subsys/console/Kconfig index 3eb48da2fa0..741bf7dfa27 100644 --- a/subsys/console/Kconfig +++ b/subsys/console/Kconfig @@ -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 diff --git a/subsys/console/line_fifo.c b/subsys/console/line_fifo.c new file mode 100644 index 00000000000..39594e4c922 --- /dev/null +++ b/subsys/console/line_fifo.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Linaro Limited. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Legacy fifo-based line input + */ + +#include +#include + +#ifdef CONFIG_UART_CONSOLE +#include +#endif +#ifdef CONFIG_TELNET_CONSOLE +#include +#endif +#ifdef CONFIG_NATIVE_POSIX_CONSOLE +#include +#endif +#ifdef CONFIG_WEBSOCKET_CONSOLE +#include +#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 +} diff --git a/subsys/shell/Kconfig b/subsys/shell/Kconfig index 219c643df15..483209bd22c 100644 --- a/subsys/shell/Kconfig +++ b/subsys/shell/Kconfig @@ -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. diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index f4f8789f803..2ae7ed216ad 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -14,24 +14,12 @@ #include #include -#include +#include +#include #include #include #include "mgmt/serial.h" -#ifdef CONFIG_UART_CONSOLE -#include -#endif -#ifdef CONFIG_TELNET_CONSOLE -#include -#endif -#ifdef CONFIG_NATIVE_POSIX_CONSOLE -#include -#endif -#ifdef CONFIG_WEBSOCKET_CONSOLE -#include -#endif - #include #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.