The tap's edge words and their ring.
More...
#include "edge_ring.h"
#include <string.h>
|
|
#define | HALF (1u << (EDGE_COUNT_BITS - 1u)) |
| | Half the counter range: the limit of a wrap-safe distance.
|
|
| 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()).
|
The tap's edge words and their ring.
See edge_ring.h.
SPDX-License-Identifier: MIT
◆ edge_ring_init()
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
-
| r | Reader 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
-
| r | Reader state. |
| ring | Ring of edge words. |
| size | Ring size in words, a power of two. |
| wr | Slot the DMA writes next. |
| est | Estimate of the present tick. |
| out | Receives the edges. |
| max | Most edges taken in this call. |
| overrun | Set 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
-
| count | Counter value of the edge, 31 bits. |
| est | Estimate 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
-
| count | Counter value at the edge; the low 31 bits are used. |
| level | Level 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
-
- 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
-
- Returns
- true for a rise.