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

The panel's half of the SUPPLY link page. More...

#include "supply_link.h"
#include <stddef.h>
#include <string.h>

Macros

#define PAGE_MIN_MV   1000u
#define PAGE_MAX_MV   20000u
#define PAGE_MIN_MA   50u
#define PAGE_MAX_MA   3000u

Functions

void supply_link_init (supply_link_t *s)
 Sets up the supply link state.
void supply_link_lost (supply_link_t *s)
 The link went or came back: nothing on the page is known, and the panel's ON, if it had one, is over.
static supply_wiring_t as_written (const supply_wiring_t *w)
 The wiring as the page is to hold it: disabled unless both pins are set and differ, with unset pins written as 0.
static bool same_wiring (const supply_wiring_t *a, const supply_wiring_t *b)
 Whether two wirings are the same, field by field.
void supply_link_wire (supply_link_t *s, const supply_wiring_t *w)
 The wiring the settings name now.
void supply_link_command (supply_link_t *s, bool on, uint16_t mv, uint16_t ma)
 What the output is to be; set points clamped to the page's 1000 to 20000mV and 50 to 3000mA.
void supply_link_reset (supply_link_t *s)
 Restart the PD mini (protocol 4.4): written once the page's output is off and its wiring written, after any OFF owed.
supply_link_write_t supply_link_next (supply_link_t *s, uint8_t *off, uint8_t *n, uint16_t *regs)
 The next write owed, or SUPPLY_LINK_W_NONE.
void supply_link_written (supply_link_t *s, int result)
 How the write supply_link_next() gave went: SUPPLY_LINK_ACK, a NACK reason, or SUPPLY_LINK_NO_ANSWER.
bool supply_link_settled (const supply_link_t *s)
 Whether nothing is owed: the page holds the command asked and the wiring, or the wiring was refused.
bool supply_link_event_stands (const supply_link_t *s, uint16_t ev)
 Whether what ev, one SUPPLY_LINK_EV_* bit, says still holds now.
bool supply_link_read_due (const supply_link_t *s, uint32_t now_ms)
 Whether a read of the page is due at now_ms.
void supply_link_read (supply_link_t *s, const uint16_t *regs, uint32_t now_ms)
 The whole page as read at now_ms, or regs NULL for a read that was not answered.
void supply_link_state (const supply_link_t *s, uint32_t now_ms, supply_state_t *st)
 The supply as the page last said, into st: readings, set points read back from the module, the mode – OFF while the module reads its output off – the module's reading count (SAMPLES, the IOmcu's count of output readings the module answered) and the time of the page read that first showed that count, and online only for a page read younger than SUPPLY_LINK_STALE_MS from a module the page drives.
bool supply_link_blind (const supply_link_t *s, uint32_t now_ms)
 Whether the module's readings have stopped at now_ms: a page has been read and its reading count (SAMPLES) has not moved for SUPPLY_LINK_BLIND_MS or more, counted on the 32-bit millisecond clock across its wrap.
bool supply_link_adopted (supply_link_t *s, bool *on, uint16_t *mv, uint16_t *ma)
 The command a programming port left on the page, once: true with on, mv and ma filled when the page's command was taken as the one asked since the last call.
uint16_t supply_link_events (supply_link_t *s)
 The events since the last call, SUPPLY_LINK_EV_*, and cleared.
void supply_link_sag (const supply_link_t *s, uint16_t *vin_mv, uint16_t *set_mv)
 The input and the set point in mV that SUPPLY_LINK_EV_SAGGED was read with: the page's VIN_MV and SET_MV_RB on the read that first showed FLAGS bit 10.
bool supply_link_wiring_moved (supply_link_follow_t *f, unsigned edits, unsigned word)
 Whether the PD mini's wiring has moved since it was last followed.
bool supply_link_held_pins (const supply_link_t *s, int *tx, int *rx)
 The PD mini's pins the page holds by its last read, as the IOmcu reserves them (supply_page_pins()): TX and RX while ENABLE is on, -1 and -1 while it is off.
bool supply_link_port_held (const supply_link_t *s)
 Whether the last read of the page had LINK_SP_PORT set: a programming port holds the supply, and the page takes an OFF of the panel's and no other change of OUTPUT, SET_MV or SET_MA.

