rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
edge_ring.c File Reference

The tap's edge words and their ring. More...

#include "edge_ring.h"
#include <string.h>

Macros

#define HALF   (1u << (EDGE_COUNT_BITS - 1u))
 Half the counter range: the limit of a wrap-safe distance.

Functions

uint32_t edge_word (uint32_t count, bool level)
 The word the program pushes for an edge at counter value count.
uint32_t edge_word_count (uint32_t word)
 A word's 31-bit count and level.
bool edge_word_level (uint32_t word)
 The word's level after the edge.
uint64_t edge_tick (uint32_t count, uint64_t est)
 The tick of the counter value count nearest est, with a counter that started at 0 and counts down.
void edge_ring_init (edge_ring_t *r)
 Start reading a ring from slot 0, as after the DMA channel restarts.
size_t edge_ring_take (edge_ring_t *r, const uint32_t *ring, uint32_t size, uint32_t wr, uint64_t est, tone_edge_t *out, size_t max, bool *overrun)
 Take the words in ring ( size words, a power of two) written since the last call, wr being the slot the DMA writes next, as edges stamped against est (the present tick, edge_tick()).

Detailed Description

The tap's edge words and their ring.

See edge_ring.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ edge_ring_init()

void edge_ring_init ( edge_ring_t * r)

Start reading a ring from slot 0, as after the DMA channel restarts.

The ring holds only zero words at that moment, so a lap before the first read shows as a word in its last slot.

Parameters
rReader state to initialise.

◆ edge_ring_take()

size_t edge_ring_take ( edge_ring_t * r,
const uint32_t * ring,
uint32_t size,
uint32_t wr,
uint64_t est,
tone_edge_t * out,
size_t max,
bool * overrun )

Take the words in ring ( size words, a power of two) written since the last call, wr being the slot the DMA writes next, as edges stamped against est (the present tick, edge_tick()).

At most max edges go to out; words past that stay in the ring for the next call.

Returns the edges written. *overrun is set when the DMA lapped the reader: nothing is returned, the reader is moved after the newest word, and the caller ends the beep under way (tone_flush()).

Parameters
rReader state.
ringRing of edge words.
sizeRing size in words, a power of two.
wrSlot the DMA writes next.
estEstimate of the present tick.
outReceives the edges.
maxMost edges taken in this call.
overrunSet to true when the DMA lapped the reader; may be NULL.
Returns
Number of edges written to out.

◆ edge_tick()

uint64_t edge_tick ( uint32_t count,
uint64_t est )

The tick of the counter value count nearest est, with a counter that started at 0 and counts down.

Ticks before the start do not exist: the result is at least 0.

Parameters
countCounter value of the edge, 31 bits.
estEstimate of the present tick.
Returns
The 64-bit tick of the edge.

◆ edge_word()

uint32_t edge_word ( uint32_t count,
bool level )

The word the program pushes for an edge at counter value count.

Parameters
countCounter value at the edge; the low 31 bits are used.
levelLevel after the edge: true for a rise.
Returns
The edge word.

◆ edge_word_count()

uint32_t edge_word_count ( uint32_t word)

A word's 31-bit count and level.

Parameters
wordEdge word.
Returns
The count, 0 to 2^31 - 1.

◆ edge_word_level()

bool edge_word_level ( uint32_t word)

The word's level after the edge.

Parameters
wordEdge word.
Returns
true for a rise.