logging: Add frontend support to v2
Extended logging v2 to support frontend api. Contrary to v1, it is possible to have frontend and backends in the system. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
ca217fe189
commit
7c72b78660
12 changed files with 95 additions and 24 deletions
|
@ -7,6 +7,13 @@
|
|||
#include <syscall_handler.h>
|
||||
#include <logging/log_internal.h>
|
||||
#include <logging/log_ctrl.h>
|
||||
#include <logging/log_frontend.h>
|
||||
#include <logging/log_backend.h>
|
||||
|
||||
/* Returns true if any backend is in use. */
|
||||
#define BACKENDS_IN_USE() \
|
||||
!(IS_ENABLED(CONFIG_LOG_FRONTEND) && \
|
||||
(IS_ENABLED(CONFIG_LOG_FRONTEND_ONLY) || log_backend_count_get() == 0))
|
||||
|
||||
void z_log_msg2_finalize(struct log_msg2 *msg, const void *source,
|
||||
const struct log_msg2_desc desc, const void *data)
|
||||
|
@ -32,6 +39,14 @@ void z_impl_z_log_msg2_static_create(const void *source,
|
|||
const struct log_msg2_desc desc,
|
||||
uint8_t *package, const void *data)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
||||
log_frontend_msg(source, desc, package, data);
|
||||
}
|
||||
|
||||
if (!BACKENDS_IN_USE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t msg_wlen = log_msg2_get_total_wlen(desc);
|
||||
struct log_msg2 *msg = z_log_msg2_alloc(msg_wlen);
|
||||
|
||||
|
@ -72,21 +87,34 @@ void z_impl_z_log_msg2_runtime_vcreate(uint8_t domain_id, const void *source,
|
|||
|
||||
size_t msg_wlen = Z_LOG_MSG2_ALIGNED_WLEN(plen, dlen);
|
||||
struct log_msg2 *msg;
|
||||
uint8_t *pkg;
|
||||
struct log_msg2_desc desc =
|
||||
Z_LOG_MSG_DESC_INITIALIZER(domain_id, level, plen, dlen);
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) {
|
||||
msg = alloca(msg_wlen * sizeof(int));
|
||||
} else {
|
||||
if (IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) && BACKENDS_IN_USE()) {
|
||||
msg = z_log_msg2_alloc(msg_wlen);
|
||||
if (IS_ENABLED(CONFIG_LOG_FRONTEND) && msg == NULL) {
|
||||
pkg = alloca(plen);
|
||||
} else {
|
||||
pkg = msg ? msg->data : NULL;
|
||||
}
|
||||
} else {
|
||||
msg = alloca(msg_wlen * sizeof(int));
|
||||
pkg = msg->data;
|
||||
}
|
||||
|
||||
if (msg && fmt) {
|
||||
plen = cbvprintf_package(msg->data, (size_t)plen, package_flags, fmt, ap);
|
||||
if (pkg && fmt) {
|
||||
plen = cbvprintf_package(pkg, (size_t)plen, package_flags, fmt, ap);
|
||||
__ASSERT_NO_MSG(plen >= 0);
|
||||
}
|
||||
|
||||
z_log_msg2_finalize(msg, source, desc, data);
|
||||
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
||||
log_frontend_msg(source, desc, pkg, data);
|
||||
}
|
||||
|
||||
if (BACKENDS_IN_USE()) {
|
||||
z_log_msg2_finalize(msg, source, desc, data);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue