1515#include <metal/compiler.h>
1616#include <metal/mutex.h>
1717#include <metal/list.h>
18+ #include <metal/sleep.h>
1819#include <metal/utilities.h>
1920#include <string.h>
2021#include <stdbool.h>
@@ -32,6 +33,12 @@ extern "C" {
3233#define RPMSG_RESERVED_ADDRESSES (1024)
3334#define RPMSG_ADDR_ANY 0xFFFFFFFF
3435
36+ /* Total tick count for 15secs - 1usec tick. */
37+ #define RPMSG_TICK_COUNT 15000000
38+
39+ /* Time to wait - In multiple of 1 msecs. */
40+ #define RPMSG_TICKS_PER_INTERVAL 1000
41+
3542/* Error macros. */
3643#define RPMSG_SUCCESS 0
3744#define RPMSG_ERROR_BASE -2000
@@ -129,6 +136,20 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
129136 uint32_t dst , const void * data , int size ,
130137 int wait );
131138
139+ /**
140+ * is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
141+ *
142+ * @ept: pointer to rpmsg endpoint
143+ *
144+ * Returns 1 if the rpmsg endpoint has both local addr and destination
145+ * addr set, 0 otherwise
146+ */
147+ static inline unsigned int is_rpmsg_ept_ready (struct rpmsg_endpoint * ept )
148+ {
149+ return (ept -> dest_addr != RPMSG_ADDR_ANY ) &&
150+ (ept -> addr != RPMSG_ADDR_ANY );
151+ }
152+
132153/**
133154 * rpmsg_send() - send a message across to the remote processor
134155 * @ept: the rpmsg endpoint
@@ -147,8 +168,17 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
147168static inline int rpmsg_send (struct rpmsg_endpoint * ept , const void * data ,
148169 int len )
149170{
150- return rpmsg_send_offchannel_raw (ept , ept -> addr , ept -> dest_addr , data ,
151- len , true);
171+ int tc = 0 ;
172+
173+ for (; tc < RPMSG_TICK_COUNT ; tc += RPMSG_TICKS_PER_INTERVAL ) {
174+ if (is_rpmsg_ept_ready (ept ))
175+ return rpmsg_send_offchannel_raw (ept , ept -> addr ,
176+ ept -> dest_addr ,
177+ data , len , true);
178+ metal_sleep_usec (RPMSG_TICKS_PER_INTERVAL );
179+ }
180+
181+ return RPMSG_ERR_ADDR ;
152182}
153183
154184/**
@@ -328,20 +358,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
328358 */
329359void rpmsg_destroy_ept (struct rpmsg_endpoint * ept );
330360
331- /**
332- * is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
333- *
334- * @ept: pointer to rpmsg endpoint
335- *
336- * Returns 1 if the rpmsg endpoint has both local addr and destination
337- * addr set, 0 otherwise
338- */
339- static inline unsigned int is_rpmsg_ept_ready (struct rpmsg_endpoint * ept )
340- {
341- return (ept -> dest_addr != RPMSG_ADDR_ANY ) &&
342- (ept -> addr != RPMSG_ADDR_ANY );
343- }
344-
345361#if defined __cplusplus
346362 }
347363#endif
0 commit comments