Detailed Description

The panel's half of the SUPPLY link page.

See supply_link.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ as_written()

supply_wiring_t as_written ( const supply_wiring_t * w)
static

The wiring as the page is to hold it: disabled unless both pins are set and differ, with unset pins written as 0.

Parameters
wThe wiring the settings name.
Returns
The wiring the page holds.

◆ same_wiring()

bool same_wiring ( const supply_wiring_t * a,
const supply_wiring_t * b )
static

Whether two wirings are the same, field by field.

Parameters
aThe first wiring.
bThe second wiring.
Returns
true when they are equal.

◆ supply_link_adopted()

bool supply_link_adopted ( supply_link_t * s,
bool * on,
uint16_t * mv,
uint16_t * ma )

The command a programming port left on the page, once: true with on, mv and ma filled when the page's command was taken as the one asked since the last call.

The caller's own copy of the command follows it; a copy left as it was is written again at the caller's next supply_link_command().

Parameters
sThe link state.
onReceives the output state the page holds.
mvReceives the set point voltage, in mV.
maReceives the set point current, in mA.
Returns
true when the page took the command asked since the last call.

◆ supply_link_blind()

bool supply_link_blind ( const supply_link_t * s,
uint32_t now_ms )

Whether the module's readings have stopped at now_ms: a page has been read and its reading count (SAMPLES) has not moved for SUPPLY_LINK_BLIND_MS or more, counted on the 32-bit millisecond clock across its wrap.

The page may still answer and the module read ONLINE: a display read that fails while the other reads answer. No operator trip acts on such readings, so the caller switches an output that is on off and says why. False before the first page read.

Parameters
sThe link state.
now_msThe time, in ms.
Returns
true when the page has been read and the last read is at least SUPPLY_LINK_BLIND_MS old.

◆ supply_link_command()

void supply_link_command ( supply_link_t * s,
bool on,
uint16_t mv,
uint16_t ma )

What the output is to be; set points clamped to the page's 1000 to 20000mV and 50 to 3000mA.

Parameters
sThe link state.
ontrue to switch the output on.
mvThe set point voltage, in mV.
maThe set point current, in mA.

◆ supply_link_event_stands()

bool supply_link_event_stands ( const supply_link_t * s,
uint16_t ev )

Whether what ev, one SUPPLY_LINK_EV_* bit, says still holds now.

A refused wiring – SUPPLY_LINK_EV_WIRING_REFUSED or _WIRING_LIVE – until a read shows the page holding the wiring the settings ask: pins stepped back to ones the page takes end it with the first read that shows them held. With no IOmcu answering it stands. True for every other event. The caller takes back an alert it showed for a refused wiring once this is false.

Parameters
sThe link state.
evOne SUPPLY_LINK_EV_* bit.
Returns
true while the cause of the event holds.

◆ supply_link_events()

uint16_t supply_link_events ( supply_link_t * s)

The events since the last call, SUPPLY_LINK_EV_*, and cleared.

Parameters
sThe link state.
Returns
The events since the last call, as SUPPLY_LINK_EV_* bits.

◆ supply_link_held_pins()

bool supply_link_held_pins ( const supply_link_t * s,
int * tx,
int * rx )

The PD mini's pins the page holds by its last read, as the IOmcu reserves them (supply_page_pins()): TX and RX while ENABLE is on, -1 and -1 while it is off.

False, both -1, before the first read since the link came up; a refused wiring leaves the page's old one, and that is what is read. tx and rx may be NULL.

Parameters
sThe link state.
txReceives the TX pin, or -1; may be NULL.
rxReceives the RX pin, or -1; may be NULL.
Returns
false before the first read since the link came up.

◆ supply_link_init()

void supply_link_init ( supply_link_t * s)

Sets up the supply link state.

Parameters
sThe link state to set up.

◆ supply_link_lost()

void supply_link_lost ( supply_link_t * s)

The link went or came back: nothing on the page is known, and the panel's ON, if it had one, is over.

Parameters
sThe link state.

◆ supply_link_next()

