|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The SENSE_MAP, SENSE_WIN_A and SENSE_WIN_B link pages. More...
#include "sense_map.h"#include <stddef.h>#include <string.h>#include "ina3221.h"#include "link_msg.h"#include "link_pages.h"#include "sense_page_int.h"Functions | |
| static bool | fitted (const uint16_t *m, unsigned a) |
Whether INA3221 part a is fitted: its bit in ENABLE is set. | |
| static void | derive (const sense_page_t *p, uint16_t *m) |
| The map SENSE's one part makes: what a read shows and a first write starts from. | |
| static const uint16_t * | kept_regs (const sense_page_t *p, uint16_t *buf) |
The kept registers in force, or derived into buf. | |
| static bool | watch_ok (uint16_t w) |
| Whether a WATCH value is one the map accepts. | |
| bool | sense_map_on_addr (const uint16_t *map, uint16_t addr) |
Whether the map map fits an INA3221 at addr. | |
| static bool | map_ok (const uint16_t *m, const uint16_t *sense) |
| The map's own rules, whatever the bus. | |
| static void | mirror (const uint16_t *m, const uint16_t *sense, uint16_t *next) |
| SENSE's set-up with the map mirrored into ENABLE bit 1 and registers 8 to 10. | |
| static bool | bus_differs (const uint16_t *a, const uint16_t *b) |
| Whether two maps differ in what core 1 reads: ENABLE, FAST, a shunt. | |
| void | sense_map_read (const sense_page_t *p, uint8_t off, uint8_t n, uint16_t *out) |
| A SENSE_MAP read. | |
| uint8_t | sense_map_write (sense_page_t *p, uint8_t off, uint8_t n, const uint16_t *in, const outputs_t *o, uint64_t taken) |
| A SENSE_MAP write, merged into the map in force (or the derived one) and the whole map judged before any of it is stored. | |
| void | sense_xwin_read (const sense_page_t *p, unsigned page, uint8_t off, uint8_t n, uint16_t *out) |
A SENSE_WIN_A (page 0) or SENSE_WIN_B (1) read; no write is taken. | |
| bool | sense_map_watches (const sense_page_t *p) |
| Whether a channel the map reads watches an output channel or a programming port: the map in force's LINK_CAP_SERVO_SENSE. | |
| void | sense_map_kept (const sense_page_t *p, uint16_t *kept, uint16_t *set) |
What is kept: registers 0 to 25 (LINK_SM_KEPT) into kept, and 1 into set while the map is in force, else 0 (the registers then the derived ones). | |
| uint8_t | sense_map_restore (sense_page_t *p, const uint16_t *kept, uint16_t set, const outputs_t *o, uint64_t taken) |
A kept map back in force at boot, through sense_map_write()'s checks, after SENSE's restore: nothing when set is 0. | |
| void | sense_map_cfg (const uint16_t *map, sense_i3221_cfg_t *out) |
| The map's kept registers as the schedule's INA3221 set-up. | |
| static uint16_t | entry_flags (const sense_window_t *w) |
| The flags of one SENSE_WIN entry: which samples it holds and which clip. | |
| void | sense_map_publish (sense_page_t *p, const sense_snap_t *s) |
| The snapshot's per-part state into SENSE_MAP's read-only registers, and every channel's window into SENSE_WIN_A and SENSE_WIN_B. | |
The SENSE_MAP, SENSE_WIN_A and SENSE_WIN_B link pages.
See sense_map.h.
SPDX-License-Identifier: MIT
|
static |
Whether two maps differ in what core 1 reads: ENABLE, FAST, a shunt.
| a | The first map. |
| b | The second map. |
|
static |
The map SENSE's one part makes: what a read shows and a first write starts from.
| p | The SENSE page state. Its set-up registers are read. |
| m | Receives LINK_SM_KEPT registers. An address outside the INA3221 range leaves them at the defaults of FAST and zero for the rest. |
|
static |
The flags of one SENSE_WIN entry: which samples it holds and which clip.
| w | The channel's window. |
|
static |
Whether INA3221 part a is fitted: its bit in ENABLE is set.
| m | The map registers. |
| a | Part index, 0 to LINK_SM_PARTS - 1. |
|
static |
The kept registers in force, or derived into buf.
| p | The SENSE page state. |
| buf | Receives the derived map when the map is not in force. |
buf.
|
static |
The map's own rules, whatever the bus.
| m | The map to judge, LINK_SM_KEPT registers. |
| sense | The SENSE page's set-up registers, read for the INA228 check. |
|
static |
SENSE's set-up with the map mirrored into ENABLE bit 1 and registers 8 to 10.
With no part fitted only the bit clears.
| m | The map in force. |
| sense | The SENSE page's set-up registers. |
| next | Receives the mirrored set-up, LINK_SN_CONFIG_COUNT registers. |
| void sense_map_cfg | ( | const uint16_t * | map, |
| sense_i3221_cfg_t * | out ) |
The map's kept registers as the schedule's INA3221 set-up.
| map | The map's registers. |
| out | Receives the INA3221 set-up of the schedule. |
| void sense_map_kept | ( | const sense_page_t * | p, |
| uint16_t * | kept, | ||
| uint16_t * | set ) |
What is kept: registers 0 to 25 (LINK_SM_KEPT) into kept, and 1 into set while the map is in force, else 0 (the registers then the derived ones).
Nothing is done when any pointer is NULL.
| p | The SENSE page state. |
| kept | Receives LINK_SM_KEPT registers. |
| set | Receives 1 while the map is in force, 0 otherwise. |
| bool sense_map_on_addr | ( | const uint16_t * | map, |
| uint16_t | addr ) |
Whether the map map fits an INA3221 at addr.
| map | The map's registers. |
| addr | The INA3221 address. |
| void sense_map_publish | ( | sense_page_t * | p, |
| const sense_snap_t * | s ) |
The snapshot's per-part state into SENSE_MAP's read-only registers, and every channel's window into SENSE_WIN_A and SENSE_WIN_B.
| p | The page, updated in place. |
| s | The snapshot. |
| void sense_map_read | ( | const sense_page_t * | p, |
| uint8_t | off, | ||
| uint8_t | n, | ||
| uint16_t * | out ) |
A SENSE_MAP read.
Registers 0 to 25 are the map in force, or the one derived from SENSE; 26 to 30 what core 1 last read; 31 reads 0.
Nothing is done when p or out is NULL, or when off and n reach past LINK_SM_COUNT.
| p | The SENSE page state. |
| off | First register, 0 to LINK_SM_COUNT - 1. |
| n | Number of registers to read. |
| out | Receives the n register values. |
| uint8_t sense_map_restore | ( | sense_page_t * | p, |
| const uint16_t * | kept, | ||
| uint16_t | set, | ||
| const outputs_t * | o, | ||
| uint64_t | taken ) |
A kept map back in force at boot, through sense_map_write()'s checks, after SENSE's restore: nothing when set is 0.
0, or the refusal, which leaves the map derived.
| p | The SENSE page state. |
| kept | The kept registers, LINK_SM_KEPT of them. |
| set | 1 when the kept map was in force, 0 for nothing to restore. |
| o | The outputs bank, as sense_map_write() takes it. |
| taken | Passed to sense_map_write() unchanged. |
set is 0 or the map is taken. Otherwise the refusal of sense_map_write(). | bool sense_map_watches | ( | const sense_page_t * | p | ) |
Whether a channel the map reads watches an output channel or a programming port: the map in force's LINK_CAP_SERVO_SENSE.
| p | The page. |
| uint8_t sense_map_write | ( | sense_page_t * | p, |
| uint8_t | off, | ||
| uint8_t | n, | ||
| const uint16_t * | in, | ||
| const outputs_t * | o, | ||
| uint64_t | taken ) |
A SENSE_MAP write, merged into the map in force (or the derived one) and the whole map judged before any of it is stored.
Refused: off the page (BAD_RANGE); a register from 26 on (READ_ONLY); ENABLE above 15, FAST not 0xFF and past 11, on a part not fitted or on a channel whose shunt is 0, a shunt not 0 outside 50 to 10000, a WATCH value outside the list, a fitted part with no channel, a fitted part on the INA228's address while SENSE enables it, the mirrored SENSE set-up refused as a SENSE write would be (its pins, while the map opens the bus), and any change while o drives (BAD_VALUE). A map taken is in force from then on; a change of ENABLE, FAST or a shunt is a new set-up (the generation moves, the readings go), a change of WATCH alone is not.
| p | The SENSE page state, changed only when the write is taken. |
| off | First register, 0 to LINK_SM_COUNT - 1. |
| n | Number of registers to write. 0 is taken with no change. |
| in | The n new register values. |
| o | The outputs bank, checked for a change while it drives. |
| taken | Passed to sense_cfg_check() unchanged. |
o drives, or a map that fails the rules above. The refusal of sense_cfg_check() when the mirrored SENSE set-up is refused. | void sense_xwin_read | ( | const sense_page_t * | p, |
| unsigned | page, | ||
| uint8_t | off, | ||
| uint8_t | n, | ||
| uint16_t * | out ) |
A SENSE_WIN_A (page 0) or SENSE_WIN_B (1) read; no write is taken.
Nothing is done when p or out is NULL, page is above 1, or off and n reach past LINK_SX_COUNT.
| p | The SENSE page state. |
| page | 0 for SENSE_WIN_A, 1 for SENSE_WIN_B. |
| off | First register, 0 to LINK_SX_COUNT - 1. |
| n | Number of registers to read. |
| out | Receives the n register values. |
|
static |
Whether a WATCH value is one the map accepts.
Accepted: none, an output channel from OUT(0) to OUT(7), a programming port from PORT(0) below LINK_PG_PORTS_MAX, and the supply.
| w | The WATCH register value. |