shell: internal api update: log backend

Add prefix z_ to internal functions and macros handling log backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2020-12-07 10:58:08 +01:00 committed by Carles Cufí
commit 37e8d825bf
4 changed files with 37 additions and 36 deletions

View file

@ -731,7 +731,7 @@ extern void z_shell_print_stream(const void *user_ctx, const char *data,
static const struct shell _name; \ static const struct shell _name; \
static struct shell_ctx UTIL_CAT(_name, _ctx); \ static struct shell_ctx UTIL_CAT(_name, _ctx); \
static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \ static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \ Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \
CONFIG_SHELL_PRINTF_BUFF_SIZE, \ CONFIG_SHELL_PRINTF_BUFF_SIZE, \
_log_queue_size, _log_timeout); \ _log_queue_size, _log_timeout); \
Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \ Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
@ -751,7 +751,7 @@ extern void z_shell_print_stream(const void *user_ctx, const char *data,
.shell_flag = _shell_flag, \ .shell_flag = _shell_flag, \
.fprintf_ctx = &_name##_fprintf, \ .fprintf_ctx = &_name##_fprintf, \
.stats = SHELL_STATS_PTR(_name), \ .stats = SHELL_STATS_PTR(_name), \
.log_backend = SHELL_LOG_BACKEND_PTR(_name), \ .log_backend = Z_SHELL_LOG_BACKEND_PTR(_name), \
LOG_INSTANCE_PTR_INIT(log, shell, _name) \ LOG_INSTANCE_PTR_INIT(log, shell, _name) \
.thread_name = STRINGIFY(_name), \ .thread_name = STRINGIFY(_name), \
.thread = &_name##_thread, \ .thread = &_name##_thread, \

View file

@ -47,9 +47,9 @@ struct shell_log_backend_msg {
}; };
/** @brief Prototype of function outputing processed data. */ /** @brief Prototype of function outputing processed data. */
int shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx); int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx);
/** @def SHELL_LOG_BACKEND_DEFINE /** @def Z_SHELL_LOG_BACKEND_DEFINE
* @brief Macro for creating instance of shell log backend. * @brief Macro for creating instance of shell log backend.
* *
* @param _name Shell name. * @param _name Shell name.
@ -59,31 +59,31 @@ int shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx);
* @param _timeout Timeout in milliseconds for pending on queue full. * @param _timeout Timeout in milliseconds for pending on queue full.
* Message is dropped on timeout. * Message is dropped on timeout.
*/ */
/** @def SHELL_LOG_BACKEND_PTR /** @def Z_SHELL_LOG_BACKEND_PTR
* @brief Macro for retrieving pointer to the instance of shell log backend. * @brief Macro for retrieving pointer to the instance of shell log backend.
* *
* @param _name Shell name. * @param _name Shell name.
*/ */
#ifdef CONFIG_SHELL_LOG_BACKEND #ifdef CONFIG_SHELL_LOG_BACKEND
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \ #define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \
LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \ LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \
K_MSGQ_DEFINE(_name##_msgq, sizeof(struct shell_log_backend_msg), \ K_MSGQ_DEFINE(_name##_msgq, sizeof(struct shell_log_backend_msg), \
_queue_size, sizeof(void *)); \ _queue_size, sizeof(void *)); \
LOG_OUTPUT_DEFINE(_name##_log_output, shell_log_backend_output_func, \ LOG_OUTPUT_DEFINE(_name##_log_output, z_shell_log_backend_output_func, \
_buf, _size); \ _buf, _size); \
static struct shell_log_backend_control_block _name##_control_block; \ static struct shell_log_backend_control_block _name##_control_block; \
static const struct shell_log_backend _name##_log_backend = { \ static const struct shell_log_backend _name##_log_backend = { \
.backend = &_name##_backend, \ .backend = &_name##_backend, \
.msgq = &_name##_msgq, \ .msgq = &_name##_msgq, \
.log_output = &_name##_log_output, \ .log_output = &_name##_log_output, \
.control_block = &_name##_control_block, \ .control_block = &_name##_control_block, \
.timeout = _timeout \ .timeout = _timeout \
} }
#define SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend) #define Z_SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend)
#else /* CONFIG_LOG */ #else /* CONFIG_LOG */
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) #define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout)
#define SHELL_LOG_BACKEND_PTR(_name) NULL #define Z_SHELL_LOG_BACKEND_PTR(_name) NULL
#endif /* CONFIG_LOG */ #endif /* CONFIG_LOG */
/** @brief Enable shell log backend. /** @brief Enable shell log backend.
@ -92,14 +92,14 @@ int shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx);
* @param ctx Pointer to shell instance. * @param ctx Pointer to shell instance.
* @param init_log_level Initial log level set to all logging sources. * @param init_log_level Initial log level set to all logging sources.
*/ */
void shell_log_backend_enable(const struct shell_log_backend *backend, void z_shell_log_backend_enable(const struct shell_log_backend *backend,
void *ctx, uint32_t init_log_level); void *ctx, uint32_t init_log_level);
/** @brief Disable shell log backend. /** @brief Disable shell log backend.
* *
* @param backend Shell log backend instance. * @param backend Shell log backend instance.
*/ */
void shell_log_backend_disable(const struct shell_log_backend *backend); void z_shell_log_backend_disable(const struct shell_log_backend *backend);
/** @brief Trigger processing of one log entry. /** @brief Trigger processing of one log entry.
* *
@ -107,7 +107,7 @@ void shell_log_backend_disable(const struct shell_log_backend *backend);
* *
* @return True if message was processed, false if FIFO was empty * @return True if message was processed, false if FIFO was empty
*/ */
bool shell_log_backend_process(const struct shell_log_backend *backend); bool z_shell_log_backend_process(const struct shell_log_backend *backend);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1114,7 +1114,8 @@ static void shell_log_process(const struct shell *shell)
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) { if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
shell_cmd_line_erase(shell); shell_cmd_line_erase(shell);
processed = shell_log_backend_process(shell->log_backend); processed = z_shell_log_backend_process(
shell->log_backend);
} }
struct k_poll_signal *signal = struct k_poll_signal *signal =
@ -1193,7 +1194,7 @@ static int instance_uninit(const struct shell *shell)
if (IS_ENABLED(CONFIG_SHELL_LOG_BACKEND)) { if (IS_ENABLED(CONFIG_SHELL_LOG_BACKEND)) {
/* todo purge log queue */ /* todo purge log queue */
shell_log_backend_disable(shell->log_backend); z_shell_log_backend_disable(shell->log_backend);
} }
err = shell->iface->api->uninit(shell->iface); err = shell->iface->api->uninit(shell->iface);
@ -1245,8 +1246,8 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
} }
if (log_backend && IS_ENABLED(CONFIG_SHELL_LOG_BACKEND)) { if (log_backend && IS_ENABLED(CONFIG_SHELL_LOG_BACKEND)) {
shell_log_backend_enable(shell->log_backend, (void *)shell, z_shell_log_backend_enable(shell->log_backend, (void *)shell,
log_level); log_level);
} }
/* Enable shell and print prompt. */ /* Enable shell and print prompt. */

