APM:Libraries
Classes | Typedefs | Functions
ring_buffer_pulse.h File Reference

Simple circular buffer for PEM input. More...

#include "hal_types.h"
#include "pwm_in.h"
Include dependency graph for ring_buffer_pulse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Pulse_buffer
 

Typedefs

typedef struct Pulse_buffer pulse_buffer
 

Functions

static void pb_init (volatile pulse_buffer *pb, uint16_t size, Pulse *buf)
 
static uint16_t pb_full_count (volatile pulse_buffer *pb)
 Return the number of elements stored in the ring buffer. More...
 
static int pb_is_full (volatile pulse_buffer *pb)
 Returns true if and only if the ring buffer is full. More...
 
static int pb_is_empty (volatile pulse_buffer *pb)
 Returns true if and only if the ring buffer is empty. More...
 
static void pb_insert (volatile pulse_buffer *pb, Pulse element)
 
static Pulse pb_remove (volatile pulse_buffer *pb)
 Remove and return the first item from a ring buffer. More...
 
static int pb_safe_insert (volatile pulse_buffer *pb, Pulse element)
 Attempt to insert an element into a ring buffer. More...
 
static void pb_reset (volatile pulse_buffer *pb)
 Discard all items from a ring buffer. More...
 

Detailed Description

Simple circular buffer for PEM input.

(c) 2017 night.nosp@m._gho.nosp@m.st@yk.nosp@m.octp.nosp@m.a.ru

based on: ring_buffer.h

This implementation is not thread-safe. In particular, none of these functions is guaranteed re-entrant.

Definition in file ring_buffer_pulse.h.

Typedef Documentation

◆ pulse_buffer

typedef struct Pulse_buffer pulse_buffer

Ring buffer type.

The buffer is empty when head == tail.

The buffer is full when the head is one byte in front of the tail, modulo buffer length.

One element is left free to distinguish empty from full.

Function Documentation

◆ pb_full_count()

static uint16_t pb_full_count ( volatile pulse_buffer pb)
inlinestatic

Return the number of elements stored in the ring buffer.

Parameters
pbBuffer whose elements to count.

Definition at line 66 of file ring_buffer_pulse.h.

Referenced by getPPM_count().

Here is the caller graph for this function:

◆ pb_init()

static void pb_init ( volatile pulse_buffer pb,
uint16_t  size,
Pulse buf 
)
inlinestatic

Initialise a ring buffer.

Parameters
pbInstance to initialise
sizeNumber of items in buf. The ring buffer will always leave one element unoccupied, so the maximum number of elements it can store will be size - 1. Thus, size must be at least 2.
bufBuffer to store items into

Definition at line 55 of file ring_buffer_pulse.h.

Referenced by pwmInit().

Here is the caller graph for this function:

◆ pb_insert()

static void pb_insert ( volatile pulse_buffer pb,
Pulse  element 
)
inlinestatic

Append element onto the end of a ring buffer.

Parameters
pbBuffer to append onto.
elementValue to append.

Definition at line 100 of file ring_buffer_pulse.h.

Referenced by pb_safe_insert(), and pwmIRQHandler().

Here is the caller graph for this function:

◆ pb_is_empty()

static int pb_is_empty ( volatile pulse_buffer pb)
inlinestatic

Returns true if and only if the ring buffer is empty.

Parameters
pbBuffer to test.

Definition at line 90 of file ring_buffer_pulse.h.

Referenced by getPPM_Pulse().

Here is the caller graph for this function:

◆ pb_is_full()

static int pb_is_full ( volatile pulse_buffer pb)
inlinestatic

Returns true if and only if the ring buffer is full.

Parameters
pbBuffer to test.

Definition at line 80 of file ring_buffer_pulse.h.

Referenced by pb_safe_insert(), and pwmIRQHandler().

Here is the caller graph for this function:

◆ pb_remove()

static Pulse pb_remove ( volatile pulse_buffer pb)
inlinestatic

Remove and return the first item from a ring buffer.

Parameters
pbBuffer to remove from, must contain at least one element.

Definition at line 110 of file ring_buffer_pulse.h.

Referenced by getPPM_Pulse().

Here is the caller graph for this function:

◆ pb_reset()

static void pb_reset ( volatile pulse_buffer pb)
inlinestatic

Discard all items from a ring buffer.

Parameters
pbRing buffer to discard all items from.

Definition at line 137 of file ring_buffer_pulse.h.

◆ pb_safe_insert()

static int pb_safe_insert ( volatile pulse_buffer pb,
Pulse  element 
)
inlinestatic

Attempt to insert an element into a ring buffer.

Parameters
pbBuffer to insert into.
elementValue to insert into pb. If pb is not full, appends element onto buffer.
Returns
If element was appended, then 1; otherwise, 0.

Definition at line 124 of file ring_buffer_pulse.h.

Here is the call graph for this function: