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

The panel's half of SENSE_WIN_A and SENSE_WIN_B (0x37, 0x38, protocol 4.25): every INA3221 channel's last complete 50ms window, for the log's columns per watched target. More...

#include <stdbool.h>
#include <stdint.h>
#include "bench_state.h"
#include "link_pages.h"

Go to the source code of this file.

Data Structures

 One read the caller makes: registers 0 to n - 1 of page. More...
 The panel's state of the SENSE_WIN link pages. More...

Macros

#define SENSE_WIN_LINK_READ_MS   40u
 A page is read this often while a part it carries is enabled: the IOmcu closes a window every 50ms, and a gate under the poll's 50ms lets every poll read, whatever its offset in the pass.
#define SENSE_WIN_LINK_ACK   0
#define SENSE_WIN_LINK_NO_ANSWER   (-1)

Functions

void sense_win_link_init (sense_win_link_t *s)
 Sets up the SENSE_WIN link state.
void sense_win_link_lost (sense_win_link_t *s)
 The link went: nothing read is the IOmcu's now.
void sense_win_link_came_up (sense_win_link_t *s, uint16_t minor)
 An IOmcu answered with protocol minor minor; below LINK_MINOR_SENSE_MAP nothing is sent to it.
void sense_win_link_want (sense_win_link_t *s, uint8_t parts)
 The parts enabled in the map the IOmcu holds, bit a for 0x40 + a: the pages to read.
bool sense_win_link_next (sense_win_link_t *s, uint32_t now_ms, sense_win_link_op_t *op)
 The next read owed at now_ms into op; false for none.
void sense_win_link_done (sense_win_link_t *s, int result, const uint16_t *regs)
 How it went: SENSE_WIN_LINK_ACK with the registers read, a NACK's reason, or SENSE_WIN_LINK_NO_ANSWER.
bool sense_win_link_window (const sense_win_link_t *s, uint16_t window, bench_chw_t *out)
 The channels whose last or previous read holds window number window into out: out->ok bit c for channel c with readings, its current and voltage flags, and the figures; every other channel 0.
void sense_win_link_ring (bench_chw_t *out, unsigned fast, const bench_state_t *b)
 FAST's channel fast (0 to 11) of out from the window ring's window that b carries in its first channel (sense_link_win_bench()): the ring holds every window of FAST, the pages only the last.

Detailed Description

The panel's half of SENSE_WIN_A and SENSE_WIN_B (0x37, 0x38, protocol 4.25): every INA3221 channel's last complete 50ms window, for the log's columns per watched target.

SENSE_WIN_A carries channels 0 to 5 (the parts at 0x40 and 0x41), SENSE_WIN_B channels 6 to 11 (0x42 and 0x43). A page is read whole, 32 registers in one exchange, every SENSE_WIN_LINK_READ_MS while a part it carries is enabled in the map in force, and not at all otherwise. An IOmcu older than 4.25 has neither page: nothing is sent to it.

Each read keeps the page's registers as read, and the read before it while that held another window. sense_win_link_window() hands out the channels of the pages whose last or previous read holds window number window, so a row of the log gets the figures of its own window or none: a window that closed and was followed by the next between two reads gives its row nothing.

Pure C, no link of its own: the caller makes each exchange and reports how it went. Control task only.

SPDX-License-Identifier: MIT

Function Documentation

◆ sense_win_link_came_up()

void sense_win_link_came_up ( sense_win_link_t * s,
uint16_t minor )

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.

◆ sense_win_link_done()

void sense_win_link_done ( sense_win_link_t * s,
int result,
const uint16_t * regs )

How it went: SENSE_WIN_LINK_ACK with the registers read, a NACK's reason, or SENSE_WIN_LINK_NO_ANSWER.

BAD_PAGE stops the reads until the next link-up.

Parameters
sThe link state.
resultThe result: an acknowledgement, a NACK's reason or SENSE_WIN_LINK_NO_ANSWER.
regsThe registers read, or NULL for a write.

◆ sense_win_link_init()

void sense_win_link_init ( sense_win_link_t * s)

Sets up the SENSE_WIN link state.

Parameters
sThe link state to set up.

◆ sense_win_link_lost()

void sense_win_link_lost ( sense_win_link_t * s)

The link went: nothing read is the IOmcu's now.

Parameters
sThe link state.

◆ sense_win_link_next()

bool sense_win_link_next ( sense_win_link_t * s,
uint32_t now_ms,
sense_win_link_op_t * op )

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

With both pages due, a second call gives the other.

Parameters
sThe link state.
now_msThe time, in ms.
opReceives the read owed.
Returns
true when a read is owed.

◆ sense_win_link_ring()

void sense_win_link_ring ( bench_chw_t * out,
unsigned fast,
const bench_state_t * b )

FAST's channel fast (0 to 11) of out from the window ring's window that b carries in its first channel (sense_link_win_bench()): the ring holds every window of FAST, the pages only the last.

Nothing for a fast of LINK_SM_FAST_NONE or a b with no new window.

Parameters
outReceives the channels.
fastFAST's channel, 0 to 11, or LINK_SM_FAST_NONE.
bThe state that carries the window.

◆ sense_win_link_want()

void sense_win_link_want ( sense_win_link_t * s,
uint8_t parts )

The parts enabled in the map the IOmcu holds, bit a for 0x40 + a: the pages to read.

A page no longer wanted forgets its last read.

Parameters
sThe link state.
partsThe parts to read: bit a for part a.

◆ sense_win_link_window()

bool sense_win_link_window ( const sense_win_link_t * s,
uint16_t window,
bench_chw_t * out )

The channels whose last or previous read holds window number window into out: out->ok bit c for channel c with readings, its current and voltage flags, and the figures; every other channel 0.

Returns whether any channel has readings. out is always written.

Parameters
sThe link state.
windowThe window number to find.
outReceives the channels.
Returns
true when any channel has readings.