Line data Source code
1 0 : /*
2 : * Copyright (c) 2022 Nordic Semiconductor ASA
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MULTIDOMAIN_HELPER_H_
8 : #define ZEPHYR_INCLUDE_LOGGING_LOG_MULTIDOMAIN_HELPER_H_
9 :
10 : /**
11 : * @brief Logger multidomain backend helpers
12 : *
13 : * This module aims to provide baseline for links and backends and simplify
14 : * the implementation. It is not core part of logging in similar way as
15 : * log_output module is just a helper for log message formatting. Links and
16 : * backends can be implemented without this helper.
17 : *
18 : * @defgroup log_backend_multidomain Logger multidomain backend helpers
19 : * @ingroup log_backend
20 : * @{
21 : */
22 :
23 : /**
24 : * @name Multidomain message IDs
25 : * @anchor LOG_MULTIDOMAIN_HELPER_MESSAGE_IDS
26 : * @{
27 : */
28 :
29 : /** @brief Logging message ID. */
30 : #define Z_LOG_MULTIDOMAIN_ID_MSG 0
31 :
32 : /** @brief Domain count request ID. */
33 : #define Z_LOG_MULTIDOMAIN_ID_GET_DOMAIN_CNT 1
34 :
35 : /** @brief Source count request ID. */
36 : #define Z_LOG_MULTIDOMAIN_ID_GET_SOURCE_CNT 2
37 :
38 : /** @brief Domain name request ID. */
39 : #define Z_LOG_MULTIDOMAIN_ID_GET_DOMAIN_NAME 3
40 :
41 : /** @brief Source name request ID. */
42 : #define Z_LOG_MULTIDOMAIN_ID_GET_SOURCE_NAME 4
43 :
44 : /** @brief Compile time and run-time levels request ID. */
45 : #define Z_LOG_MULTIDOMAIN_ID_GET_LEVELS 5
46 :
47 : /** @brief Setting run-time level ID. */
48 : #define Z_LOG_MULTIDOMAIN_ID_SET_RUNTIME_LEVEL 6
49 :
50 : /** @brief Get number of dropped message ID. */
51 : #define Z_LOG_MULTIDOMAIN_ID_DROPPED 7
52 :
53 : /** @brief Link-backend readiness indication ID/ */
54 : #define Z_LOG_MULTIDOMAIN_ID_READY 8
55 :
56 : /**@} */
57 :
58 : /**
59 : * @name Multidomain status flags
60 : * @anchor LOG_MULTIDOMAIN_STATUS
61 : * @{
62 : */
63 :
64 : /** @brief OK. */
65 : #define Z_LOG_MULTIDOMAIN_STATUS_OK 0
66 : /** @brief Error. */
67 : #define Z_LOG_MULTIDOMAIN_STATUS_ERR 1
68 :
69 : /**@} */
70 :
71 : /** @brief Content of the logging message. */
72 1 : struct log_multidomain_log_msg {
73 0 : FLEXIBLE_ARRAY_DECLARE(uint8_t, data);
74 : } __packed;
75 :
76 : /** @brief Content of the domain count message. */
77 1 : struct log_multidomain_domain_cnt {
78 0 : uint16_t count;
79 : } __packed;
80 :
81 : /** @brief Content of the source count message. */
82 1 : struct log_multidomain_source_cnt {
83 0 : uint8_t domain_id;
84 0 : uint16_t count;
85 : } __packed;
86 :
87 : /** @brief Content of the domain name message. */
88 1 : struct log_multidomain_domain_name {
89 0 : uint8_t domain_id;
90 0 : char name[];
91 : } __packed;
92 :
93 : /** @brief Content of the source name message. */
94 1 : struct log_multidomain_source_name {
95 0 : uint8_t domain_id;
96 0 : uint16_t source_id;
97 0 : char name[];
98 : } __packed;
99 :
100 : /** @brief Content of the message for getting logging levels. */
101 1 : struct log_multidomain_levels {
102 0 : uint8_t domain_id;
103 0 : uint16_t source_id;
104 0 : uint8_t level;
105 0 : uint8_t runtime_level;
106 : } __packed;
107 :
108 : /** @brief Content of the message for setting logging level. */
109 1 : struct log_multidomain_set_runtime_level {
110 0 : uint8_t domain_id;
111 0 : uint16_t source_id;
112 0 : uint8_t runtime_level;
113 : } __packed;
114 :
115 : /** @brief Content of the message for getting amount of dropped messages. */
116 1 : struct log_multidomain_dropped {
117 0 : uint32_t dropped;
118 : } __packed;
119 :
120 : /** @brief Union with all message types. */
121 1 : union log_multidomain_msg_data {
122 0 : struct log_multidomain_log_msg log_msg;
123 0 : struct log_multidomain_domain_cnt domain_cnt;
124 0 : struct log_multidomain_source_cnt source_cnt;
125 0 : struct log_multidomain_domain_name domain_name;
126 0 : struct log_multidomain_source_name source_name;
127 0 : struct log_multidomain_levels levels;
128 0 : struct log_multidomain_set_runtime_level set_rt_level;
129 0 : struct log_multidomain_dropped dropped;
130 : };
131 :
132 : /** @brief Message. */
133 1 : struct log_multidomain_msg {
134 0 : uint8_t id;
135 0 : uint8_t status;
136 0 : union log_multidomain_msg_data data;
137 : } __packed;
138 :
139 : /** @brief Forward declaration. */
140 : struct log_multidomain_link;
141 :
142 : /** @brief Structure with link transport API. */
143 1 : struct log_multidomain_link_transport_api {
144 0 : int (*init)(struct log_multidomain_link *link);
145 0 : int (*send)(struct log_multidomain_link *link, void *data, size_t len);
146 : };
147 :
148 : /** @brief Union for holding data returned by associated remote backend. */
149 1 : union log_multidomain_link_dst {
150 0 : uint16_t count;
151 :
152 : struct {
153 0 : char *dst;
154 0 : size_t *len;
155 0 : } name;
156 :
157 : struct {
158 0 : uint8_t level;
159 0 : uint8_t runtime_level;
160 0 : } levels;
161 :
162 : struct {
163 : uint8_t level;
164 0 : } set_runtime_level;
165 : };
166 :
167 : /** @brief Remote link API. */
168 1 : extern struct log_link_api log_multidomain_link_api;
169 :
170 : /** @brief Remote link structure. */
171 1 : struct log_multidomain_link {
172 0 : const struct log_multidomain_link_transport_api *transport_api;
173 0 : struct k_sem rdy_sem;
174 0 : const struct log_link *link;
175 0 : union log_multidomain_link_dst dst;
176 0 : int status;
177 0 : bool ready;
178 : };
179 :
180 : /** @brief Forward declaration. */
181 : struct log_multidomain_backend;
182 :
183 : /** @brief Backend transport API. */
184 1 : struct log_multidomain_backend_transport_api {
185 0 : int (*init)(struct log_multidomain_backend *backend);
186 0 : int (*send)(struct log_multidomain_backend *backend, void *data, size_t len);
187 : };
188 :
189 : /** @brief Remote backend API. */
190 1 : extern const struct log_backend_api log_multidomain_backend_api;
191 :
192 : /** @brief Remote backend structure. */
193 1 : struct log_multidomain_backend {
194 0 : const struct log_multidomain_backend_transport_api *transport_api;
195 0 : const struct log_backend *log_backend;
196 0 : struct k_sem rdy_sem;
197 0 : bool panic;
198 0 : int status;
199 0 : bool ready;
200 : };
201 :
202 : /** @brief Function to be called when data is received from remote.
203 : *
204 : * @param link Link instance.
205 : * @param data Data.
206 : * @param len Data length.
207 : */
208 1 : void log_multidomain_link_on_recv_cb(struct log_multidomain_link *link,
209 : const void *data, size_t len);
210 :
211 : /** @brief Function called on error reported by transport layer.
212 : *
213 : * @param link Link instance.
214 : * @param err Error code.
215 : */
216 1 : void log_multidomain_link_on_error(struct log_multidomain_link *link, int err);
217 :
218 : /** @brief Function called when connection with remote is established.
219 : *
220 : * @param link Link instance.
221 : * @param err Error code.
222 : */
223 1 : void log_multidomain_link_on_started(struct log_multidomain_link *link, int err);
224 :
225 : /** @brief Function to be called when data is received from remote.
226 : *
227 : * @param backend Backend instance.
228 : * @param data Data.
229 : * @param len Data length.
230 : */
231 1 : void log_multidomain_backend_on_recv_cb(struct log_multidomain_backend *backend,
232 : const void *data, size_t len);
233 :
234 : /** @brief Function called on error reported by transport layer.
235 : *
236 : * @param backend Backend instance.
237 : * @param err Error code.
238 : */
239 1 : void log_multidomain_backend_on_error(struct log_multidomain_backend *backend, int err);
240 :
241 : /** @brief Function called when connection with remote is established.
242 : *
243 : * @param backend Backend instance.
244 : * @param err Error code.
245 : */
246 1 : void log_multidomain_backend_on_started(struct log_multidomain_backend *backend, int err);
247 :
248 : /** @} */
249 :
250 : #endif /* ZEPHYR_INCLUDE_LOGGING_LOG_MULTIDOMAIN_HELPER_H_ */
|