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

The tone service. More...

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

Macros

#define U16_MAX   65535u

Functions

static uint16_t clip16 (uint64_t v)
 Clip a 64-bit count to 16 bits.
static uint16_t round16 (float v)
 A non-negative float rounded to the nearest integer, clipped to 16 bits.
void tone_svc_init (tone_svc_t *s)
 Clear the service state.
uint64_t tone_svc_ticks (uint64_t us)
 us microseconds after the capture started, in ticks.
void tone_svc_cfg (const tone_cmd_t *cmd, tone_cfg_t *c)
 The detector's configuration for an order: the defaults of tone.h at the capture's tick, with the order's range, split, gap and minimum.
void tone_svc_rec (const tone_beep_t *b, tone_rec_t *r)
 A detector beep in the page's units, ticks of TONE_SVC_TICK_HZ.
static bool restart (tone_svc_t *s, const tone_cmd_t *cmd)
 Restart under a new order: the detector, the hold-off horizon, the ring reader and the flags.
static void report (const tone_svc_t *s, tone_status_t *st)
 Fill the status for this pass.
size_t tone_svc_step (tone_svc_t *s, const tone_cmd_t *cmd, const uint32_t *ring, uint32_t wr, uint64_t now, bool fifo_overrun, tone_rec_t *rec, tone_status_t *st)
 One pass.

Detailed Description

The tone service.

See tone_svc.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ clip16()

uint16_t clip16 ( uint64_t v)
static

Clip a 64-bit count to 16 bits.

Parameters
vCount to clip.
Returns
v, or 65535 when it is larger.

◆ report()

void report ( const tone_svc_t * s,
tone_status_t * st )
static

Fill the status for this pass.

Parameters
sService state.
stReceives the status; cleared first.

◆ restart()

bool restart ( tone_svc_t * s,
const tone_cmd_t * cmd )
static

Restart under a new order: the detector, the hold-off horizon, the ring reader and the flags.

False when the order's settings are refused.

Parameters
sService state.
cmdOrder from core 0.
Returns
false when the order's settings are refused.

◆ round16()

uint16_t round16 ( float v)
static

A non-negative float rounded to the nearest integer, clipped to 16 bits.

Parameters
vValue to round.
Returns
The rounded value, 0 for a value not above zero, 65535 at most.

◆ tone_svc_cfg()

void tone_svc_cfg ( const tone_cmd_t * cmd,
tone_cfg_t * c )

The detector's configuration for an order: the defaults of tone.h at the capture's tick, with the order's range, split, gap and minimum.

Parameters
cmdOrder from core 0.
cReceives the detector settings.

◆ tone_svc_init()

void tone_svc_init ( tone_svc_t * s)

Clear the service state.

Parameters
sService state; cleared to zero.

◆ tone_svc_rec()

void tone_svc_rec ( const tone_beep_t * b,
tone_rec_t * r )

A detector beep in the page's units, ticks of TONE_SVC_TICK_HZ.

Parameters
bBeep from the detector.
rReceives the beep in the page's units.

◆ tone_svc_step()

size_t tone_svc_step ( tone_svc_t * s,
const tone_cmd_t * cmd,
const uint32_t * ring,
uint32_t wr,
uint64_t now,
bool fifo_overrun,
tone_rec_t * rec,
tone_status_t * st )

One pass.

ring is the capture ring (TONE_RING_WORDS words), wr the slot the DMA writes next, now the present in ticks since the capture started, fifo_overrun true when the state machine dropped a word (its FIFO was full): the words read in that pass and in the next are discarded, the beep under way ends and the status shows the overrun. The caller reads the flag before wr, so the next pass's boundary lies after the flag was cleared; words the FIFO still held at the drop reach the ring before that boundary unless the DMA stalls for a whole pass, 1ms, and a stall that long overflows the FIFO again. The beeps finished go to rec, at most TONE_SVC_BEEPS; the count is returned. st is always written.

Parameters
sService state.
cmdOrder from core 0.
ringCapture ring, TONE_RING_WORDS words.
wrSlot the DMA writes next.
nowPresent, in ticks since the capture started.
fifo_overruntrue when the state machine dropped a word.
recReceives the finished beeps; NULL to take none.
stReceives the status; always written.
Returns
Number of beeps written to rec.

◆ tone_svc_ticks()

uint64_t tone_svc_ticks ( uint64_t us)

us microseconds after the capture started, in ticks.

Parameters
usTime, microseconds.
Returns
Ticks of the capture's clock.