AM64x MCU+ SDK  11.01.00
ipc_rpmsg.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-2023 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef IPC_RPMSG_H_
34 #define IPC_RPMSG_H_
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdint.h>
41 #include <kernel/dpl/SystemP.h>
42 #include <kernel/dpl/SemaphoreP.h>
43 #include <drivers/hw_include/cslr_soc.h>
44 #include <drivers/ipc_rpmsg/ipc_rpmsg_queue.h>
45 #include <drivers/ipc_rpmsg/include/ipc_rpmsg_linux_resource_table.h>
46 
62 #define RPMESSAGE_MAX_LOCAL_ENDPT (64U)
63 
70 #define RPMESSAGE_VRING_ADDR_INVALID (0xFFFFFFFFU)
71 
86 #define RPMESSAGE_VRING_SIZE(numBuf, bufSize) (((numBuf)*(uint16_t)((bufSize)+32U))+32U)
87 
91 #define RPMESSAGE_OBJECT_SIZE_MAX (192U)
92 
96 #define RPMESSAGE_CRC_SIZE (2U)
97 
101 struct RPMessage_Object_s;
102 
122 typedef void (*RPMessage_RecvCallback)(struct RPMessage_Object_s *obj, void *arg,
123  void *data, uint16_t dataLen, int32_t crcStatus,
124  uint16_t remoteCoreId, uint16_t remoteEndPt);
125 
139 typedef void (*RPMessage_RecvNotifyCallback)(struct RPMessage_Object_s *obj, void *arg);
140 
141 
156 typedef void (*RPMessage_ControlEndPtCallback)(void *arg,
157  uint16_t remoteCoreId, uint16_t remoteEndPt, const char *remoteServiceName);
158 
168 typedef int32_t (*RPMessage_CrcHookFxn)(uint8_t *data, uint16_t dataLen, uint8_t crcSize, void *crc);
169 
170 /* structure to hold state of RPMessage end point */
171 typedef struct RPMessage_Object_s
172 {
173  uint16_t localEndPt; /* local end point number, MUST be < RPMESSAGE_MAX_LOCAL_ENDPT */
174  RPMessage_RecvCallback recvCallback; /* when not NULL, received messages are handled in callback that via RPMessage_recv */
175  void *recvCallbackArgs; /* arguments passed to the recvCallback callback */
176  uint32_t doRecvUnblock; /* flag to unblock RPMessage_recv, if its blocked for every waiting for messages and user wants to shutdown or exit */
177  RPMessage_Queue endPtQ; /* end point specific queue to hold received messages pending for processing at this end point */
178  SemaphoreP_Object newEndPtMsgSem; /* semaphore to indicate that there messages pending endPtQ */
179  RPMessage_RecvNotifyCallback recvNotifyCallback; /* when not NULL, this callback is whenever a message is received */
180  void *recvNotifyCallbackArgs; /* arguments passed to the recvNotifyCallback callback */
182 
196 typedef struct
197 {
198  uint16_t localEndPt;
204 
215 typedef struct
216 {
217  uintptr_t vringTxBaseAddr[CSL_CORE_ID_MAX];
218  uintptr_t vringRxBaseAddr[CSL_CORE_ID_MAX];
219  uint32_t vringSize;
220  uint16_t vringNumBuf;
221  uint16_t vringMsgSize;
222  const RPMessage_ResourceTable *linuxResourceTable;
227  uint16_t linuxCoreId;
228  uint8_t isCrcEnabled; /* CRC Enable/Disable flag */
229  RPMessage_CrcHookFxn crcHookFxn; /* Hook Function to be provided by application for CRC calculation */
231 
238 
245 
251 int32_t RPMessage_init(const RPMessage_Params *params);
252 
256 void RPMessage_deInit(void);
257 
271 int32_t RPMessage_waitForLinuxReady(uint32_t timeout);
272 
280  void *controlEndPtCallbackArgs);
281 
296 
303 
311 
322 
341 int32_t RPMessage_announce(uint16_t remoteProcId, uint16_t localEndPt, const char* name);
342 
366 int32_t RPMessage_send( void *data,
367  uint16_t dataLen,
368  uint16_t remoteCoreId,
369  uint16_t remoteEndPt,
370  uint16_t localEndPt,
371  uint32_t timeout
372  );
373 
394 int32_t RPMessage_recv(RPMessage_Object *obj, void* data, uint16_t *dataLen,
395  uint16_t *remoteCoreId, uint16_t *remoteEndPt, uint32_t timeout);
396 
397 
400 #ifdef __cplusplus
401 }
402 #endif
403 
404 #endif /* IPC_RPMSG_H_ */
405 
CSL_CORE_ID_MAX
#define CSL_CORE_ID_MAX
Definition: cslr_soc_defines.h:77
RPMessage_recv
int32_t RPMessage_recv(RPMessage_Object *obj, void *data, uint16_t *dataLen, uint16_t *remoteCoreId, uint16_t *remoteEndPt, uint32_t timeout)
Blocking API to wait till a message is received from any CPU at the specified local end point.
RPMessage_CrcHookFxn
int32_t(* RPMessage_CrcHookFxn)(uint8_t *data, uint16_t dataLen, uint8_t crcSize, void *crc)
This is the CRC Hook function to be defined in application for CRC Calculation.
Definition: ipc_rpmsg.h:168
RPMessage_ControlEndPtCallback
void(* RPMessage_ControlEndPtCallback)(void *arg, uint16_t remoteCoreId, uint16_t remoteEndPt, const char *remoteServiceName)
Callback that is invoked when a annoucement message is received on the control end point.
Definition: ipc_rpmsg.h:156
RPMessage_unblock
void RPMessage_unblock(RPMessage_Object *obj)
Unblocks RPMessage_recv, for the input object, if it is blocked waiting on messages and users want to...
RPMessage_Object
Definition: ipc_rpmsg.h:172
RPMessage_Params::vringSize
uint32_t vringSize
Definition: ipc_rpmsg.h:219
SystemP.h
RPMessage_CreateParams::localEndPt
uint16_t localEndPt
Definition: ipc_rpmsg.h:198
RPMessage_construct
int32_t RPMessage_construct(RPMessage_Object *obj, const RPMessage_CreateParams *createParams)
Create a RPMessage object to receive messages at a specified end-point.
RPMessage_waitForLinuxReady
int32_t RPMessage_waitForLinuxReady(uint32_t timeout)
Wait for linux side RPMessage to be ready.
RPMessage_CreateParams::recvNotifyCallback
RPMessage_RecvNotifyCallback recvNotifyCallback
Definition: ipc_rpmsg.h:201
RPMessage_Object::endPtQ
RPMessage_Queue endPtQ
Definition: ipc_rpmsg.h:177
RPMessage_Object::recvCallback
RPMessage_RecvCallback recvCallback
Definition: ipc_rpmsg.h:174
RPMessage_Params::vringMsgSize
uint16_t vringMsgSize
Definition: ipc_rpmsg.h:221
RPMessage_deInit
void RPMessage_deInit(void)
De-Initialize RPMessage module.
data
uint32_t data
Definition: tisci_rm_psil.h:1
SemaphoreP.h
RPMessage_init
int32_t RPMessage_init(const RPMessage_Params *params)
Initialize RPMessage module.
RPMessage_getLocalEndPt
uint16_t RPMessage_getLocalEndPt(const RPMessage_Object *obj)
Return local end point of a RPMessage_Object.
RPMessage_Params::linuxResourceTable
const RPMessage_ResourceTable * linuxResourceTable
Definition: ipc_rpmsg.h:222
RPMessage_CreateParams::recvCallback
RPMessage_RecvCallback recvCallback
Definition: ipc_rpmsg.h:199
RPMessage_Params_init
void RPMessage_Params_init(RPMessage_Params *params)
Set default values to RPMessage_Params.
RPMessage_announce
int32_t RPMessage_announce(uint16_t remoteProcId, uint16_t localEndPt, const char *name)
Announce a local end point at which a service is created to a remote core.
RPMessage_RecvNotifyCallback
void(* RPMessage_RecvNotifyCallback)(struct RPMessage_Object_s *obj, void *arg)
Callback that is invoked when a message is received from any CPU at the specified local end point.
Definition: ipc_rpmsg.h:139
RPMessage_CreateParams::recvCallbackArgs
void * recvCallbackArgs
Definition: ipc_rpmsg.h:200
RPMessage_Object::recvCallbackArgs
void * recvCallbackArgs
Definition: ipc_rpmsg.h:175
RPMessage_Params::linuxCoreId
uint16_t linuxCoreId
Definition: ipc_rpmsg.h:227
RPMessage_CreateParams_init
void RPMessage_CreateParams_init(RPMessage_CreateParams *params)
Set default values to RPMessage_CreateParams.
RPMessage_Params::isCrcEnabled
uint8_t isCrcEnabled
Definition: ipc_rpmsg.h:228
RPMessage_RecvCallback
void(* RPMessage_RecvCallback)(struct RPMessage_Object_s *obj, void *arg, void *data, uint16_t dataLen, int32_t crcStatus, uint16_t remoteCoreId, uint16_t remoteEndPt)
Callback that is invoked when a message is received from any CPU at the specified local end point.
Definition: ipc_rpmsg.h:122
RPMessage_Params::vringNumBuf
uint16_t vringNumBuf
Definition: ipc_rpmsg.h:220
RPMessage_Object::recvNotifyCallback
RPMessage_RecvNotifyCallback recvNotifyCallback
Definition: ipc_rpmsg.h:179
RPMessage_Object::doRecvUnblock
uint32_t doRecvUnblock
Definition: ipc_rpmsg.h:176
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
RPMessage_Params
Parameters passed to RPMessage_init, these are generated via SysCfg.
Definition: ipc_rpmsg.h:216
RPMessage_Object::localEndPt
uint16_t localEndPt
Definition: ipc_rpmsg.h:173
RPMessage_Object::newEndPtMsgSem
SemaphoreP_Object newEndPtMsgSem
Definition: ipc_rpmsg.h:178
RPMessage_Params::crcHookFxn
RPMessage_CrcHookFxn crcHookFxn
Definition: ipc_rpmsg.h:229
RPMessage_CreateParams
Parameters passed to RPMessage_construct.
Definition: ipc_rpmsg.h:197
RPMessage_CreateParams::recvNotifyCallbackArgs
void * recvNotifyCallbackArgs
Definition: ipc_rpmsg.h:202
RPMessage_controlEndPtCallback
void RPMessage_controlEndPtCallback(RPMessage_ControlEndPtCallback controlEndPtCallback, void *controlEndPtCallbackArgs)
Callback to call when a control message is received on a control end point.
RPMessage_send
int32_t RPMessage_send(void *data, uint16_t dataLen, uint16_t remoteCoreId, uint16_t remoteEndPt, uint16_t localEndPt, uint32_t timeout)
Send a message to a remote core at a specified remote end point.
RPMessage_Object::recvNotifyCallbackArgs
void * recvNotifyCallbackArgs
Definition: ipc_rpmsg.h:180
RPMessage_destruct
void RPMessage_destruct(RPMessage_Object *obj)
Delete a previously created RPMessage object.