2018-08-09 11:40:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHELL_LOG_BACKEND_H__
|
|
|
|
#define SHELL_LOG_BACKEND_H__
|
|
|
|
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/logging/log_backend.h>
|
|
|
|
#include <zephyr/logging/log_output.h>
|
|
|
|
#include <zephyr/sys/mpsc_pbuf.h>
|
|
|
|
#include <zephyr/sys/atomic.h>
|
2018-08-09 11:40:02 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern const struct log_backend_api log_backend_shell_api;
|
|
|
|
|
|
|
|
/** @brief Shell log backend states. */
|
|
|
|
enum shell_log_backend_state {
|
|
|
|
SHELL_LOG_BACKEND_UNINIT,
|
|
|
|
SHELL_LOG_BACKEND_ENABLED,
|
|
|
|
SHELL_LOG_BACKEND_DISABLED,
|
|
|
|
SHELL_LOG_BACKEND_PANIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Shell log backend control block (RW data). */
|
|
|
|
struct shell_log_backend_control_block {
|
2019-01-23 14:49:32 +01:00
|
|
|
atomic_t dropped_cnt;
|
2018-08-09 11:40:02 +02:00
|
|
|
enum shell_log_backend_state state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Shell log backend instance structure (RO data). */
|
|
|
|
struct shell_log_backend {
|
|
|
|
const struct log_backend *backend;
|
|
|
|
const struct log_output *log_output;
|
|
|
|
struct shell_log_backend_control_block *control_block;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t timeout;
|
2021-01-29 16:34:48 +01:00
|
|
|
const struct mpsc_pbuf_buffer_config *mpsc_buffer_config;
|
|
|
|
struct mpsc_pbuf_buffer *mpsc_buffer;
|
2018-08-09 11:40:02 +02:00
|
|
|
};
|
|
|
|
|
2018-12-18 14:48:56 +01:00
|
|
|
/** @brief Shell log backend message structure. */
|
|
|
|
struct shell_log_backend_msg {
|
|
|
|
struct log_msg *msg;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t timestamp;
|
2018-12-18 14:48:56 +01:00
|
|
|
};
|
|
|
|
|
2022-02-24 13:00:55 +01:00
|
|
|
/** @brief Prototype of function outputting processed data. */
|
2020-12-07 10:58:08 +01:00
|
|
|
int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx);
|
2018-08-09 11:40:02 +02:00
|
|
|
|
2020-12-07 10:58:08 +01:00
|
|
|
/** @def Z_SHELL_LOG_BACKEND_DEFINE
|
2018-08-09 11:40:02 +02:00
|
|
|
* @brief Macro for creating instance of shell log backend.
|
|
|
|
*
|
2018-12-17 10:43:58 +01:00
|
|
|
* @param _name Shell name.
|
|
|
|
* @param _buf Output buffer.
|
|
|
|
* @param _size Output buffer size.
|
|
|
|
* @param _queue_size Log message queue size.
|
|
|
|
* @param _timeout Timeout in milliseconds for pending on queue full.
|
|
|
|
* Message is dropped on timeout.
|
2018-08-09 11:40:02 +02:00
|
|
|
*/
|
2020-12-07 10:58:08 +01:00
|
|
|
/** @def Z_SHELL_LOG_BACKEND_PTR
|
2018-08-09 11:40:02 +02:00
|
|
|
* @brief Macro for retrieving pointer to the instance of shell log backend.
|
|
|
|
*
|
|
|
|
* @param _name Shell name.
|
|
|
|
*/
|
2019-09-23 02:19:19 +02:00
|
|
|
#ifdef CONFIG_SHELL_LOG_BACKEND
|
2021-01-29 16:34:48 +01:00
|
|
|
#define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \
|
|
|
|
LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \
|
|
|
|
LOG_OUTPUT_DEFINE(_name##_log_output, z_shell_log_backend_output_func,\
|
|
|
|
_buf, _size); \
|
|
|
|
static struct shell_log_backend_control_block _name##_control_block; \
|
2023-02-16 13:44:59 +01:00
|
|
|
static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) \
|
2022-10-28 12:27:15 +02:00
|
|
|
_name##_buf[_queue_size / sizeof(uint32_t)]; \
|
2021-01-29 16:34:48 +01:00
|
|
|
const struct mpsc_pbuf_buffer_config _name##_mpsc_buffer_config = { \
|
|
|
|
.buf = _name##_buf, \
|
|
|
|
.size = ARRAY_SIZE(_name##_buf), \
|
|
|
|
.notify_drop = NULL, \
|
2022-06-21 11:51:38 +02:00
|
|
|
.get_wlen = log_msg_generic_get_wlen, \
|
2021-01-29 16:34:48 +01:00
|
|
|
.flags = MPSC_PBUF_MODE_OVERWRITE, \
|
|
|
|
}; \
|
|
|
|
struct mpsc_pbuf_buffer _name##_mpsc_buffer; \
|
|
|
|
static const struct shell_log_backend _name##_log_backend = { \
|
|
|
|
.backend = &_name##_backend, \
|
|
|
|
.log_output = &_name##_log_output, \
|
|
|
|
.control_block = &_name##_control_block, \
|
|
|
|
.timeout = _timeout, \
|
2022-06-14 06:22:19 +02:00
|
|
|
.mpsc_buffer_config = &_name##_mpsc_buffer_config, \
|
|
|
|
.mpsc_buffer = &_name##_mpsc_buffer, \
|
2018-08-09 11:40:02 +02:00
|
|
|
}
|
|
|
|
|
2020-12-07 10:58:08 +01:00
|
|
|
#define Z_SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend)
|
2018-08-09 11:40:02 +02:00
|
|
|
#else /* CONFIG_LOG */
|
2020-12-07 10:58:08 +01:00
|
|
|
#define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout)
|
|
|
|
#define Z_SHELL_LOG_BACKEND_PTR(_name) NULL
|
2018-08-09 11:40:02 +02:00
|
|
|
#endif /* CONFIG_LOG */
|
|
|
|
|
|
|
|
/** @brief Enable shell log backend.
|
|
|
|
*
|
|
|
|
* @param backend Shell log backend instance.
|
|
|
|
* @param ctx Pointer to shell instance.
|
|
|
|
* @param init_log_level Initial log level set to all logging sources.
|
|
|
|
*/
|
2020-12-07 10:58:08 +01:00
|
|
|
void z_shell_log_backend_enable(const struct shell_log_backend *backend,
|
|
|
|
void *ctx, uint32_t init_log_level);
|
2018-08-09 11:40:02 +02:00
|
|
|
|
|
|
|
/** @brief Disable shell log backend.
|
|
|
|
*
|
|
|
|
* @param backend Shell log backend instance.
|
|
|
|
*/
|
2020-12-07 10:58:08 +01:00
|
|
|
void z_shell_log_backend_disable(const struct shell_log_backend *backend);
|
2018-08-09 11:40:02 +02:00
|
|
|
|
|
|
|
/** @brief Trigger processing of one log entry.
|
|
|
|
*
|
|
|
|
* @param backend Shell log backend instance.
|
|
|
|
*
|
|
|
|
* @return True if message was processed, false if FIFO was empty
|
|
|
|
*/
|
2020-12-07 10:58:08 +01:00
|
|
|
bool z_shell_log_backend_process(const struct shell_log_backend *backend);
|
2018-08-09 11:40:02 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* SHELL_LOG_BACKEND_H__ */
|