blob: 040223bc4e30439c5ea0a25daee809b64affc647 [file] [log] [blame]
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ipc/ipc_service.h>
#include <ipc/ipc_service_backend.h>
#include <logging/log.h>
#include <zephyr.h>
#include <device.h>
LOG_MODULE_REGISTER(ipc_service, CONFIG_IPC_SERVICE_LOG_LEVEL);
int ipc_service_register_endpoint(const struct device *instance,
struct ipc_ept *ept,
const struct ipc_ept_cfg *cfg)
{
const struct ipc_service_backend *backend;
if (!instance || !ept || !cfg) {
LOG_ERR("Invalid instance, endpoint or configuration");
return -EINVAL;
}
backend = (const struct ipc_service_backend *) instance->api;
if (!backend || !backend->register_endpoint) {
LOG_ERR("Invalid backend configuration");
return -EIO;
}
LOG_DBG("Register endpoint %s", cfg->name ? cfg->name : "");
ept->instance = instance;
return backend->register_endpoint(instance, &ept->token, cfg);
}
int ipc_service_send(struct ipc_ept *ept, const void *data, size_t len)
{
const struct ipc_service_backend *backend;
backend = ept->instance->api;
if (!backend || !backend->send) {
LOG_ERR("Invalid backend configuration");
return -EIO;
}
return backend->send(ept->instance, ept->token, data, len);
}