Skip to content

Commit 69663da

Browse files
committed
logging: Add logging v2 implementation for log_msg
Added implementation of log_msg2 which is creating log messages using cbprintf packaging and storing them in circular ring buffer (mpsg_pbuf). Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 1cfe6e9 commit 69663da

File tree

14 files changed

+1008
-20
lines changed

14 files changed

+1008
-20
lines changed

include/linker/common-rom.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
} GROUP_LINK_IN(ROMABLE_REGION)
154154
#endif /* CONFIG_PCIE */
155155

156+
SECTION_DATA_PROLOGUE(log_strings_sections,,)
157+
{
158+
__log_strings_start = .;
159+
KEEP(*(SORT(.log_strings*)));
160+
__log_strings_end = .;
161+
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
162+
156163
SECTION_DATA_PROLOGUE(log_const_sections,,)
157164
{
158165
__log_const_start = .;

include/logging/log_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_
88

99
#include <logging/log_msg.h>
10+
#include <logging/log_core2.h>
1011
#include <logging/log_instance.h>
1112
#include <stdbool.h>
1213
#include <stdint.h>
@@ -438,6 +439,7 @@ enum log_strdup_action {
438439
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
439440
} while (0)
440441

442+
441443
/** @brief Get name of the log source.
442444
*
443445
* @param source_id Source ID.

include/logging/log_core2.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_
7+
#define ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_
8+
9+
#include <logging/log_msg2.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#define Z_TRACING_LOG_TRACE(id) do { \
16+
Z_TRACING_LOG_HDR_INIT(_msg, id); \
17+
z_log_msg2_put_trace(_msg); \
18+
} while (0)
19+
20+
#define Z_TRACING_LOG_TRACE_PTR(id, ptr) do { \
21+
Z_TRACING_LOG_HDR_INIT(_msg, id); \
22+
z_log_msg2_put_trace_ptr(_msg, ptr); \
23+
} while (0)
24+
25+
void z_log_msg2_put_trace(struct log_msg2_trace trace);
26+
27+
void z_log_msg2_put_trace_ptr(struct log_msg2_trace hdr, void *data);
28+
29+
30+
/** @brief Initialize module for handling logging message. */
31+
void z_log_msg2_init(void);
32+
33+
/** @brief Allocate log message.
34+
*
35+
* @param wlen Length in 32 bit words.
36+
*
37+
* @return allocated space or null if cannot be allocated.
38+
*/
39+
struct log_msg2 *z_log_msg2_alloc(uint32_t wlen);
40+
41+
/** @brief Commit log message.
42+
*
43+
* @param msg Message.
44+
*/
45+
void z_log_msg2_commit(struct log_msg2 *msg);
46+
47+
/** @brief Get pending log message.
48+
*
49+
* @param[out] len Message length in bytes is written is @p len is not null.
50+
*
51+
* @param Message or null if no pending messages.
52+
*/
53+
union log_msg2_generic *z_log_msg2_claim(void);
54+
55+
/** @brief Free message.
56+
*
57+
* @param msg Message.
58+
*/
59+
void z_log_msg2_free(union log_msg2_generic *msg);
60+
61+
/** @brief Check if there are any message pending.
62+
*
63+
* @retval true if at least one message is pending.
64+
* @retval false if no message is pending.
65+
*/
66+
bool z_log_msg2_pending(void);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_CORE2_H_ */

include/logging/log_ctrl.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_
77
#define ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_
88

9-
#include <logging/log_backend.h>
109
#include <kernel.h>
10+
#include <logging/log_backend.h>
11+
#include <logging/log_msg.h>
1112

1213
#ifdef __cplusplus
1314
extern "C" {
1415
#endif
1516

16-
1717
/**
1818
* @brief Logger
1919
* @defgroup logger Logger system
@@ -29,7 +29,7 @@ extern "C" {
2929
* @{
3030
*/
3131

32-
typedef uint32_t (*timestamp_get_t)(void);
32+
typedef log_timestamp_t (*log_timestamp_get_t)(void);
3333

3434
/** @brief Function system initialization of the logger.
3535
*
@@ -63,7 +63,8 @@ void log_thread_set(k_tid_t process_tid);
6363
*
6464
* @return 0 on success or error.
6565
*/
66-
int log_set_timestamp_func(timestamp_get_t timestamp_getter, uint32_t freq);
66+
int log_set_timestamp_func(log_timestamp_get_t timestamp_getter,
67+
uint32_t freq);
6768

6869
/**
6970
* @brief Switch the logger subsystem to the panic mode.

include/logging/log_msg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/atomic.h>
1010
#include <sys/util.h>
1111
#include <string.h>
12+
#include <logging/log_msg2.h>
1213

1314
#ifdef __cplusplus
1415
extern "C" {

0 commit comments

Comments
 (0)