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  * @{
20  */
21 
22 /**
23  * @brief Register IPC endpoint
24  *
25  * Registers IPC endpoint to enable communication with a remote device.
26  * The endpoint is created when the slave device registers it.
27  *
28  * The same function registers endpoints for both master and slave devices.
29  *
30  * @param name String containing the name of the endpoint. Must be identical
31  *             for master and slave
32  * @param cb Callback executed when data are available on given endpoint
33  *
34  * @retval >=0 id of registered endpoint on success;
35  * @retval -EINPROGRESS when requested to register an endpoint after endpoints
36  *         creation procedure has started;
37  * @retval -ENOMEM when there is not enough slots to register the endpoint;
38  * @retval <0 an other negative errno code, reported by rpmsg.
39  */
40 int rpmsg_service_register_endpoint(const char *name, rpmsg_ept_cb cb);
41 
42 /**
43  * @brief Send data using given IPC endpoint
44  *
45  * @param endpoint_id Id of registered endpoint, obtained by
46  *                    @ref rpmsg_service_register_endpoint
47  * @param data Pointer to the buffer to send through RPMsg service
48  * @param len Number of bytes to send.
49  *
50  * @retval >=0 number of sent bytes;
51  * @retval <0 an error code, reported by rpmsg.
52  */
53 int rpmsg_service_send(int endpoint_id, const void *data, size_t len);
54 
55 /**
56  * @brief Check if endpoint is bound.
57  *
58  * Checks if remote endpoint has been created
59  * and the master has bound its endpoint to it.
60  *
61  * @param endpoint_id Id of registered endpoint, obtained by
62  *                    @ref rpmsg_service_register_endpoint
63  *
64  * @retval true endpoint is bound
65  * @retval false endpoint not bound
66  */
67 bool rpmsg_service_endpoint_is_bound(int endpoint_id);
68 
69 /**
70  * @}
71  */
72 
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif /* ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_ */
79