supply_link_write_t supply_link_next ( supply_link_t * s,
uint8_t * off,
uint8_t * n,
uint16_t * regs )

The next write owed, or SUPPLY_LINK_W_NONE.

off and n say where on the page and how many registers, regs what; the caller writes them and reports with supply_link_written().

Parameters
sThe link state.
offReceives the page offset of the write.
nReceives the number of registers.
regsReceives the register values.
Returns
The write owed, or SUPPLY_LINK_W_NONE.

◆ supply_link_port_held()

bool supply_link_port_held ( const supply_link_t * s)

Whether the last read of the page had LINK_SP_PORT set: a programming port holds the supply, and the page takes an OFF of the panel's and no other change of OUTPUT, SET_MV or SET_MA.

The KST page holds it for its whole session; from protocol 4.29 the HITEC page holds it from its OPEN to its CLOSE. False before the first read since the link came up.

Parameters
sThe link state.
Returns
true while held.

◆ supply_link_read()

void supply_link_read ( supply_link_t * s,
const uint16_t * regs,
uint32_t now_ms )

The whole page as read at now_ms, or regs NULL for a read that was not answered.

Parameters
sThe link state.
regsThe page as read, or NULL for a read not answered.
now_msThe time, in ms.

◆ supply_link_read_due()

bool supply_link_read_due ( const supply_link_t * s,
uint32_t now_ms )

Whether a read of the page is due at now_ms.

Parameters
sThe link state.
now_msThe time, in ms.
Returns
true when a read of the page is due.

◆ supply_link_reset()

void supply_link_reset ( supply_link_t * s)

Restart the PD mini (protocol 4.4): written once the page's output is off and its wiring written, after any OFF owed.

Parameters
sThe link state.

◆ supply_link_sag()

void supply_link_sag ( const supply_link_t * s,
uint16_t * vin_mv,
uint16_t * set_mv )

The input and the set point in mV that SUPPLY_LINK_EV_SAGGED was read with: the page's VIN_MV and SET_MV_RB on the read that first showed FLAGS bit 10.

An input reading taken between the IOmcu's cut and that read replaces the one that cut.

Parameters
sThe link state.
vin_mvReceives the input voltage, in mV.
set_mvReceives the set point, in mV.

◆ supply_link_settled()

bool supply_link_settled ( const supply_link_t * s)

Whether nothing is owed: the page holds the command asked and the wiring, or the wiring was refused.

Parameters
sThe link state.
Returns
true when nothing is owed.

◆ supply_link_state()

void supply_link_state ( const supply_link_t * s,
uint32_t now_ms,
supply_state_t * st )

The supply as the page last said, into st: readings, set points read back from the module, the mode – OFF while the module reads its output off – the module's reading count (SAMPLES, the IOmcu's count of output readings the module answered) and the time of the page read that first showed that count, and online only for a page read younger than SUPPLY_LINK_STALE_MS from a module the page drives.

The readings are marked valid (ok) only while the count moved within the last SUPPLY_LINK_STALE_MS; behind a count that stands still they stay as the last ones with ok 0. Left as they are: output, which is what the panel asked, and the run's extremes, totals and trip.

Parameters
sThe link state.
now_msThe time, in ms.
stReceives the supply state.

◆ supply_link_wire()

void supply_link_wire ( supply_link_t * s,
const supply_wiring_t * w )

The wiring the settings name now.

Parameters
sThe link state.
wThe wiring the settings name.

◆ supply_link_wiring_moved()

bool supply_link_wiring_moved ( supply_link_follow_t * f,
unsigned edits,
unsigned word )

Whether the PD mini's wiring has moved since it was last followed.

Parameters
fThe followed wiring state, updated.
editsThe edit count now.
wordThe wiring word now.
Returns
true when the edit count or the wiring word has moved since the last call.

◆ supply_link_written()

void supply_link_written ( supply_link_t * s,
int result )

How the write supply_link_next() gave went: SUPPLY_LINK_ACK, a NACK reason, or SUPPLY_LINK_NO_ANSWER.

Parameters
sThe link state.
resultThe result: an acknowledgement, a NACK's reason or SUPPLY_LINK_NO_ANSWER.