Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
circular_buffer.h File Reference
#include <stdint.h>
#include <stddef.h>
+ Include dependency graph for circular_buffer.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  circular_buffer
 This is a general purpose circular buffer for storing buffers in a FIFO order. More...
 

Enumerations

enum  cir_error { CIR_ERROR_NO_MSG = -1 , CIR_ERROR_BUFFER_TOO_SMALL = -2 , CIR_ERROR_NO_SPACE_AVAILABLE = -3 }
 

Functions

void circular_buffer_init (struct circular_buffer *cb, uint8_t *buffer, size_t len)
 initialize a circular buffer. More...
 
int circular_buffer_get (struct circular_buffer *cb, uint8_t *buf, size_t len)
 copy the next buffer available in cb to buf. More...
 
int circular_buffer_put (struct circular_buffer *cb, uint8_t *buf, size_t len)
 Copy buf in the circular buffer. More...
 

Data Structure Documentation

◆ circular_buffer

struct circular_buffer

This is a general purpose circular buffer for storing buffers in a FIFO order.

A current limitation: the size of the buffers is limited to 255, is size beeing stored on a uint8_t.

Declare a circular_buffer and allocate a buffer that will outlive it. Initialize the circular_buffer using circular_buffer_init.

Definition at line 23 of file circular_buffer.h.

Data Fields
uint8_t * _buf
size_t _buf_len
size_t read_offset
size_t write_offset

Enumeration Type Documentation

◆ cir_error

enum cir_error
Enumerator
CIR_ERROR_NO_MSG 

circular buffer is empty

CIR_ERROR_BUFFER_TOO_SMALL 

destination buffer is too small

CIR_ERROR_NO_SPACE_AVAILABLE 

no space available in the circular buffer

Definition at line 30 of file circular_buffer.h.

Function Documentation

◆ circular_buffer_get()

int circular_buffer_get ( struct circular_buffer cb,
uint8_t buf,
size_t  len 
)

copy the next buffer available in cb to buf.

Parameters
cbThe circular buffer
bufdestination buffer
lensize of buf
Returns
Size of the data copied to buf, or an error code if negative.

Definition at line 22 of file circular_buffer.c.

References circular_buffer::_buf, circular_buffer::_buf_len, CIR_ERROR_BUFFER_TOO_SMALL, CIR_ERROR_NO_MSG, circular_buffer::read_offset, and circular_buffer::write_offset.

Referenced by sts3032_event().

+ Here is the caller graph for this function:

◆ circular_buffer_init()

void circular_buffer_init ( struct circular_buffer cb,
uint8_t buffer,
size_t  len 
)

initialize a circular buffer.

Parameters
cbcircular_buffer structure
bufferbuffer used internally by the circular buffer
lensize of buffer

Definition at line 13 of file circular_buffer.c.

References circular_buffer::_buf, circular_buffer::_buf_len, circular_buffer::read_offset, and circular_buffer::write_offset.

Referenced by actuators_sts3032_init().

+ Here is the caller graph for this function:

◆ circular_buffer_put()

int circular_buffer_put ( struct circular_buffer cb,
uint8_t buf,
size_t  len 
)

Copy buf in the circular buffer.

Parameters
cbThe circular buffer
bufsource buffer
lenSize of buf
Returns
0 on success, Error code if negative

len == available is invalid because it will cause write_offset to ne equal to read_offset, which is considered an empty buffer.

Definition at line 51 of file circular_buffer.c.

References circular_buffer::_buf, circular_buffer::_buf_len, CIR_ERROR_NO_SPACE_AVAILABLE, circular_buffer::read_offset, and circular_buffer::write_offset.

Referenced by write_buf().

+ Here is the caller graph for this function: