ipc: Added IPC Service to support different transport backends
IPC Service allow plugging in different transport backends. Specifies a generic API that is implemented by the backend. Signed-off-by: Marcin Jeliński <marcin.jelinski@nordicsemi.no>
This commit is contained in:
parent
14272c2726
commit
3fcd8d1003
7 changed files with 275 additions and 0 deletions
107
include/ipc/ipc_service.h
Normal file
107
include/ipc/ipc_service.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_H_
|
||||
#define ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief IPC Service API
|
||||
* @defgroup ipc_service_api IPC service APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief Event callback structure.
|
||||
*
|
||||
* It is registered during endpoint registration.
|
||||
* This structure is part of the endpoint configuration.
|
||||
*/
|
||||
struct ipc_service_cb {
|
||||
/** @brief Bind was successful.
|
||||
*
|
||||
* @param priv Private user data.
|
||||
*/
|
||||
void (*bound)(void *priv);
|
||||
|
||||
/** @brief New packet arrived.
|
||||
*
|
||||
* @param data Pointer to data buffer.
|
||||
* @param len Length of @a data.
|
||||
* @param priv Private user data.
|
||||
*/
|
||||
void (*received)(const void *data, size_t len, void *priv);
|
||||
|
||||
/** @brief An error occurred.
|
||||
*
|
||||
* @param message Error message.
|
||||
* @param priv Private user data.
|
||||
*/
|
||||
void (*error)(const char *message, void *priv);
|
||||
};
|
||||
|
||||
/** @brief Endpoint instance.
|
||||
*
|
||||
* Content is not important for user of the API.
|
||||
* It is implemented in a specific backend.
|
||||
*/
|
||||
struct ipc_ept;
|
||||
|
||||
/** @brief Endpoint configuration structure. */
|
||||
struct ipc_ept_cfg {
|
||||
|
||||
/** Name of the endpoint. */
|
||||
const char *name;
|
||||
|
||||
/** Endpoint priority. If the backend supports priorities. */
|
||||
int prio;
|
||||
|
||||
/** Event callback structure. */
|
||||
struct ipc_service_cb cb;
|
||||
|
||||
/** Private user data. */
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/** @brief Register IPC endpoint.
|
||||
*
|
||||
* Registers IPC endpoint to enable communication with a remote device.
|
||||
*
|
||||
* The same function registers endpoints for both master and slave devices.
|
||||
*
|
||||
* @param ept Endpoint object.
|
||||
* @param cfg Endpoint configuration.
|
||||
*
|
||||
* @retval -EIO when no backend is registered.
|
||||
* @retval -EINVAL when pointer to an endpoint or endpoint configuration is invalid.
|
||||
* @retval Other errno codes depending on the implementation of the backend.
|
||||
*/
|
||||
int ipc_service_register_endpoint(struct ipc_ept **ept, const struct ipc_ept_cfg *cfg);
|
||||
|
||||
/** @brief Send data using given IPC endpoint.
|
||||
*
|
||||
* @param ept Registered endpoint by @ref ipc_service_register_endpoint.
|
||||
* @param data Pointer to the buffer to send.
|
||||
* @param len Number of bytes to send.
|
||||
*
|
||||
* @retval -EIO when no backend is registered.
|
||||
* @retval Other errno codes depending on the implementation of the backend.
|
||||
*/
|
||||
int ipc_service_send(struct ipc_ept *ept, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_H_ */
|
72
include/ipc/ipc_service_backend.h
Normal file
72
include/ipc/ipc_service_backend.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_BACKEND_H_
|
||||
#define ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_BACKEND_H_
|
||||
|
||||
#include <ipc/ipc_service.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief IPC Service backend
|
||||
* @ingroup ipc_service_api
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief IPC backend configuration structure.
|
||||
*
|
||||
* This structure is used for configuration backend during registration.
|
||||
*/
|
||||
struct ipc_service_backend {
|
||||
/** @brief Name of the IPC backend. */
|
||||
const char *name;
|
||||
|
||||
/** @brief Pointer to the function that will be used to send data to the endpoint.
|
||||
*
|
||||
* @param ept Registered endpoint.
|
||||
* @param data Pointer to the buffer to send.
|
||||
* @param len Number of bytes to send.
|
||||
*
|
||||
* @retval Status code.
|
||||
*/
|
||||
int (*send)(struct ipc_ept *ept, const void *data, size_t len);
|
||||
|
||||
/** @brief Pointer to the function that will be used to register endpoints.
|
||||
*
|
||||
* @param ept Endpoint object.
|
||||
* @param cfg Endpoint configuration.
|
||||
*
|
||||
* @retval Status code.
|
||||
*/
|
||||
int (*register_endpoint)(struct ipc_ept **ept, const struct ipc_ept_cfg *cfg);
|
||||
};
|
||||
|
||||
/** @brief IPC backend registration.
|
||||
*
|
||||
* Registration must be done before using IPC Service.
|
||||
*
|
||||
* @param backend Configuration of the backend.
|
||||
*
|
||||
* @retval -EALREADY The backend is already registered.
|
||||
* @retval -EINVAL The backend configuration is incorrect.
|
||||
* @retval Zero on success.
|
||||
*
|
||||
*/
|
||||
int ipc_service_register_backend(const struct ipc_service_backend *backend);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_IPC_SERVICE_IPC_SERVICE_BACKEND_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue