Zephyr Project API 3.7.0
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#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>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
26struct log_link;
27
28typedef void (*log_link_callback_t)(const struct log_link *link,
29 union log_msg_generic *msg);
30
31typedef void (*log_link_dropped_cb_t)(const struct log_link *link,
32 uint32_t dropped);
33
38
40 int (*initiate)(const struct log_link *link, struct log_link_config *config);
41 int (*activate)(const struct log_link *link);
42 int (*get_domain_name)(const struct log_link *link, uint32_t domain_id,
43 char *buf, size_t *length);
44 int (*get_source_name)(const struct log_link *link, uint32_t domain_id,
45 uint16_t source_id, char *buf, size_t *length);
46 int (*get_levels)(const struct log_link *link, uint32_t domain_id,
47 uint16_t source_id, uint8_t *level,
48 uint8_t *runtime_level);
49 int (*set_runtime_level)(const struct log_link *link, uint32_t domain_id,
50 uint16_t source_id, uint8_t level);
51};
52
55 uint16_t source_cnt[1 + COND_CODE_1(CONFIG_LOG_MULTIDOMAIN,
56 (CONFIG_LOG_REMOTE_DOMAIN_MAX_COUNT),
57 (0))];
60};
61
70
86#define LOG_LINK_DEF(_name, _api, _buf_wlen, _ctx) \
87 static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) _name##_buf32[_buf_wlen]; \
88 static const struct mpsc_pbuf_buffer_config _name##_mpsc_pbuf_config = { \
89 .buf = (uint32_t *)_name##_buf32, \
90 .size = _buf_wlen, \
91 .notify_drop = z_log_notify_drop, \
92 .get_wlen = log_msg_generic_get_wlen, \
93 .flags = IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ? \
94 MPSC_PBUF_MODE_OVERWRITE : 0 \
95 }; \
96 COND_CODE_0(_buf_wlen, (), (static STRUCT_SECTION_ITERABLE(log_msg_ptr, \
97 _name##_log_msg_ptr);)) \
98 static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, \
99 mpsc_pbuf_buffer, \
100 _name##_log_mpsc_pbuf); \
101 static struct log_link_ctrl_blk _name##_ctrl_blk; \
102 static const STRUCT_SECTION_ITERABLE(log_link, _name) = \
103 { \
104 .api = &_api, \
105 .name = STRINGIFY(_name), \
106 .ctrl_blk = &_name##_ctrl_blk, \
107 .ctx = _ctx, \
108 .mpsc_pbuf = _buf_wlen ? &_name##_log_mpsc_pbuf : NULL, \
109 .mpsc_pbuf_config = _buf_wlen ? &_name##_mpsc_pbuf_config : NULL \
110 }
111
123static inline int log_link_initiate(const struct log_link *link,
124 struct log_link_config *config)
125{
126 __ASSERT_NO_MSG(link);
127
128 return link->api->initiate(link, config);
129}
130
142static inline int log_link_activate(const struct log_link *link)
143{
144 __ASSERT_NO_MSG(link);
145
146 return link->api->activate(link);
147}
148
156static inline int log_link_is_active(const struct log_link *link)
157{
158 return link->ctrl_blk->domain_offset > 0 ? 0 : -EINPROGRESS;
159}
160
167static inline uint8_t log_link_domains_count(const struct log_link *link)
168{
169 __ASSERT_NO_MSG(link);
170
171 return link->ctrl_blk->domain_cnt;
172}
173
181static inline uint16_t log_link_sources_count(const struct log_link *link,
182 uint32_t domain_id)
183{
184 __ASSERT_NO_MSG(link);
185
186 return link->ctrl_blk->source_cnt[domain_id];
187}
188
201static inline int log_link_get_domain_name(const struct log_link *link,
202 uint32_t domain_id, char *buf,
203 size_t *length)
204{
205 __ASSERT_NO_MSG(link);
206
207 return link->api->get_domain_name(link, domain_id, buf, length);
208}
209
222static inline int log_link_get_source_name(const struct log_link *link,
223 uint32_t domain_id, uint16_t source_id,
224 char *buf, size_t *length)
225{
226 __ASSERT_NO_MSG(link);
227 __ASSERT_NO_MSG(buf);
228
229 return link->api->get_source_name(link, domain_id, source_id,
230 buf, length);
231}
232
243static inline int log_link_get_levels(const struct log_link *link,
244 uint32_t domain_id, uint16_t source_id,
245 uint8_t *level, uint8_t *runtime_level)
246{
247 __ASSERT_NO_MSG(link);
248
249 return link->api->get_levels(link, domain_id, source_id,
250 level, runtime_level);
251}
252
262static inline int log_link_set_runtime_level(const struct log_link *link,
263 uint32_t domain_id, uint16_t source_id,
264 uint8_t level)
265{
266 __ASSERT_NO_MSG(link);
267 __ASSERT_NO_MSG(level);
268
269 return link->api->set_runtime_level(link, domain_id, source_id, level);
270}
271
282void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len);
283
288#ifdef __cplusplus
289}
290#endif
291
292#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:179
#define EINPROGRESS
Operation now in progress.
Definition errno.h:103
__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:117