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

The IOmcu's sensor service. More...

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

Functions

void sense_svc_init (sense_svc_t *v, const sense_svc_io_t *io)
 A service with the bus closed; the first step takes its command whole.
static uint64_t now_us (const sense_svc_t *v)
 The service's clock, in µs.
static bool any_part (const sense_sched_cfg_t *c)
 Test whether a configuration enables any part.
static void set_up (sense_svc_t *v, const sense_cmd_t *cmd)
 The set-up: the bus closed, and opened again with a fresh schedule on the command's pins when a part is enabled.
bool sense_window_over (const sense_window_t *w, int32_t clip_ua, uint16_t limit_ma)
 Whether window w of a channel passed limit_ma: its highest current rounded to mA (as SENSE_WIN shows it) above the limit, or a sample clipped at the top of the range when that top, clip_ua (the top code's current, 163.8mV across the shunt), is above the limit.
static void judge (sense_svc_t *v, const sense_cmd_t *cmd)
 The windows that closed in this tick, each channel against its limit, once a window.
static void capture (sense_svc_t *v, const sense_cmd_t *cmd)
 Act on the capture part of a command, once per capture generation.
static bool part_missing (const sense_sched_t *s)
 An enabled part that is not online, whose address a scan may find.
static bool capture_under_way (const sense_sched_t *s)
 Test whether a capture is armed, waiting or moving.
static uint16_t online_bit (sense_state_t st, uint8_t addr)
 The bit a part's address has in PRESENT while it is online, else 0.
static uint16_t online_mask (const sense_sched_t *s)
 The PRESENT mask of the parts online now.
static void scan (sense_svc_t *v, uint64_t now)
 Scan the addresses of the scan range for parts that may have appeared.
static void snap_capture (const sense_svc_t *v, sense_snap_t *out)
 The capture's fields: the schedule's, or lost for an arm refused.
static void snap (const sense_svc_t *v, sense_snap_t *out)
 Fill a snapshot of the service's state.
void sense_svc_step (sense_svc_t *v, const sense_cmd_t *cmd, sense_snap_t *out)
 One tick, every 1ms: cmd acted on, the schedule ticked while the bus is open, and out filled.

Detailed Description

The IOmcu's sensor service.

See sense_svc.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ any_part()

bool any_part ( const sense_sched_cfg_t * c)
static

Test whether a configuration enables any part.

Parameters
cThe schedule configuration.
Returns
true when the INA228, an INA3221 or the output encoder is enabled.

◆ capture()

void capture ( sense_svc_t * v,
const sense_cmd_t * cmd )
static

Act on the capture part of a command, once per capture generation.

Parameters
vThe service.
cmdThe command.

◆ capture_under_way()

bool capture_under_way ( const sense_sched_t * s)
static

Test whether a capture is armed, waiting or moving.

Parameters
sThe schedule.
Returns
true while the capture is armed, waiting or moving.

◆ judge()

void judge ( sense_svc_t * v,
const sense_cmd_t * cmd )
static

The windows that closed in this tick, each channel against its limit, once a window.

A part not online as the windows rolled (last_online) is judged on nothing.

Parameters
vThe service.
cmdThe command, with the limits.

◆ now_us()

uint64_t now_us ( const sense_svc_t * v)
static

The service's clock, in µs.

Parameters
vThe service.
Returns
The time the schedule's clock reads, in µs.

◆ online_bit()

uint16_t online_bit ( sense_state_t st,
uint8_t addr )
static

The bit a part's address has in PRESENT while it is online, else 0.

Parameters
stThe part's state.
addrThe part's I2C address.
Returns
The bit for the address when the part is online, else 0.

◆ online_mask()

uint16_t online_mask ( const sense_sched_t * s)
static

The PRESENT mask of the parts online now.

Parameters
sThe schedule.
Returns
One bit per online part address.

◆ part_missing()

bool part_missing ( const sense_sched_t * s)
static

An enabled part that is not online, whose address a scan may find.

Parameters
sThe schedule.
Returns
true when an enabled part is not online.

◆ scan()

void scan ( sense_svc_t * v,
uint64_t now )
static

Scan the addresses of the scan range for parts that may have appeared.

Parameters
vThe service.
nowThe current time, in µs.

◆ sense_svc_init()

void sense_svc_init ( sense_svc_t * v,
const sense_svc_io_t * io )

A service with the bus closed; the first step takes its command whole.

Parameters
vThe service to set up.
ioThe callbacks the service calls.

◆ sense_svc_step()

void sense_svc_step ( sense_svc_t * v,
const sense_cmd_t * cmd,
sense_snap_t * out )

One tick, every 1ms: cmd acted on, the schedule ticked while the bus is open, and out filled.

Parameters
vThe service.
cmdThe command to act on.
outReceives the snapshot.

◆ sense_window_over()

bool sense_window_over ( const sense_window_t * w,
int32_t clip_ua,
uint16_t limit_ma )

Whether window w of a channel passed limit_ma: its highest current rounded to mA (as SENSE_WIN shows it) above the limit, or a sample clipped at the top of the range when that top, clip_ua (the top code's current, 163.8mV across the shunt), is above the limit.

Never with a limit of 0, and never for a negative current. The service judges each channel's window once, as it closes, on core 1, so no window is missed however late core 0 takes the snapshot.

Parameters
wThe window to judge.
clip_uaThe current at the top code, in µA.
limit_maThe limit, in mA.
Returns
true when the window passed the limit.

◆ set_up()

void set_up ( sense_svc_t * v,
const sense_cmd_t * cmd )
static

The set-up: the bus closed, and opened again with a fresh schedule on the command's pins when a part is enabled.

Parameters
vThe service.
cmdThe command.

◆ snap()

void snap ( const sense_svc_t * v,
sense_snap_t * out )
static

Fill a snapshot of the service's state.

Parameters
vThe service.
outReceives the snapshot.

◆ snap_capture()

void snap_capture ( const sense_svc_t * v,
sense_snap_t * out )
static

The capture's fields: the schedule's, or lost for an arm refused.

Parameters
vThe service.
outReceives the snapshot.