STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
virtio_buffer.h File Reference

Ring buffer used to store the data received through OpenAMP. More...

#include <stdint.h>

Classes

struct  virtio_buffer_t
 Ring buffer of bytes, filled by the rx callback and consumed by the application. More...
 

Macros

#define VIRTIO_BUFFER_SIZE   (RPMSG_VRING_TOTAL_PAYLOAD_SIZE * 1 + 1)
 Size of virtio ring buffer.
 

Functions

void virtio_buffer_init (virtio_buffer_t *ring)
 Initialize a virtio ring buffer to empty.
 
uint16_t virtio_buffer_read_available (virtio_buffer_t *ring)
 Get the number of bytes available to read.
 
uint16_t virtio_buffer_read (virtio_buffer_t *ring, uint8_t *dst, uint16_t size)
 Read and remove bytes from the ring buffer.
 
uint16_t virtio_buffer_peek (virtio_buffer_t *ring, uint8_t *dst, uint16_t size)
 Copy bytes from the ring buffer without removing them.
 
uint16_t virtio_buffer_write_available (virtio_buffer_t *ring)
 Get the number of bytes that can be written.
 
uint16_t virtio_buffer_write (virtio_buffer_t *ring, uint8_t *src, uint16_t size)
 Write bytes into the ring buffer.
 

Detailed Description

Ring buffer used to store the data received through OpenAMP.

Macro Definition Documentation

◆ VIRTIO_BUFFER_SIZE

#define VIRTIO_BUFFER_SIZE   (RPMSG_VRING_TOTAL_PAYLOAD_SIZE * 1 + 1)

Size of virtio ring buffer.

Note
See virtio_config.h for the size decision. (7937 bytes by default) The multiplier should be at least 1. As a result, the minimum required size of the initial virtio_buffer_write_available() must be RPMSG_VRING_TOTAL_PAYLOAD_SIZE.
If VIRTIO_BUFFER_SIZE is still too big, RPMSG_VRING_TOTAL_PAYLOAD_SIZE can be reduced by reducing the number of VRING_NUM_BUFFS in virtio_config.h.

Function Documentation

◆ virtio_buffer_init()

void virtio_buffer_init ( virtio_buffer_t *  ring)

Initialize a virtio ring buffer to empty.

Parameters
ringPointer to the ring buffer to initialize.

◆ virtio_buffer_peek()

uint16_t virtio_buffer_peek ( virtio_buffer_t *  ring,
uint8_t *  dst,
uint16_t  size 
)

Copy bytes from the ring buffer without removing them.

Parameters
ringPointer to the ring buffer.
dstDestination buffer.
sizeMaximum number of bytes to copy.
Returns
Number of bytes actually copied, at most size.
Note
Not protected against race conditions on read_index. Do not use concurrently from an interrupt and the main loop.

◆ virtio_buffer_read()

uint16_t virtio_buffer_read ( virtio_buffer_t *  ring,
uint8_t *  dst,
uint16_t  size 
)

Read and remove bytes from the ring buffer.

Parameters
ringPointer to the ring buffer.
dstDestination buffer.
sizeMaximum number of bytes to read.
Returns
Number of bytes actually read, at most size.
Note
Not protected against race conditions on read_index. Do not use concurrently from an interrupt and the main loop.

◆ virtio_buffer_read_available()

uint16_t virtio_buffer_read_available ( virtio_buffer_t *  ring)

Get the number of bytes available to read.

Parameters
ringPointer to the ring buffer.
Returns
Number of bytes that virtio_buffer_read() can return.

◆ virtio_buffer_write()

uint16_t virtio_buffer_write ( virtio_buffer_t *  ring,
uint8_t *  src,
uint16_t  size 
)

Write bytes into the ring buffer.

Parameters
ringPointer to the ring buffer.
srcSource data.
sizeMaximum number of bytes to write.
Returns
Number of bytes actually written, at most size.
Note
Not protected against race conditions on write_index. Do not use concurrently from an interrupt and the main loop.

◆ virtio_buffer_write_available()

uint16_t virtio_buffer_write_available ( virtio_buffer_t *  ring)

Get the number of bytes that can be written.

Parameters
ringPointer to the ring buffer.
Returns
Number of free bytes. One byte is always kept unused to tell a full buffer from an empty one.