1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_
8 #define ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_
9 
10 #include <openamp/open_amp.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  * @brief RPMsg service API
18  * @defgroup rpmsg_service_api RPMsg service APIs
19  * @ingroup ipc
20  * @{
21  */
22 
23 /**
24  * @brief Register IPC endpoint
25  *
26  * Registers IPC endpoint to enable communication with a remote device.
27  * The endpoint is created when the slave device registers it.
28  *
29  * The same function registers endpoints for both master and slave devices.
30  *
31  * @param name String containing the name of the endpoint. Must be identical
32  *             for master and slave
33  * @param cb Callback executed when data are available on given endpoint
34  *
35  * @retval >=0 id of registered endpoint on success;
36  * @retval -EINPROGRESS when requested to register an endpoint after endpoints
37  *         creation procedure has started;
38  * @retval -ENOMEM when there is not enough slots to register the endpoint;
39  * @retval <0 an other negative errno code, reported by rpmsg.
40  */
41 int rpmsg_service_register_endpoint(const char *name, rpmsg_ept_cb cb);
42 
43 /**
44  * @brief Send data using given IPC endpoint
45  *
46  * @param endpoint_id Id of registered endpoint, obtained by
47  *                    @ref rpmsg_service_register_endpoint
48  * @param data Pointer to the buffer to send through RPMsg service
49  * @param len Number of bytes to send.
50  *
51  * @retval >=0 number of sent bytes;
52  * @retval <0 an error code, reported by rpmsg.
53  */
54 int rpmsg_service_send(int endpoint_id, const void *data, size_t len);
55 
56 /**
57  * @brief Check if endpoint is bound.
58  *
59  * Checks if remote endpoint has been created
60  * and the master has bound its endpoint to it.
61  *
62  * @param endpoint_id Id of registered endpoint, obtained by
63  *                    @ref rpmsg_service_register_endpoint
64  *
65  * @retval true endpoint is bound
66  * @retval false endpoint not bound
67  */
68 bool rpmsg_service_endpoint_is_bound(int endpoint_id);
69 
70 /**
71  * @}
72  */
73 
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_ */
80