Skip to content

Commit fdda485

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
rpmsg: wait ept ready in rpmsg_send
since the destination address need time to return from peer Signed-off-by: ligd <liguiding@pinecone.net>
1 parent b1af124 commit fdda485

2 files changed

Lines changed: 32 additions & 23 deletions

File tree

lib/include/openamp/rpmsg.h

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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,
147168
static 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
*/
329359
void 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

lib/rpmsg/rpmsg_virtio.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
#include <metal/alloc.h>
11-
#include <metal/sleep.h>
1211
#include <metal/utilities.h>
1312
#include <openamp/rpmsg_virtio.h>
1413
#include <openamp/virtqueue.h>
@@ -17,12 +16,6 @@
1716

1817
#define RPMSG_NUM_VRINGS 2
1918

20-
/* Total tick count for 15secs - 1usec tick. */
21-
#define RPMSG_TICK_COUNT 15000000
22-
23-
/* Time to wait - In multiple of 1 msecs. */
24-
#define RPMSG_TICKS_PER_INTERVAL 1000
25-
2619
#ifndef VIRTIO_SLAVE_ONLY
2720
metal_weak void *
2821
rpmsg_virtio_shm_pool_get_buffer(struct rpmsg_virtio_shm_pool *shpool,

0 commit comments

Comments
 (0)