Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
log_link.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
14#define ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
15
16#include <zephyr/types.h>
17#include <zephyr/sys/__assert.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
32
33struct log_link;
34
41typedef void (*log_link_callback_t)(const struct log_link *link,
42 union log_msg_generic *msg);
43
50typedef void (*log_link_dropped_cb_t)(const struct log_link *link,
51 uint32_t dropped);
52
58
66 int (*initiate)(const struct log_link *link, struct log_link_config *config);
68 int (*activate)(const struct log_link *link);
70 int (*get_domain_name)(const struct log_link *link, uint32_t domain_id,
71 char *buf, size_t *length);
73 int (*get_source_name)(const struct log_link *link, uint32_t domain_id,
74 uint16_t source_id, char *buf, size_t *length);
76 int (*get_levels)(const struct log_link *link, uint32_t domain_id,
77 uint16_t source_id, uint8_t *level,
78 uint8_t *runtime_level);
80 int (*set_runtime_level)(const struct log_link *link, uint32_t domain_id,
81 uint16_t source_id, uint8_t level);
82};
83
87 uint32_t domain_cnt;
88 uint16_t source_cnt[1 + COND_CODE_1(CONFIG_LOG_MULTIDOMAIN,
89 (CONFIG_LOG_REMOTE_DOMAIN_MAX_COUNT),
90 (0))];
91 uint32_t domain_offset;
92 uint32_t *filters;
94};
95
97struct log_link {
98 const struct log_link_api *api;
99 const char *name;
101 void *ctx;
103 struct mpsc_pbuf_buffer *mpsc_pbuf;
104 const struct mpsc_pbuf_buffer_config *mpsc_pbuf_config;
106};
107
123#define LOG_LINK_DEF(_name, _api, _buf_wlen, _ctx) \
124 static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) _name##_buf32[_buf_wlen]; \
125 static const struct mpsc_pbuf_buffer_config _name##_mpsc_pbuf_config = { \
126 .buf = (uint32_t *)_name##_buf32, \
127 .size = _buf_wlen, \
128 .notify_drop = z_log_notify_drop, \
129 .get_wlen = log_msg_generic_get_wlen, \
130 .flags = IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ? \
131 MPSC_PBUF_MODE_OVERWRITE : 0 \
132 }; \
133 COND_CODE_0(_buf_wlen, (), (static STRUCT_SECTION_ITERABLE(log_msg_ptr, \
134 _name##_log_msg_ptr);)) \
135 static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, \
136 mpsc_pbuf_buffer, \
137 _name##_log_mpsc_pbuf); \
138 static struct log_link_ctrl_blk _name##_ctrl_blk; \
139 static const STRUCT_SECTION_ITERABLE(log_link, _name) = \
140 { \
141 .api = &_api, \
142 .name = STRINGIFY(_name), \
143 .ctrl_blk = &_name##_ctrl_blk, \
144 .ctx = _ctx, \
145 .mpsc_pbuf = _buf_wlen ? &_name##_log_mpsc_pbuf : NULL, \
146 .mpsc_pbuf_config = _buf_wlen ? &_name##_mpsc_pbuf_config : NULL \
147 }
148
160static inline int log_link_initiate(const struct log_link *link,
161 struct log_link_config *config)
162{
163 __ASSERT_NO_MSG(link);
164
165 return link->api->initiate(link, config);
166}
167
179static inline int log_link_activate(const struct log_link *link)
180{
181 __ASSERT_NO_MSG(link);
182
183 return link->api->activate(link);
184}
185
193static inline int log_link_is_active(const struct log_link *link)
194{
195 return link->ctrl_blk->domain_offset > 0 ? 0 : -EINPROGRESS;
196}
197
204static inline uint8_t log_link_domains_count(const struct log_link *link)
205{
206 __ASSERT_NO_MSG(link);
207
208 return link->ctrl_blk->domain_cnt;
209}
210
218static inline uint16_t log_link_sources_count(const struct log_link *link,
219 uint32_t domain_id)
220{
221 __ASSERT_NO_MSG(link);
222
223 return link->ctrl_blk->source_cnt[domain_id];
224}
225
238static inline int log_link_get_domain_name(const struct log_link *link,
239 uint32_t domain_id, char *buf,
240 size_t *length)
241{
242 __ASSERT_NO_MSG(link);
243
244 return link->api->get_domain_name(link, domain_id, buf, length);
245}
246
259static inline int log_link_get_source_name(const struct log_link *link,
260 uint32_t domain_id, uint16_t source_id,
261 char *buf, size_t *length)
262{
263 __ASSERT_NO_MSG(link);
264 __ASSERT_NO_MSG(buf);
265
266 return link->api->get_source_name(link, domain_id, source_id,
267 buf, length);
268}
269
280static inline int log_link_get_levels(const struct log_link *link,
281 uint32_t domain_id, uint16_t source_id,
282 uint8_t *level, uint8_t *runtime_level)
283{
284 __ASSERT_NO_MSG(link);
285
286 return link->api->get_levels(link, domain_id, source_id,
287 level, runtime_level);
288}
289
299static inline int log_link_set_runtime_level(const struct log_link *link,
300 uint32_t domain_id, uint16_t source_id,
301 uint8_t level)
302{
303 __ASSERT_NO_MSG(link);
304 __ASSERT_NO_MSG(level);
305
306 return link->api->set_runtime_level(link, domain_id, source_id, level);
307}
308
319void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len);
320
324
325#ifdef __cplusplus
326}
327#endif
328
329#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_ */
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:209
#define EINPROGRESS
Operation now in progress.
Definition errno.h:104
Header file for logging internal functions.
Header file for log messages.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
MPSC packet buffer configuration.
Definition mpsc_pbuf.h:131
uint32_t * buf
Definition mpsc_pbuf.h:133
MPSC packet buffer structure.
Definition mpsc_pbuf.h:90
Iterable sections helpers.