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

Which meter measures the servo rail. More...

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

Functions

void servo_source_init (servo_source_t *s)
 The meter is the model until a step says otherwise.
static servo_source_why_t judge (uint32_t now_ms, uint16_t minor, const sense_link_meter_t *m)
 The first of conditions 1 to 5 that fails, or NONE.
static servo_source_id_t step (servo_source_t *s, uint32_t now_ms, bool link_up, uint16_t minor, const sense_link_meter_t *m)
 Carries out one poll of the source.
servo_source_id_t servo_source_step (servo_source_t *s, uint32_t now_ms, bool link_up, uint16_t minor, const sense_link_meter_t *m)
 One poll: the conditions judged at now_ms from link_up, the IOmcu's protocol minor minor and m, sense_link_meter()'s answer of the same poll.
servo_source_why_t servo_source_dropped (const servo_source_t *s, uint32_t *at)
 Why the INA3221 last stopped being the meter: SERVO_SOURCE_WHY_RESET when its reset count moved in that step, else the condition that failed in it, or SERVO_SOURCE_WHY_NO_LINK.
uint32_t servo_source_changes (const servo_source_t *s)
 How many times the meter has changed since servo_source_init(), modulo 2^32.
servo_source_id_t servo_source_id (const servo_source_t *s)
 The meter as of the last step.
servo_source_why_t servo_source_why (const servo_source_t *s)
 Why the INA3221 is not the meter, as of the last step.
uint32_t servo_source_event (servo_source_t *s, uint32_t now_ms)
 One event for the alert band, the older IOmcu before the reset, cleared; 0 while none waits or while the last one handed out is younger than SERVO_SOURCE_EVENT_GAP_MS at now_ms.
void servo_source_event_back (servo_source_t *s, uint32_t ev)
 Put back an event servo_source_event() handed out that never reached the band, so it is handed out again after the gap.

Detailed Description

Which meter measures the servo rail.

See servo_source.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ judge()

servo_source_why_t judge ( uint32_t now_ms,
uint16_t minor,
const sense_link_meter_t * m )
static

The first of conditions 1 to 5 that fails, or NONE.

Parameters
now_msThe time, in ms.
minorThe IOmcu's protocol minor version.
mThe sense_link_meter() answer.
Returns
The reason, or SERVO_SOURCE_WHY_NONE.

◆ servo_source_changes()

uint32_t servo_source_changes ( const servo_source_t * s)

How many times the meter has changed since servo_source_init(), modulo 2^32.

It orders two answers taken at different polls: of two counts the one that is ahead by less than 2^31 is the later.

Parameters
sThe source state.
Returns
The change count, modulo 2^32.

◆ servo_source_dropped()

servo_source_why_t servo_source_dropped ( const servo_source_t * s,
uint32_t * at )

Why the INA3221 last stopped being the meter: SERVO_SOURCE_WHY_RESET when its reset count moved in that step, else the condition that failed in it, or SERVO_SOURCE_WHY_NO_LINK.

at, when not NULL, takes servo_source_changes() as that step left it. SERVO_SOURCE_WHY_NONE while the INA3221 has not stopped being the meter since servo_source_init().

Parameters
sThe source state.
atReceives the change count of that step, or NULL.
Returns
The reason the INA3221 last stopped being the meter, or SERVO_SOURCE_WHY_NONE.

◆ servo_source_event()

uint32_t servo_source_event ( servo_source_t * s,
uint32_t now_ms )

One event for the alert band, the older IOmcu before the reset, cleared; 0 while none waits or while the last one handed out is younger than SERVO_SOURCE_EVENT_GAP_MS at now_ms.

Parameters
sThe source state.
now_msThe time, in ms.
Returns
The event for the alert band, or 0 for none.

◆ servo_source_event_back()

void servo_source_event_back ( servo_source_t * s,
uint32_t ev )

Put back an event servo_source_event() handed out that never reached the band, so it is handed out again after the gap.

Not once the link has gone: both events are about the IOmcu that answered.

Parameters
sThe source state.
evThe event to put back.

◆ servo_source_id()

servo_source_id_t servo_source_id ( const servo_source_t * s)

The meter as of the last step.

Parameters
sThe source state.
Returns
The meter as of the last step.

◆ servo_source_init()

void servo_source_init ( servo_source_t * s)

The meter is the model until a step says otherwise.

Parameters
sThe source state.

◆ servo_source_step()

servo_source_id_t servo_source_step ( servo_source_t * s,
uint32_t now_ms,
bool link_up,
uint16_t minor,
const sense_link_meter_t * m )

One poll: the conditions judged at now_ms from link_up, the IOmcu's protocol minor minor and m, sense_link_meter()'s answer of the same poll.

Returns the meter.

Parameters
sThe source state.
now_msThe time, in ms.
link_uptrue while the IOmcu link is up.
minorThe IOmcu's protocol minor version.
mThe sense_link_meter() answer of this poll.
Returns
The meter, a servo_source_id_t.

◆ servo_source_why()

servo_source_why_t servo_source_why ( const servo_source_t * s)

Why the INA3221 is not the meter, as of the last step.

Parameters
sThe source state.
Returns
Why the INA3221 is not the meter, as of the last step.

◆ step()

servo_source_id_t step ( servo_source_t * s,
uint32_t now_ms,
bool link_up,
uint16_t minor,
const sense_link_meter_t * m )
static

Carries out one poll of the source.

Parameters
sThe source state.
now_msThe time, in ms.
link_uptrue while the IOmcu link is up.
minorThe IOmcu's protocol minor version.
mThe sense_link_meter() answer, or NULL.
Returns
The meter after the poll.