logging: Add ipc_service log link

Added link that sends messages over ipc_service. It uses
log_link_remote and will talk to log_backend_ipc_service based
on log_link_backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-08-12 09:19:13 +02:00 committed by Carles Cufí
parent b01867812e
commit af573dbffb
3 changed files with 116 additions and 0 deletions

View file

@ -70,6 +70,11 @@ if(NOT CONFIG_LOG_MODE_MINIMAL)
log_multidomain_link.c
)
zephyr_sources_ifdef(
CONFIG_LOG_LINK_IPC_SERVICE
log_link_ipc_service.c
)
else()
zephyr_sources(log_minimal.c)

View file

@ -4,3 +4,17 @@
config LOG_MULTIDOMAIN_LINK
bool
select LOG_TIMESTAMP_64BIT
config LOG_LINK_IPC_SERVICE
bool "IPC service link"
depends on LOG_MULTIDOMAIN
select LOG_MULTIDOMAIN_LINK
config LOG_LINK_IPC_SERVICE_BUFFER_SIZE
int "Dedicated buffer size"
depends on LOG_LINK_IPC_SERVICE
default 2048
help
Dedicated buffer allows to maintain ordering of processed messages.
If 0, main buffer is used and messages are processed in the order of
arrival.

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/ipc/ipc_service.h>
#include <zephyr/logging/log_link.h>
#include <zephyr/logging/log_multidomain_helper.h>
#include <zephyr/logging/log_core.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(link_ipc);
struct log_link_ipc_service {
struct ipc_ept ept;
struct log_multidomain_link link_remote;
};
static void bound_cb(void *priv)
{
struct log_multidomain_link *link_remote = priv;
log_multidomain_link_on_started(link_remote, 0);
}
static void error_cb(const char *message, void *priv)
{
struct log_multidomain_link *link_remote = priv;
log_multidomain_link_on_error(link_remote, -EIO);
}
static void recv_cb(const void *data, size_t len, void *priv)
{
struct log_multidomain_link *link_remote = priv;
log_multidomain_link_on_recv_cb(link_remote, data, len);
}
static int link_ipc_service_send(struct log_multidomain_link *link_remote,
void *data, size_t len)
{
struct log_link_ipc_service *link_ipc_service =
CONTAINER_OF(link_remote, struct log_link_ipc_service, link_remote);
return ipc_service_send(&link_ipc_service->ept, data, len);
}
static int link_ipc_service_init(struct log_multidomain_link *link_remote)
{
struct log_link_ipc_service *link_ipc_service =
CONTAINER_OF(link_remote, struct log_link_ipc_service, link_remote);
static struct ipc_ept_cfg ept_cfg = {
.name = "logging",
.prio = 0,
.cb = {
.bound = bound_cb,
.received = recv_cb,
.error = error_cb,
},
};
const struct device *ipc_instance = DEVICE_DT_GET(DT_CHOSEN(zephyr_log_ipc));
int err;
ept_cfg.priv = (void *)link_remote;
err = ipc_service_open_instance(ipc_instance);
if (err < 0 && err != -EALREADY) {
__ASSERT(0, "ipc_service_open_instance() failure (err:%d)\n", err);
return err;
}
err = ipc_service_register_endpoint(ipc_instance, &link_ipc_service->ept, &ept_cfg);
return err;
}
struct log_multidomain_link_transport_api log_link_ipc_service_transport_api = {
.init = link_ipc_service_init,
.send = link_ipc_service_send
};
static struct log_link_ipc_service link_ipc_service_data = {
.link_remote = {
.transport_api = &log_link_ipc_service_transport_api
}
};
LOG_LINK_DEF(link_ipc_service, log_multidomain_link_api,
CONFIG_LOG_LINK_IPC_SERVICE_BUFFER_SIZE,
&link_ipc_service_data.link_remote);
const struct log_link *log_link_ipc_get_link(void)
{
return &link_ipc_service;
}