Skip to content

Commit

Permalink
subsys: console: Factor out fifo-based console input abstraction
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pfalcon authored and nashif committed Jun 20, 2018
1 parent 54a5997 commit f6d8ab8
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 37 deletions.
19 changes: 19 additions & 0 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion samples/subsys/console/echo/prj.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion samples/subsys/console/getchar/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_CONSOLE_PULL=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
2 changes: 1 addition & 1 deletion samples/subsys/console/getline/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_CONSOLE_PULL=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETLINE=y
2 changes: 1 addition & 1 deletion subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions subsys/console/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions subsys/console/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -49,5 +49,5 @@ config CONSOLE_PUTCHAR_BUFSIZE

endif # CONSOLE_GETCHAR

endif # CONSOLE_PULL
endif # CONSOLE_SUBSYS
endmenu
45 changes: 45 additions & 0 deletions subsys/console/line_fifo.c
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions subsys/shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
31 changes: 4 additions & 27 deletions subsys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f6d8ab8

Please sign in to comment.