Skip to content

Commit 4be970c

Browse files
committed
Add RPMSG_VRING_TOTAL_PAYLOAD_SIZE to decide buffer free
1 parent dca8824 commit 4be970c

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

cores/arduino/VirtIOSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ size_t VirtIOSerial::readBytes(char *buffer, size_t length)
122122
uint16_t prev_write_available = virtio_buffer_write_available(&_VirtIOSerialObj.ring);
123123
const size_t size = virtio_buffer_read(&_VirtIOSerialObj.ring, reinterpret_cast<uint8_t *>(buffer), length);
124124

125-
if (prev_write_available < RPMSG_VRING_PAYLOAD_SIZE
126-
&& virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_VRING_PAYLOAD_SIZE) {
125+
if (prev_write_available < RPMSG_VRING_TOTAL_PAYLOAD_SIZE
126+
&& virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_VRING_TOTAL_PAYLOAD_SIZE) {
127127
MAILBOX_Notify_Rx_Buf_Free();
128128
}
129129

@@ -180,7 +180,7 @@ void VirtIOSerial::rxCallback(VIRT_UART_HandleTypeDef *huart)
180180
while (size > 0) {
181181
size -= virtio_buffer_write(&_VirtIOSerialObj.ring, huart->pRxBuffPtr, size);
182182
}
183-
if (virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_VRING_PAYLOAD_SIZE) {
183+
if (virtio_buffer_write_available(&_VirtIOSerialObj.ring) >= RPMSG_VRING_TOTAL_PAYLOAD_SIZE) {
184184
MAILBOX_Notify_Rx_Buf_Free();
185185
}
186186
}

cores/arduino/stm32/OpenAMP/openamp_conf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#ifdef VIRTIOCON
2525

26+
/**
27+
* Note: Do not remove this. Removing this might not trigger compile error but
28+
* the configuration can be significantly different.
29+
*/
2630
#include "virtio_config.h"
2731

2832
#ifdef __cplusplus
@@ -121,7 +125,9 @@ extern int __OPENAMP_region_end__[]; /* defined by linker script */
121125
#define VRING_TX_ADDRESS -1 /* allocated by Master processor: CA7 */
122126
#define VRING_BUFF_ADDRESS -1 /* allocated by Master processor: CA7 */
123127
#define VRING_ALIGNMENT 16 /* fixed to match with linux constraint */
128+
#ifndef VRING_NUM_BUFFS
124129
#define VRING_NUM_BUFFS 16 /* number of rpmsg buffer */
130+
#endif
125131
#else
126132
#error "VRING configuration for the device missing"
127133
#endif

cores/arduino/stm32/OpenAMP/virtio_buffer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
extern "C" {
3131
#endif
3232

33-
#define VIRTIO_BUFFER_SIZE (RPMSG_VRING_PAYLOAD_SIZE * 2)
33+
/**
34+
* See virtio_config.h for the size decision.
35+
* The multiplier should be at least 1.
36+
* If VIRTIO_BUFFER_SIZE is still too big, RPMSG_VRING_TOTAL_PAYLOAD_SIZE
37+
* can be reduced by reducing the number of VRING_NUM_BUFFS in virtio_config.h.
38+
*/
39+
#define VIRTIO_BUFFER_SIZE (RPMSG_VRING_TOTAL_PAYLOAD_SIZE * 2)
3440

3541
typedef struct {
3642
uint8_t buffer[VIRTIO_BUFFER_SIZE];

cores/arduino/stm32/OpenAMP/virtio_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
#define RPMSG_VRING_HEADER_SIZE (16)
1414
#define RPMSG_VRING_PAYLOAD_SIZE (RPMSG_BUFFER_SIZE - RPMSG_VRING_HEADER_SIZE)
1515

16+
/**
17+
* number of rpmsg buffer
18+
* This means that a single call of rproc_virtio_notified(rvdev.vdev, VRING1_ID)
19+
* will trigger VirtIOSerial::rxCallback() VRING_NUM_BUFFS times at maximum.
20+
* A buffer handles VirtIOSerial::rxCallback() requires to be
21+
* (RPMSG_VRING_PAYLOAD_SIZE * VRING_NUM_BUFFS) at minimum to prevent overflow.
22+
*/
23+
#define VRING_NUM_BUFFS 16
24+
#define RPMSG_VRING_TOTAL_PAYLOAD_SIZE (RPMSG_VRING_PAYLOAD_SIZE * VRING_NUM_BUFFS)
25+
1626
#if defined (__LOG_TRACE_IO_)
1727
// OpenAMP trace (log) buffer configuration. See rsc_table.c and Print.cpp
1828
#define SYSTEM_TRACE_BUF_SZ 2048

0 commit comments

Comments
 (0)