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
@@ -140,6 +147,19 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
140147 uint32_t dst , const void * data , int len ,
141148 int wait );
142149
150+ /**
151+ * is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
152+ *
153+ * @ept: pointer to rpmsg endpoint
154+ *
155+ * Returns 1 if the rpmsg endpoint has both local addr and destination
156+ * addr set, 0 otherwise
157+ */
158+ static inline unsigned int is_rpmsg_ept_ready (struct rpmsg_endpoint * ept )
159+ {
160+ return ept && ept -> rdev && ept -> dest_addr != RPMSG_ADDR_ANY ;
161+ }
162+
143163/**
144164 * rpmsg_send() - send a message across to the remote processor
145165 * @ept: the rpmsg endpoint
@@ -158,8 +178,17 @@ int rpmsg_send_offchannel_raw(struct rpmsg_endpoint *ept, uint32_t src,
158178static inline int rpmsg_send (struct rpmsg_endpoint * ept , const void * data ,
159179 int len )
160180{
161- return rpmsg_send_offchannel_raw (ept , ept -> addr , ept -> dest_addr , data ,
162- len , true);
181+ int tc = 0 ;
182+
183+ for (; tc < RPMSG_TICK_COUNT ; tc += RPMSG_TICKS_PER_INTERVAL ) {
184+ if (is_rpmsg_ept_ready (ept ))
185+ return rpmsg_send_offchannel_raw (ept , ept -> addr ,
186+ ept -> dest_addr ,
187+ data , len , true);
188+ metal_sleep_usec (RPMSG_TICKS_PER_INTERVAL );
189+ }
190+
191+ return RPMSG_ERR_ADDR ;
163192}
164193
165194/**
@@ -432,8 +461,17 @@ static inline int rpmsg_sendto_nocopy(struct rpmsg_endpoint *ept,
432461static inline int rpmsg_send_nocopy (struct rpmsg_endpoint * ept ,
433462 const void * data , int len )
434463{
435- return rpmsg_send_offchannel_nocopy (ept , ept -> addr ,
436- ept -> dest_addr , data , len );
464+ int tc = 0 ;
465+
466+ for (; tc < RPMSG_TICK_COUNT ; tc += RPMSG_TICKS_PER_INTERVAL ) {
467+ if (is_rpmsg_ept_ready (ept ))
468+ return rpmsg_send_offchannel_nocopy (ept , ept -> addr ,
469+ ept -> dest_addr ,
470+ data , len );
471+ metal_sleep_usec (RPMSG_TICKS_PER_INTERVAL );
472+ }
473+
474+ return RPMSG_ERR_ADDR ;
437475}
438476
439477/**
@@ -506,19 +544,6 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
506544 */
507545void rpmsg_destroy_ept (struct rpmsg_endpoint * ept );
508546
509- /**
510- * is_rpmsg_ept_ready - check if the rpmsg endpoint ready to send
511- *
512- * @ept: pointer to rpmsg endpoint
513- *
514- * Returns 1 if the rpmsg endpoint has both local addr and destination
515- * addr set, 0 otherwise
516- */
517- static inline unsigned int is_rpmsg_ept_ready (struct rpmsg_endpoint * ept )
518- {
519- return ept && ept -> rdev && ept -> dest_addr != RPMSG_ADDR_ANY ;
520- }
521-
522547#if defined __cplusplus
523548 }
524549#endif
0 commit comments