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

The panel's half of the SENSE_MAP page. More...

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

Macros

#define STATUS_AT   ((uint8_t)LINK_SM_ID_0)
#define STATUS_N   ((uint8_t)(LINK_SM_FLAGS - LINK_SM_ID_0 + 1))

Functions

void sense_map_link_init (sense_map_link_t *s)
 Sets up the SENSE_MAP link state.
static void forget_reads (sense_map_link_t *s, uint32_t now_ms)
 What was read and said under the map in force: news again under the next.
void sense_map_link_lost (sense_map_link_t *s)
 The link went: nothing on the page is known.
void sense_map_link_came_up (sense_map_link_t *s, uint16_t minor, uint32_t now_ms)
 An IOmcu answered with protocol minor minor; below LINK_MINOR_SENSE_MAP nothing is sent to it.
static void raise (sense_map_link_t *s, uint8_t ev, uint8_t parts)
 Raises an event for the parts it is about.
void sense_map_link_want (sense_map_link_t *s, const sense_map_want_t *w, uint32_t now_ms)
 The map SENSORS asks for now.
static bool fitted_any (const sense_map_link_t *s)
 Whether any part is enabled by the map asked or held.
bool sense_map_link_next (sense_map_link_t *s, uint32_t now_ms, bool idle, sense_map_link_op_t *op)
 The next exchange owed at now_ms into op; false for none.
static unsigned held_mirror (const sense_map_link_t *s)
 The part SENSE reports on, by the map in force: FAST's, else the lowest fitted; 4 for none.
uint16_t sense_map_link_mirror_dmohm (const sense_map_link_t *s, unsigned ch)
 The shunt in 0.1mOhm of CH ch (1 to 3) of the part SENSE mirrors, as the page holds the map: the part SENSE's CLIPPED flag and SERVO_SENSE are about.
bool sense_map_link_waits_for_pins (const sense_map_link_t *s, const sense_link_t *sl)
 Whether the map waits for SENSE's pins: it enables a part while SENSE has not been read since link-up or the sensor bus's pins it holds are not the ones asked.
static void judge (sense_map_link_t *s, uint32_t now_ms)
 What a read of IDs and FLAGS says that the operator is told.
static void take_status (sense_map_link_t *s, const uint16_t *regs)
 Takes a status read: the IDs and the FLAGS.
void sense_map_link_done (sense_map_link_t *s, int result, const uint16_t *regs, uint32_t now_ms)
 How it went: SENSE_MAP_LINK_ACK with the registers read (NULL for a write), a NACK's reason, or SENSE_MAP_LINK_NO_ANSWER.
bool sense_map_link_page (const sense_map_link_t *s)
 Whether the IOmcu has the page: up, 4.25 or later, and no read refused.
bool sense_map_link_held (const sense_map_link_t *s)
 Whether the page holds the map asked: read since link-up, not refused, and nothing owed.
bool sense_map_link_in_force (const sense_map_link_t *s)
 Whether the IOmcu goes by a map written to it, not the one derived from SENSE: FLAGS' IN_FORCE as last read, or a write taken since.
bool sense_map_link_take_reread (sense_map_link_t *s)
 Whether a write was taken since the last call: SENSE's set-up is to be read again.
uint8_t sense_map_link_event (sense_map_link_t *s, uint32_t now_ms, uint8_t *part, uint16_t *id)
 The events since the last call, SENSE_MAP_LINK_EV_*, the lowest bit first, one at a time; 0 for none, and 0 while the last one handed out is younger than SENSE_MAP_LINK_EVENT_GAP_MS at now_ms.
bool sense_map_link_event_stands (const sense_map_link_t *s, uint8_t ev, uint8_t part)
 Whether the cause of event ev for part part still holds: the map refused, the part dark, or, for SILENT and WRONG, the part fitted on a link that answers.
void sense_map_link_event_back (sense_map_link_t *s, uint8_t ev, uint8_t part)
 Put back an event sense_map_link_event() handed out that never reached the band, with the part it named.
static sens_part_t old_part (const sense_link_t *sl, uint32_t now_ms)
 An IOmcu older than 4.25: the mirror part as SENSE reads it.
sens_part_t sense_map_link_part (const sense_map_link_t *s, const sense_link_t *sl, unsigned a, unsigned mirror, uint32_t now_ms)
 What fitted part a is doing at now_ms, a sens_part_t.