View file

@ -9,14 +9,14 @@
#include "shell_ops.h" #include "shell_ops.h"
#include <logging/log_ctrl.h> #include <logging/log_ctrl.h>
int shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx) int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx)
{ {
z_shell_print_stream(ctx, data, length); z_shell_print_stream(ctx, data, length);
return length; return length;
} }
void shell_log_backend_enable(const struct shell_log_backend *backend, void z_shell_log_backend_enable(const struct shell_log_backend *backend,
void *ctx, uint32_t init_log_level) void *ctx, uint32_t init_log_level)
{ {
int err = 0; int err = 0;
@ -117,7 +117,7 @@ static void msg_to_fifo(const struct shell *shell,
} }
} }
void shell_log_backend_disable(const struct shell_log_backend *backend) void z_shell_log_backend_disable(const struct shell_log_backend *backend)
{ {
fifo_flush(backend); fifo_flush(backend);
log_backend_disable(backend->backend); log_backend_disable(backend->backend);
@ -139,7 +139,7 @@ static void msg_process(const struct log_output *log_output,
log_msg_put(msg); log_msg_put(msg);
} }
bool shell_log_backend_process(const struct shell_log_backend *backend) bool z_shell_log_backend_process(const struct shell_log_backend *backend)
{ {
uint32_t dropped; uint32_t dropped;
const struct shell *shell = const struct shell *shell =
@ -281,11 +281,11 @@ static void panic(const struct log_backend *const backend)
shell_op_cursor_horiz_move(shell, shell_op_cursor_horiz_move(shell,
-shell->ctx->vt100_ctx.cons.cur_x); -shell->ctx->vt100_ctx.cons.cur_x);
while (shell_log_backend_process(shell->log_backend)) { while (z_shell_log_backend_process(shell->log_backend)) {
/* empty */ /* empty */
} }
} else { } else {
shell_log_backend_disable(shell->log_backend); z_shell_log_backend_disable(shell->log_backend);
} }
} }