|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The panel's half of the SENSE, SERVO_SENSE and SERVO_WIN link pages: what the last reads hold, handed to the screens, the log and the band – the servo windows, the meter, the ESC figures and totals, the encoder and the parts' addresses and identities – and the rows of SETUP the page does not hold. More...
Functions | |
| static uint8_t | servo_ok (const sense_link_t *s) |
| SERVO_SENSE's last read: the channels whose window holds readings, bit n-1 for CHn. | |
| static bool | servo_window_new (const sense_link_t *s) |
| Whether SERVO_SENSE's last read holds a window not taken yet. | |
| unsigned | sense_link_windows (const sense_link_t *s) |
| How many windows sense_link_take_window() hands over now: the ring's waiting ones, or without the ring 1 while SERVO_SENSE's last read holds a window not taken yet. | |
| static void | servo_channel (const sense_link_t *s, size_t i, bench_state_t *b) |
Channel index i of SERVO_SENSE's last read into b. | |
| void | sense_link_win_bench (const sense_link_t *s, const sense_link_win_t *w, bench_state_t *b) |
A ring window into b's log fields: servo_new set, its number, CH1's mean and highest current and lowest bus voltage with servo_ok bit 0 set while the window holds samples, servo_no_current and servo_no_voltage bit 0 for the quantity it holds no sample of, and CH2's and CH3's figures from SERVO_SENSE's last read when that read shows the same window number. | |
| bool | sense_link_take_window (sense_link_t *s, bench_state_t *b) |
The INA3221's next window into b for the log, once per window; true and servo_new set, false and b untouched otherwise. | |
| static bool | held_as_asked (const sense_link_t *s) |
| Whether the page holds what the panel asks of it. | |
| void | sense_link_meter (const sense_link_t *s, sense_link_meter_t *out) |
What the servo rail's meter is chosen from, into out. | |
| uint16_t | sense_link_flags (const sense_link_t *s) |
| FLAGS as last read, 0 before any read. | |
| uint32_t | sense_link_reads (const sense_link_t *s) |
| SENSE reads answered since init: a caller that compares two counts can tell a read made in between. | |
| bool | sense_link_esc (const sense_link_t *s, uint32_t now_ms, bool *v_ok, float *volts, bool *i_ok, float *amps) |
| The ESC's own telemetry voltage and current, from the last SENSE read if it is younger than SENSE_LINK_STALE_MS, each with its valid bit. | |
| bool | sense_link_totals (const sense_link_t *s, uint32_t now_ms, int32_t *charge_cmah, uint32_t *energy_cwh) |
| The INA228's charge in 0.01mAh and energy in 0.01Wh as last read, 0 while they are not the run's totals. | |
| bool | sense_link_enc_on (const sense_link_t *s) |
| Whether the encoder is set up on the page: enabled there, and read. | |
| static bool | enc_read (const sense_link_t *s, uint32_t now_ms, uint16_t *flags) |
Whether the last SENSE read is fresh at now_ms and holds a reading of the encoder's registers from a part that answers; its flags into flags. | |
| bool | sense_link_enc (const sense_link_t *s, uint32_t now_ms, sense_link_enc_t *out) |
The encoder's last angle into out: true when the page enables it, the last SENSE read is younger than SENSE_LINK_STALE_MS at now_ms, the part was online in it, the angle holds a reading of this set-up and that reading's STATUS has MD set: a magnet is detected, and RAW ANGLE is a position. | |
| bool | sense_link_enc_no_magnet (const sense_link_t *s, uint32_t now_ms) |
Whether sense_link_enc() gives no angle at now_ms because the part answers and sees no magnet: every condition of sense_link_enc() but MD holds. | |
| uint16_t | sense_link_enc_magnet (const sense_link_t *s) |
| The magnet bits SENSE_LINK_EV_ENC_MAGNET was raised with: LINK_SN_ENC_MD, _ML and _MH, as read. | |
| uint8_t | sense_link_addr (const sense_link_t *s, sense_link_part_t part) |
The address part is set up at on the page, 0 while not known. | |
| uint16_t | sense_link_id (const sense_link_t *s, sense_link_part_t part) |
The ID part gave, as last read (DEVICE_ID, the die ID). | |
| uint8_t | sense_link_found (const sense_link_t *s, sense_link_part_t part) |
Another address that answered the last scan where part could be: an INA228 at 0x40 to 0x4F, an INA3221 at 0x40 to 0x43, neither at the other part's address while that one is enabled. | |
| uint16_t | sense_link_event_id (const sense_link_t *s, sense_link_part_t part) |
What an event was raised with, kept for when the band shows it: the ID part gave for SENSE_LINK_EV_*_WRONG, and the address the scan found for SENSE_LINK_EV_*_SILENT (0 none). | |
| uint8_t | sense_link_event_found (const sense_link_t *s, sense_link_part_t part) |
| The address a scan found for the event's part, or 0 for none. | |
| uint8_t | sense_link_clipped_channel (const sense_link_t *s) |
| The INA3221 channel SENSE_LINK_EV_I3221_CLIPPED names, 1 to 3: the one sense_link_event() last handed out. | |
| uint16_t | sense_link_i3221_dmohm (const sense_link_t *s) |
| The INA3221's shunt on the page, 0.1mOhm. | |
| uint8_t | sense_link_i3221_addr (const sense_link_t *s) |
| The INA3221's address on the page, the part SERVO_SENSE reads: 0x40 to 0x43; 0 before the page is read. | |
| int | sense_link_sda (const sense_link_t *s) |
| The pins asked, -1 for unset: what SENSE_LINK_EV_BUS_REFUSED names. | |
| int | sense_link_scl (const sense_link_t *s) |
| The SCL pin asked, -1 for unset. | |
| uint16_t | sense_link_unheld (const sense_link_t *s) |
| The rows whose value as asked is not the one the page holds, SENSE_LINK_ROW_*: a set-up not written yet – it rests SENSE_LINK_SETTLE_MS and waits for an idle bank – one the page refused, and a part that is on in the settings and off on the page because its frame was refused, its pins are unset, both monitors share an address or the IOmcu is older than the part. | |
| void | sense_link_set_map (sense_link_t *s, bool map) |
| Whether the INA3221 parts go by SENSE_MAP (sense_map_link_page()): then ENABLE bit 1 and the INA3221's frame are the IOmcu's mirror of the map, kept as read and never written, and refuse nothing. | |
| void | sense_link_set_map_held (sense_link_t *s, bool held) |
| Whether SENSE_MAP holds the map SETUP asks (sense_map_link_held()): with the map in force the meter is held only then. | |
| void | sense_link_reread (sense_link_t *s) |
| Read SENSE's set-up again, and the identity after it: a SENSE_MAP write was taken, and the mirror registers moved with it. | |
| bool | sense_link_take_caps (sense_link_t *s, uint16_t *caps) |
The capability bits an identity read since the last call brought, into caps; false if none did. | |
| bool | sense_link_take_win (sense_link_t *s, sense_link_win_t *out) |
The next CH1 window of the ring into out, oldest first, each number once: false when none waits, out untouched. | |
| uint32_t | sense_link_win_lost (const sense_link_t *s) |
| Window numbers that left the ring before a read took them, since init, modulo 2^32: the windows lost, and with them any number the IOmcu skipped that was out of the ring by the read. | |
| bool | sense_link_held_pins (const sense_link_t *s, int *sda, int *scl) |
| The sensor bus's pins the page holds by its last read or write, as the IOmcu reserves them (sense_page_pins()): SDA and SCL while ENABLE has a part on, -1 and -1 while it has none or the IOmcu has no SENSE page. | |
The panel's half of the SENSE, SERVO_SENSE and SERVO_WIN link pages: what the last reads hold, handed to the screens, the log and the band – the servo windows, the meter, the ESC figures and totals, the encoder and the parts' addresses and identities – and the rows of SETUP the page does not hold.
The state machine that decides what is read and written is in sense_link.c. See sense_link.h.
SPDX-License-Identifier: MIT
|
static |
Whether the last SENSE read is fresh at now_ms and holds a reading of the encoder's registers from a part that answers; its flags into flags.
| s | The link state. |
| now_ms | The time, in ms. |
| flags | Receives the encoder flags. |
|
static |
Whether the page holds what the panel asks of it.
With the map in force the INA3221's enable bit and frame are the map's mirror, which the panel does not ask: they are left out.
| s | The link state. |
| uint8_t sense_link_addr | ( | const sense_link_t * | s, |
| sense_link_part_t | part ) |
The address part is set up at on the page, 0 while not known.
| s | The link state. |
| part | The part. |
| uint8_t sense_link_clipped_channel | ( | const sense_link_t * | s | ) |
The INA3221 channel SENSE_LINK_EV_I3221_CLIPPED names, 1 to 3: the one sense_link_event() last handed out.
Channels that clip together are handed out one each, the event standing until the last.
| s | The link state. |
| bool sense_link_enc | ( | const sense_link_t * | s, |
| uint32_t | now_ms, | ||
| sense_link_enc_t * | out ) |
The encoder's last angle into out: true when the page enables it, the last SENSE read is younger than SENSE_LINK_STALE_MS at now_ms, the part was online in it, the angle holds a reading of this set-up and that reading's STATUS has MD set: a magnet is detected, and RAW ANGLE is a position.
False, out untouched, otherwise. This is the one place an angle leaves the link, so no caller has an angle read without a magnet.
| s | The link state. |
| now_ms | The time, in ms. |
| out | Receives the angle. |
| uint16_t sense_link_enc_magnet | ( | const sense_link_t * | s | ) |
The magnet bits SENSE_LINK_EV_ENC_MAGNET was raised with: LINK_SN_ENC_MD, _ML and _MH, as read.
| s | The link state. |
| bool sense_link_enc_no_magnet | ( | const sense_link_t * | s, |
| uint32_t | now_ms ) |
Whether sense_link_enc() gives no angle at now_ms because the part answers and sees no magnet: every condition of sense_link_enc() but MD holds.
| s | The link state. |
| now_ms | The time, in ms. |
| bool sense_link_enc_on | ( | const sense_link_t * | s | ) |
Whether the encoder is set up on the page: enabled there, and read.
| s | The link state. |
| bool sense_link_esc | ( | const sense_link_t * | s, |
| uint32_t | now_ms, | ||
| bool * | v_ok, | ||
| float * | volts, | ||
| bool * | i_ok, | ||
| float * | amps ) |
The ESC's own telemetry voltage and current, from the last SENSE read if it is younger than SENSE_LINK_STALE_MS, each with its valid bit.
False, both bits clear, otherwise.
| s | The link state. |
| now_ms | The time, in ms. |
| v_ok | Receives the valid bit of the voltage. |
| volts | Receives the voltage, in V. |
| i_ok | Receives the valid bit of the current. |
| amps | Receives the current, in A. |
| uint8_t sense_link_event_found | ( | const sense_link_t * | s, |
| sense_link_part_t | part ) |
The address a scan found for the event's part, or 0 for none.
| s | The link state. |
| part | The part. |
| uint16_t sense_link_event_id | ( | const sense_link_t * | s, |
| sense_link_part_t | part ) |
What an event was raised with, kept for when the band shows it: the ID part gave for SENSE_LINK_EV_*_WRONG, and the address the scan found for SENSE_LINK_EV_*_SILENT (0 none).
A later read can show another; a part that answers as itself before the band shows either drops it.
| s | The link state. |
| part | The part. |
| uint16_t sense_link_flags | ( | const sense_link_t * | s | ) |
FLAGS as last read, 0 before any read.
| s | The link state. |
| uint8_t sense_link_found | ( | const sense_link_t * | s, |
| sense_link_part_t | part ) |
Another address that answered the last scan where part could be: an INA228 at 0x40 to 0x4F, an INA3221 at 0x40 to 0x43, neither at the other part's address while that one is enabled.
The lowest; 0 for none.
| s | The link state. |
| part | The part. |
| bool sense_link_held_pins | ( | const sense_link_t * | s, |
| int * | sda, | ||
| int * | scl ) |
The sensor bus's pins the page holds by its last read or write, as the IOmcu reserves them (sense_page_pins()): SDA and SCL while ENABLE has a part on, -1 and -1 while it has none or the IOmcu has no SENSE page.
False, both -1, while that is not known: no link, or no read yet. sda and scl may be NULL.
| s | The link state. |
| sda | Receives the SDA pin, or -1; may be NULL. |
| scl | Receives the SCL pin, or -1; may be NULL. |
| uint8_t sense_link_i3221_addr | ( | const sense_link_t * | s | ) |
The INA3221's address on the page, the part SERVO_SENSE reads: 0x40 to 0x43; 0 before the page is read.
| s | The link state. |
| uint16_t sense_link_i3221_dmohm | ( | const sense_link_t * | s | ) |
The INA3221's shunt on the page, 0.1mOhm.
| s | The link state. |
| uint16_t sense_link_id | ( | const sense_link_t * | s, |
| sense_link_part_t | part ) |
The ID part gave, as last read (DEVICE_ID, the die ID).
| s | The link state. |
| part | The part. |
| void sense_link_meter | ( | const sense_link_t * | s, |
| sense_link_meter_t * | out ) |
What the servo rail's meter is chosen from, into out.
| s | The link state. |
| out | Receives the meter's choice. |
| uint32_t sense_link_reads | ( | const sense_link_t * | s | ) |
SENSE reads answered since init: a caller that compares two counts can tell a read made in between.
| s | The link state. |
| void sense_link_reread | ( | sense_link_t * | s | ) |
Read SENSE's set-up again, and the identity after it: a SENSE_MAP write was taken, and the mirror registers moved with it.
| s | The link state. |
| int sense_link_scl | ( | const sense_link_t * | s | ) |
The SCL pin asked, -1 for unset.
| s | The link state. |
| int sense_link_sda | ( | const sense_link_t * | s | ) |
The pins asked, -1 for unset: what SENSE_LINK_EV_BUS_REFUSED names.
| s | The link state. |
| void sense_link_set_map | ( | sense_link_t * | s, |
| bool | map ) |
Whether the INA3221 parts go by SENSE_MAP (sense_map_link_page()): then ENABLE bit 1 and the INA3221's frame are the IOmcu's mirror of the map, kept as read and never written, and refuse nothing.
| s | The link state. |
| map | true when the INA3221 parts go by SENSE_MAP. |
| void sense_link_set_map_held | ( | sense_link_t * | s, |
| bool | held ) |
Whether SENSE_MAP holds the map SETUP asks (sense_map_link_held()): with the map in force the meter is held only then.
| s | The link state. |
| held | true while SENSE_MAP holds the map SETUP asks. |
| bool sense_link_take_caps | ( | sense_link_t * | s, |
| uint16_t * | caps ) |
The capability bits an identity read since the last call brought, into caps; false if none did.
| s | The link state. |
| caps | Receives the capability bits. |
| bool sense_link_take_win | ( | sense_link_t * | s, |
| sense_link_win_t * | out ) |
The next CH1 window of the ring into out, oldest first, each number once: false when none waits, out untouched.
| s | The link state. |
| out | Receives the window. |
| bool sense_link_take_window | ( | sense_link_t * | s, |
| bench_state_t * | b ) |
The INA3221's next window into b for the log, once per window; true and servo_new set, false and b untouched otherwise.
With the ring (sense_link_win_on()): the next CH1 window, as sense_link_take_win() and sense_link_win_bench() give it. Call until false: a poll brings up to LINK_SW_RING windows.
Without it: SERVO_SENSE's last read, when it holds a window with readings whose number has not been taken before.
| s | The link state. |
| b | Receives the window for the log. |
| bool sense_link_totals | ( | const sense_link_t * | s, |
| uint32_t | now_ms, | ||
| int32_t * | charge_cmah, | ||
| uint32_t * | energy_cwh ) |
The INA228's charge in 0.01mAh and energy in 0.01Wh as last read, 0 while they are not the run's totals.
False before any read and for a read older than SENSE_LINK_TOTALS_MS at now_ms.
| s | The link state. |
| now_ms | The time, in ms. |
| charge_cmah | Receives the charge, in 0.01mAh. |
| energy_cwh | Receives the energy, in 0.01Wh. |
| uint16_t sense_link_unheld | ( | const sense_link_t * | s | ) |
The rows whose value as asked is not the one the page holds, SENSE_LINK_ROW_*: a set-up not written yet – it rests SENSE_LINK_SETTLE_MS and waits for an idle bank – one the page refused, and a part that is on in the settings and off on the page because its frame was refused, its pins are unset, both monitors share an address or the IOmcu is older than the part.
The comparison is want against held, the two this module writes from. 0 while no IOmcu answers and before the page has been read: nothing is known to compare with. An IOmcu without the page holds no part, and the parts that are on are named.
| s | The link state. |
| void sense_link_win_bench | ( | const sense_link_t * | s, |
| const sense_link_win_t * | w, | ||
| bench_state_t * | b ) |
A ring window into b's log fields: servo_new set, its number, CH1's mean and highest current and lowest bus voltage with servo_ok bit 0 set while the window holds samples, servo_no_current and servo_no_voltage bit 0 for the quantity it holds no sample of, and CH2's and CH3's figures from SERVO_SENSE's last read when that read shows the same window number.
| s | The link state. |
| w | The ring window. |
| b | Receives the log fields. |
| uint32_t sense_link_win_lost | ( | const sense_link_t * | s | ) |
Window numbers that left the ring before a read took them, since init, modulo 2^32: the windows lost, and with them any number the IOmcu skipped that was out of the ring by the read.
A caller that compares two counts has those of the time in between.
| s | The link state. |
| unsigned sense_link_windows | ( | const sense_link_t * | s | ) |
How many windows sense_link_take_window() hands over now: the ring's waiting ones, or without the ring 1 while SERVO_SENSE's last read holds a window not taken yet.
| s | The link state. |
|
static |
Channel index i of SERVO_SENSE's last read into b.
| s | The link state. |
| i | The channel index, from 0. |
| b | Receives the channel figures. |
|
static |
SERVO_SENSE's last read: the channels whose window holds readings, bit n-1 for CHn.
| s | The link state. |
|
static |
Whether SERVO_SENSE's last read holds a window not taken yet.
| s | The link state. |