Zephyr Project API  3.3.0
A Scalable Open Source RTOS
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#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
7#define ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
8
9#include <zephyr/types.h>
10#include <zephyr/sys/__assert.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
25struct log_link;
26
27typedef void (*log_link_callback_t)(const struct log_link *link,
28 union log_msg_generic *msg);
29
30typedef void (*log_link_dropped_cb_t)(const struct log_link *link,
31 uint32_t dropped);
32
36};
37
39 int (*initiate)(const struct log_link *link, struct log_link_config *config);
40 int (*activate)(const struct log_link *link);
41 int (*get_domain_name)(const struct log_link *link, uint32_t domain_id,
42 char *buf, size_t *length);
43 int (*get_source_name)(const struct log_link *link, uint32_t domain_id,
44 uint16_t source_id, char *buf, size_t *length);
45 int (*get_levels)(const struct log_link *link, uint32_t domain_id,
46 uint16_t source_id, uint8_t *level,
47 uint8_t *runtime_level);
48 int (*set_runtime_level)(const struct log_link *link, uint32_t domain_id,
49 uint16_t source_id, uint8_t level);
50};
51
54 uint16_t source_cnt[1 + COND_CODE_1(CONFIG_LOG_MULTIDOMAIN,
55 (CONFIG_LOG_REMOTE_DOMAIN_MAX_COUNT),
56 (0))];
59};
60
61struct log_link {
62 const struct log_link_api *api;
63 const char *name;
65 void *ctx;
68};
69
85#define LOG_LINK_DEF(_name, _api, _buf_wlen, _ctx) \
86 static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) _name##_buf32[_buf_wlen]; \
87 static const struct mpsc_pbuf_buffer_config _name##_mpsc_pbuf_config = { \
88 .buf = (uint32_t *)_name##_buf32, \
89 .size = _buf_wlen, \
90 .notify_drop = z_log_notify_drop, \
91 .get_wlen = log_msg_generic_get_wlen, \
92 .flags = IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ? \
93 MPSC_PBUF_MODE_OVERWRITE : 0 \
94 }; \
95 COND_CODE_0(_buf_wlen, (), (static STRUCT_SECTION_ITERABLE(log_msg_ptr, \
96 _name##_log_msg_ptr);)) \
97 static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, \
98 mpsc_pbuf_buffer, \
99 _name##_log_mpsc_pbuf); \
100 static struct log_link_ctrl_blk _name##_ctrl_blk; \
101 static const STRUCT_SECTION_ITERABLE(log_link, _name) = \
102 { \
103 .api = &_api, \
104 .name = STRINGIFY(_name), \
105 .ctrl_blk = &_name##_ctrl_blk, \
106 .ctx = _ctx, \
107 .mpsc_pbuf = _buf_wlen ? &_name##_log_mpsc_pbuf : NULL, \
108 .mpsc_pbuf_config = _buf_wlen ? &_name##_mpsc_pbuf_config : NULL \
109 }
110
122static inline int log_link_initiate(const struct log_link *link,
123 struct log_link_config *config)
124{
125 __ASSERT_NO_MSG(link);
126
127 return link->api->initiate(link, config);
128}
129
141static inline int log_link_activate(const struct log_link *link)
142{
143 __ASSERT_NO_MSG(link);
144
145 return link->api->activate(link);
146}
147
155static inline int log_link_is_active(const struct log_link *link)
156{
157 return link->ctrl_blk->domain_offset > 0 ? 0 : -EINPROGRESS;
158}
159
166static inline uint8_t log_link_domains_count(const struct log_link *link)
167{
168 __ASSERT_NO_MSG(link);
169
170 return link->ctrl_blk->domain_cnt;
171}
172
180static inline uint16_t log_link_sources_count(const struct log_link *link,
181 uint32_t domain_id)
182{
183 __ASSERT_NO_MSG(link);
184
185 return link->ctrl_blk->source_cnt[domain_id];
186}
187
200static inline int log_link_get_domain_name(const struct log_link *link,
201 uint32_t domain_id, char *buf,
202 size_t *length)
203{
204 __ASSERT_NO_MSG(link);
205
206 return link->api->get_domain_name(link, domain_id, buf, length);
207}
208
221static inline int log_link_get_source_name(const struct log_link *link,
222 uint32_t domain_id, uint16_t source_id,
223 char *buf, size_t *length)
224{
225 __ASSERT_NO_MSG(link);
226 __ASSERT_NO_MSG(buf);
227
228 return link->api->get_source_name(link, domain_id, source_id,
229 buf, length);
230}
231
242static inline int log_link_get_levels(const struct log_link *link,
243 uint32_t domain_id, uint16_t source_id,
244 uint8_t *level, uint8_t *runtime_level)
245{
246 __ASSERT_NO_MSG(link);
247
248 return link->api->get_levels(link, domain_id, source_id,
249 level, runtime_level);
250}
251
261static inline int log_link_set_runtime_level(const struct log_link *link,
262 uint32_t domain_id, uint16_t source_id,
263 uint8_t level)
264{
265 __ASSERT_NO_MSG(link);
266 __ASSERT_NO_MSG(level);
267
268 return link->api->set_runtime_level(link, domain_id, source_id, level);
269}
270
281void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len);
282
287#ifdef __cplusplus
288}
289#endif
290
291#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:176
#define EINPROGRESS
Definition: errno.h:104
__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
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static void msg(uint64_t c64)
Definition: main.c:17
Definition: log_msg.h:111