Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
shell_log_backend.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef SHELL_LOG_BACKEND_H__
8#define SHELL_LOG_BACKEND_H__
9
10#include <zephyr.h>
11#include <logging/log_backend.h>
12#include <logging/log_output.h>
13#include <sys/mpsc_pbuf.h>
14#include <sys/atomic.h>
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19extern const struct log_backend_api log_backend_shell_api;
20
27};
28
33};
34
37 const struct log_backend *backend;
38 struct k_msgq *msgq;
39 const struct log_output *log_output;
44};
45
48 struct log_msg *msg;
50};
51
53int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx);
54
70#ifdef CONFIG_SHELL_LOG_BACKEND
71#define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout) \
72 LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \
73 K_MSGQ_DEFINE(_name##_msgq, sizeof(struct shell_log_backend_msg), \
74 _queue_size, sizeof(void *)); \
75 LOG_OUTPUT_DEFINE(_name##_log_output, z_shell_log_backend_output_func,\
76 _buf, _size); \
77 static struct shell_log_backend_control_block _name##_control_block; \
78 static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) _name##_buf[128]; \
79 const struct mpsc_pbuf_buffer_config _name##_mpsc_buffer_config = { \
80 .buf = _name##_buf, \
81 .size = ARRAY_SIZE(_name##_buf), \
82 .notify_drop = NULL, \
83 .get_wlen = log_msg2_generic_get_wlen, \
84 .flags = MPSC_PBUF_MODE_OVERWRITE, \
85 }; \
86 struct mpsc_pbuf_buffer _name##_mpsc_buffer; \
87 static const struct shell_log_backend _name##_log_backend = { \
88 .backend = &_name##_backend, \
89 .msgq = IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) ? \
90 &_name##_msgq : NULL, \
91 .log_output = &_name##_log_output, \
92 .control_block = &_name##_control_block, \
93 .timeout = _timeout, \
94 .mpsc_buffer_config = IS_ENABLED(CONFIG_LOG2_MODE_DEFERRED) ? \
95 &_name##_mpsc_buffer_config : NULL, \
96 .mpsc_buffer = IS_ENABLED(CONFIG_LOG2_MODE_DEFERRED) ? \
97 &_name##_mpsc_buffer : NULL, \
98 }
99
100#define Z_SHELL_LOG_BACKEND_PTR(_name) (&_name##_log_backend)
101#else /* CONFIG_LOG */
102#define Z_SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size, _queue_size, _timeout)
103#define Z_SHELL_LOG_BACKEND_PTR(_name) NULL
104#endif /* CONFIG_LOG */
105
112void z_shell_log_backend_enable(const struct shell_log_backend *backend,
113 void *ctx, uint32_t init_log_level);
114
119void z_shell_log_backend_disable(const struct shell_log_backend *backend);
120
127bool z_shell_log_backend_process(const struct shell_log_backend *backend);
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* SHELL_LOG_BACKEND_H__ */
int atomic_t
Definition: atomic.h:21
shell_log_backend_state
Shell log backend states.
Definition: shell_log_backend.h:22
@ SHELL_LOG_BACKEND_UNINIT
Definition: shell_log_backend.h:23
@ SHELL_LOG_BACKEND_PANIC
Definition: shell_log_backend.h:26
@ SHELL_LOG_BACKEND_DISABLED
Definition: shell_log_backend.h:25
@ SHELL_LOG_BACKEND_ENABLED
Definition: shell_log_backend.h:24
const struct log_backend_api log_backend_shell_api
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Message Queue Structure.
Definition: kernel.h:4290
Logger backend API.
Definition: log_backend.h:32
Logger backend structure.
Definition: log_backend.h:62
Log message structure.
Definition: log_msg.h:139
Log_output instance structure.
Definition: log_output.h:76
MPSC packet buffer configuration.
Definition: mpsc_pbuf.h:119
MPSC packet buffer structure.
Definition: mpsc_pbuf.h:84
Shell log backend control block (RW data).
Definition: shell_log_backend.h:30
enum shell_log_backend_state state
Definition: shell_log_backend.h:32
atomic_t dropped_cnt
Definition: shell_log_backend.h:31
Shell log backend message structure.
Definition: shell_log_backend.h:47
struct log_msg * msg
Definition: shell_log_backend.h:48
uint32_t timestamp
Definition: shell_log_backend.h:49
Shell log backend instance structure (RO data).
Definition: shell_log_backend.h:36
uint32_t timeout
Definition: shell_log_backend.h:41
struct mpsc_pbuf_buffer * mpsc_buffer
Definition: shell_log_backend.h:43
const struct log_backend * backend
Definition: shell_log_backend.h:37
const struct mpsc_pbuf_buffer_config * mpsc_buffer_config
Definition: shell_log_backend.h:42
struct k_msgq * msgq
Definition: shell_log_backend.h:38
const struct log_output * log_output
Definition: shell_log_backend.h:39
struct shell_log_backend_control_block * control_block
Definition: shell_log_backend.h:40
static fdata_t data[2]
Definition: test_fifo_contexts.c:15