uint16_t sense_map_link_status (const sense_map_link_t *s, const sense_link_t *sl, unsigned mirror, uint32_t now_ms)
 The four parts' sense_map_link_part(), 4 bits each, part 0 lowest; SENS_PART_UNKNOWN for a part not fitted.

Variables

static const uint8_t k_ev [4]

Detailed Description

The panel's half of the SENSE_MAP page.

See sense_map_link.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ fitted_any()

bool fitted_any ( const sense_map_link_t * s)
static

Whether any part is enabled by the map asked or held.

Parameters
sThe link state.
Returns
true when a part is enabled.

◆ forget_reads()

void forget_reads ( sense_map_link_t * s,
uint32_t now_ms )
static

What was read and said under the map in force: news again under the next.

Parameters
sThe link state.
now_msThe time, in ms.

◆ held_mirror()

unsigned held_mirror ( const sense_map_link_t * s)
static

The part SENSE reports on, by the map in force: FAST's, else the lowest fitted; 4 for none.

Parameters
sThe link state.
Returns
The part, 0 to 3; 4 for none.

◆ judge()

void judge ( sense_map_link_t * s,
uint32_t now_ms )
static

What a read of IDs and FLAGS says that the operator is told.

Parameters
sThe link state.
now_msThe time, in ms.

◆ old_part()

sens_part_t old_part ( const sense_link_t * sl,
uint32_t now_ms )
static

An IOmcu older than 4.25: the mirror part as SENSE reads it.

Parameters
slThe SENSE link.
now_msThe time, in ms.
Returns
What the mirror part is doing, as sens_part_t.

◆ raise()

void raise ( sense_map_link_t * s,
uint8_t ev,
uint8_t parts )
static

Raises an event for the parts it is about.

Parameters
sThe link state.
evThe event bit.
partsThe parts the event is about, one bit each.

◆ sense_map_link_came_up()

void sense_map_link_came_up ( sense_map_link_t * s,
uint16_t minor,
uint32_t now_ms )

An IOmcu answered with protocol minor minor; below LINK_MINOR_SENSE_MAP nothing is sent to it.

Parameters
sThe link state.
minorThe IOmcu's protocol minor version.
now_msThe time, in ms.

◆ sense_map_link_done()

void sense_map_link_done ( sense_map_link_t * s,
int result,
const uint16_t * regs,
uint32_t now_ms )

How it went: SENSE_MAP_LINK_ACK with the registers read (NULL for a write), a NACK's reason, or SENSE_MAP_LINK_NO_ANSWER.

Parameters
sThe link state.
resultThe result: an acknowledgement, a NACK's reason or SENSE_MAP_LINK_NO_ANSWER.
regsThe registers read, or NULL for a write.
now_msThe time, in ms.

◆ sense_map_link_event()

uint8_t sense_map_link_event ( sense_map_link_t * s,
uint32_t now_ms,
uint8_t * part,
uint16_t * id )

The events since the last call, SENSE_MAP_LINK_EV_*, the lowest bit first, one at a time; 0 for none, and 0 while the last one handed out is younger than SENSE_MAP_LINK_EVENT_GAP_MS at now_ms.

part is the lowest part it names, 0 to 3 (0 for REFUSED), with its ID for WRONG in id. SILENT and WRONG are handed out a part at a time.

Parameters
sThe link state.
now_msThe time, in ms.
partReceives the lowest part the event names, 0 to 3.
idReceives the ID for WRONG.
Returns
The event, a SENSE_MAP_LINK_EV_* bit, or 0 for none.

◆ sense_map_link_event_back()

void sense_map_link_event_back ( sense_map_link_t * s,
uint8_t ev,
uint8_t part )

Put back an event sense_map_link_event() handed out that never reached the band, with the part it named.

Not once its cause is over (sense_map_link_event_stands()).

Parameters
sThe link state.
evThe event, a SENSE_MAP_LINK_EV_* bit.
partThe part, 0 to 3.

◆ sense_map_link_event_stands()

bool sense_map_link_event_stands ( const sense_map_link_t * s,
uint8_t ev,
uint8_t part )

Whether the cause of event ev for part part still holds: the map refused, the part dark, or, for SILENT and WRONG, the part fitted on a link that answers.

Parameters
sThe link state.
evThe event, a SENSE_MAP_LINK_EV_* bit.
partThe part, 0 to 3.
Returns
true while the cause of the event holds.

◆ sense_map_link_held()

bool sense_map_link_held ( const sense_map_link_t * s)

Whether the page holds the map asked: read since link-up, not refused, and nothing owed.

False on an IOmcu older than 4.25.

Parameters
sThe link state.
Returns
true when the page holds the map asked.

◆ sense_map_link_in_force()

bool sense_map_link_in_force ( const sense_map_link_t * s)

Whether the IOmcu goes by a map written to it, not the one derived from SENSE: FLAGS' IN_FORCE as last read, or a write taken since.

False before the page is read and on an IOmcu older than 4.25.

Parameters
sThe link state.
Returns
true when the IOmcu goes by the map written to it.

◆ sense_map_link_init()

void sense_map_link_init ( sense_map_link_t * s)

Sets up the SENSE_MAP link state.

Parameters
sThe link state to set up.

◆ sense_map_link_lost()

void sense_map_link_lost ( sense_map_link_t * s)

The link went: nothing on the page is known.

Parameters
sThe link state.

◆ sense_map_link_mirror_dmohm()

uint16_t sense_map_link_mirror_dmohm ( const sense_map_link_t * s,
unsigned ch )

The shunt in 0.1mOhm of CH ch (1 to 3) of the part SENSE mirrors, as the page holds the map: the part SENSE's CLIPPED flag and SERVO_SENSE are about.

0 without a map read, or for no such part.

Parameters
sThe link state.
chThe channel, 1 to 3.
Returns
The shunt in 0.1mOhm, or 0 without a map read or for no such part.

◆ sense_map_link_next()

bool sense_map_link_next ( sense_map_link_t * s,
uint32_t now_ms,
bool idle,
sense_map_link_op_t * op )

The next exchange owed at now_ms into op; false for none.

The write goes only while idle.

Parameters
sThe link state.
now_msThe time, in ms.
idletrue while the bus is idle.
opReceives the exchange owed.
Returns
true when an exchange is owed.

◆ sense_map_link_page()

bool sense_map_link_page ( const sense_map_link_t * s)

Whether the IOmcu has the page: up, 4.25 or later, and no read refused.

Parameters
sThe link state.
Returns
true when the IOmcu has the page.

◆ sense_map_link_part()

sens_part_t sense_map_link_part ( const sense_map_link_t * s,
const sense_link_t * sl,
unsigned a,
unsigned mirror,
uint32_t now_ms )

What fitted part a is doing at now_ms, a sens_part_t.

sl is SENSE's link, which reads the mirror part mirror (0 to 3, 0xFF none) on an IOmcu older than 4.25.

Parameters
sThe link state.
slThe SENSE link.
aThe fitted part, 0 to 3.
mirrorThe part SENSE mirrors, 0 to 3, or 0xFF for none.
now_msThe time, in ms.
Returns
What fitted part a is doing, as sens_part_t.

◆ sense_map_link_status()

uint16_t sense_map_link_status ( const sense_map_link_t * s,
const sense_link_t * sl,
unsigned mirror,
uint32_t now_ms )

The four parts' sense_map_link_part(), 4 bits each, part 0 lowest; SENS_PART_UNKNOWN for a part not fitted.

Parameters
sThe link state.
slThe SENSE link.
mirrorThe part SENSE mirrors, 0 to 3, or 0xFF for none.
now_msThe time, in ms.
Returns
The four parts' sense_map_link_part() values, 4 bits each, part 0 lowest.

◆ sense_map_link_take_reread()

bool sense_map_link_take_reread ( sense_map_link_t * s)

Whether a write was taken since the last call: SENSE's set-up is to be read again.

Cleared.

Parameters
sThe link state.
Returns
true when a write was taken since the last call.

◆ sense_map_link_waits_for_pins()

bool sense_map_link_waits_for_pins ( const sense_map_link_t * s,
const sense_link_t * sl )

Whether the map waits for SENSE's pins: it enables a part while SENSE has not been read since link-up or the sensor bus's pins it holds are not the ones asked.

The page judges a map against the pins it holds, so SENSE writes them first.

Parameters
sThe link state.
slThe SENSE link.
Returns
true when the map waits for SENSE's pins.

◆ sense_map_link_want()

void sense_map_link_want ( sense_map_link_t * s,
const sense_map_want_t * w,
uint32_t now_ms )

The map SENSORS asks for now.

Parameters
sThe link state.
wThe map to ask for.
now_msThe time, in ms.

◆ take_status()

void take_status ( sense_map_link_t * s,
const uint16_t * regs )
static

Takes a status read: the IDs and the FLAGS.

Parameters
sThe link state.
regsThe registers read.

Variable Documentation

◆ k_ev

const uint8_t k_ev[4]
static
Initial value:
= {
}