|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The panel's half of the TONE link page. More...
Macros | |
| #define | FRAME_N 4u |
| #define | FRAME0_AT ((uint8_t)LINK_TN_ENABLE) |
| #define | FRAME1_AT ((uint8_t)LINK_TN_SPLIT_PCT) |
| #define | FRAME1_CFG (LINK_TN_CONFIG_COUNT - (unsigned)LINK_TN_SPLIT_PCT) |
| #define | CYCLE 65535u |
| #define | ST(reg) |
| #define | RESTART_BEHIND 1024u |
Functions | |
| static unsigned | pos_of (uint16_t n) |
| The position of a beep number in the ring. | |
| static uint16_t | num_of (unsigned pos) |
| The beep number at a position in the ring. | |
| static uint16_t | succ_of (uint16_t n) |
The number after n, and the one before. | |
| static uint16_t | pred_of (uint16_t n) |
| The number before a beep. | |
| static unsigned | dist (uint16_t from, uint16_t to) |
Beeps from from, the last one taken, to to, the newest. | |
| void | tone_link_init (tone_link_t *t) |
| Sets up the tone link state. | |
| void | tone_link_lost (tone_link_t *t) |
| The link went: nothing on the page is known, and nothing is read or written until it comes up again. | |
| void | tone_link_came_up (tone_link_t *t, uint16_t minor, uint32_t now_ms) |
An IOmcu answered with protocol minor minor. | |
| static bool | setup_valid (const tone_setup_t *w) |
Whether w is a set-up SETUP can name: every value inside the page's own range. | |
| void | tone_link_want (tone_link_t *t, const tone_setup_t *w, uint32_t now_ms) |
| The set-up SETUP names now. | |
| static bool | pair_valid (unsigned f_min, unsigned f_max, unsigned gap_ms) |
| Whether a tone range and a gap are a set-up the page takes: the high tone above the low one, and a silence at least one period of the low tone long. | |
| static bool | frame0_differs (const tone_link_t *t) |
| Whether the wanted first frame differs from the held one. | |
| static bool | frame1_differs (const tone_link_t *t) |
| Whether the wanted second frame differs from the held one. | |
| static bool | pin_retry_due (const tone_link_t *t, uint32_t now_ms) |
| Whether the first frame is owed again for a pin something else holds: the page's FLAGS say the saved tap met a busy pin at boot, the page holds what is asked, and TONE_LINK_RETRY_MS have passed since the last try. | |
| static tone_link_op_kind_t | write_owed (const tone_link_t *t, uint16_t *regs, bool retry) |
The write owed now, or NONE, with its registers in regs. | |
| static void | read_op (tone_link_op_t *op, tone_link_op_kind_t kind, uint8_t off, uint8_t n) |
| Sets up a read operation of the TONE page. | |
| static unsigned | owed (const tone_link_t *t) |
| Beeps the page has that the panel has not taken, by the last status. | |
| bool | tone_link_next (tone_link_t *t, uint32_t now_ms, tone_link_op_t *op) |
The next exchange owed at now_ms, into op; false for none. | |
| static bool | may_pass_later (const tone_link_t *t, int result) |
Whether a first frame refused with result may pass later, unchanged: the page said its pin is busy. | |
| static void | written (tone_link_t *t, tone_link_op_kind_t w, int result, uint32_t now_ms) |
| Handles the result of a write. | |
| static void | judge_status (tone_link_t *t) |
| What a status read says that the operator is told: a pin that is not free and an overrun, each on its edge. | |
| static void | note_window (tone_link_t *t, uint32_t now_ms) |
| When WINDOW last moved, after a status read. | |
| static void | follow_head (tone_link_t *t) |
| Where the panel stands against BEEP_HEAD after a status read. | |
| static void | take_beep (tone_link_t *t, const uint16_t *r) |
| Takes the beep a read holds into the panel's history. | |
| void | tone_link_done (tone_link_t *t, int result, const uint16_t *regs, uint32_t now_ms) |
How the exchange tone_link_next() gave went: TONE_LINK_ACK with the registers read (regs, op.n of them; NULL for a write), a NACK reason, or TONE_LINK_NO_ANSWER. | |
| bool | tone_link_event_stands (const tone_link_t *t, uint16_t ev) |
Whether what ev, one TONE_LINK_EV_* bit, says still holds now. | |
| uint16_t | tone_link_event (tone_link_t *t, uint32_t now_ms) |
| One event for the alert band, which shows one line and replaces it with the next: the most pressing waiting, cleared, and the rest kept. | |
| void | tone_link_event_back (tone_link_t *t, uint16_t ev) |
| Put back an event tone_link_event() handed out that never reached the band, so it is handed out again after the gap. | |
| bool | tone_link_settled (const tone_link_t *t) |
| Whether nothing is owed: the page holds the set-up asked, less the frames it refused. | |
| uint8_t | tone_link_unheld (const tone_link_t *t) |
| The frames whose values as asked are not the ones the page holds, TONE_LINK_ROWS_*: not written yet, or refused. | |
| unsigned | tone_link_beeps (const tone_link_t *t, tone_beep_t *out, unsigned max) |
The beeps the panel has read, newest first, at most max; how many. | |
| uint32_t | tone_link_read_count (const tone_link_t *t) |
| Beeps read since init, and beeps the panel did not read: the ring moved past them, or the page no longer held them. | |
| uint32_t | tone_link_missed (const tone_link_t *t) |
| Counts the beeps the panel did not read. | |
| uint16_t | tone_link_flags (const tone_link_t *t) |
| FLAGS as last read, 0 before any read. | |
| static tone_state_t | state_of (const tone_link_t *t, bool fresh, bool *read) |
What the tap is doing, as the screen words it; fresh says the last status read is recent enough to speak for the page. | |
| void | tone_link_readout (const tone_link_t *t, uint32_t now_ms, tone_readout_t *r) |
The screen's copy of everything above, at now_ms. | |
| unsigned | tone_link_pin (const tone_link_t *t) |
| The pin and the tone range asked, for the alerts' text. | |
| unsigned | tone_link_f_min (const tone_link_t *t) |
| The lower end of the tone range asked, for the alerts' text. | |
| unsigned | tone_link_f_max (const tone_link_t *t) |
| The upper end of the tone range asked, for the alerts' text. | |
| bool | tone_link_held_pin (const tone_link_t *t, int *pin) |
| The tap's pin the page holds by its last read or write, as the IOmcu reserves it (tone_page_pins()): the pin while ENABLE has the tap on and the last status read does not say the pin refused, -1 otherwise and while the IOmcu has no TONE page. | |
| #define ST | ( | reg | ) |
|
static |
Beeps from from, the last one taken, to to, the newest.
| from | The last beep taken. |
| to | The newest beep. |
|
static |
Where the panel stands against BEEP_HEAD after a status read.
| t | The link state. |
|
static |
Whether the wanted first frame differs from the held one.
| t | The link state. |
|
static |
Whether the wanted second frame differs from the held one.
| t | The link state. |
|
static |
What a status read says that the operator is told: a pin that is not free and an overrun, each on its edge.
| t | The link state. |
|
static |
Whether a first frame refused with result may pass later, unchanged: the page said its pin is busy.
A 4.17 page says BUSY for that and BAD_VALUE for a set-up no freed pin makes good. An older page says BAD_VALUE for both, so its refusal may pass later unless the panel sees the frame's own values fail: a high tone not above the low one, or the gap held too short for the low tone.
| t | The link state. |
| result | The NACK reason. |
|
static |
When WINDOW last moved, after a status read.
A page that does not run reads WINDOW 0 and is not judged by it: each such read counts as a move, so a capture that starts has TONE_LINK_WINDOW_STALE_MS from the last read that found it not running to show its first window.
| t | The link state. |
| now_ms | The time, in ms. |
|
static |
The beep number at a position in the ring.
| pos | The position. |
|
static |
Beeps the page has that the panel has not taken, by the last status.
| t | The link state. |
|
static |
Whether a tone range and a gap are a set-up the page takes: the high tone above the low one, and a silence at least one period of the low tone long.
| f_min | The low tone, in Hz. |
| f_max | The high tone, in Hz. |
| gap_ms | The silence, in ms. |
|
static |
Whether the first frame is owed again for a pin something else holds: the page's FLAGS say the saved tap met a busy pin at boot, the page holds what is asked, and TONE_LINK_RETRY_MS have passed since the last try.
| t | The link state. |
| now_ms | The time, in ms. |
|
static |
The position of a beep number in the ring.
| n | The beep number. |
|
static |
The number before a beep.
| n | The beep number. |
|
static |
Sets up a read operation of the TONE page.
| op | Receives the operation. |
| kind | The operation kind. |
| off | The first register. |
| n | The number of registers. |
|
static |
Whether w is a set-up SETUP can name: every value inside the page's own range.
A zeroed one – a snapshot nobody has published into – is not, and is no reason to write anything. F_MAX_HZ above F_MIN_HZ and a GAP_MS as long as F_MIN_HZ's period are for the page to judge.
| w | The set-up. |
|
static |
What the tap is doing, as the screen words it; fresh says the last status read is recent enough to speak for the page.
read, false on the call, is set when the state is the one that read gives, so its values are current.
| t | The link state. |
| fresh | true when the last status read is recent enough to speak for the page. |
| read | Set when the state comes from the page read; false on entry. |
|
static |
The number after n, and the one before.
| n | The beep number. |
|
static |
Takes the beep a read holds into the panel's history.
| t | The link state. |
| r | The registers read. |
| unsigned tone_link_beeps | ( | const tone_link_t * | t, |
| tone_beep_t * | out, | ||
| unsigned | max ) |
The beeps the panel has read, newest first, at most max; how many.
| t | The link state. |
| out | Receives the beeps, newest first. |
| max | The number of entries out holds. |
| void tone_link_came_up | ( | tone_link_t * | t, |
| uint16_t | minor, | ||
| uint32_t | now_ms ) |
An IOmcu answered with protocol minor minor.
Below TONE_LINK_MINOR it has no page and nothing is sent to it, and the tap enabled on SETUP raises TONE_LINK_EV_NO_PAGE.
| t | The link state. |
| minor | The IOmcu's protocol minor version. |
| now_ms | The time, in ms. |
| void tone_link_done | ( | tone_link_t * | t, |
| int | result, | ||
| const uint16_t * | regs, | ||
| uint32_t | now_ms ) |
How the exchange tone_link_next() gave went: TONE_LINK_ACK with the registers read (regs, op.n of them; NULL for a write), a NACK reason, or TONE_LINK_NO_ANSWER.
| t | The link state. |
| result | The result: an acknowledgement, a NACK's reason or TONE_LINK_NO_ANSWER. |
| regs | The registers read, or NULL for a write. |
| now_ms | The time, in ms. |
| uint16_t tone_link_event | ( | tone_link_t * | t, |
| uint32_t | now_ms ) |
One event for the alert band, which shows one line and replaces it with the next: the most pressing waiting, cleared, and the rest kept.
0 while none waits or while the last one handed out is younger than TONE_LINK_EVENT_GAP_MS at now_ms.
| t | The link state. |
| now_ms | The time, in ms. |
| void tone_link_event_back | ( | tone_link_t * | t, |
| uint16_t | ev ) |
Put back an event tone_link_event() handed out that never reached the band, so it is handed out again after the gap.
An event about an IOmcu is not put back once the link has gone.
| t | The link state. |
| ev | The event to put back. |
| bool tone_link_event_stands | ( | const tone_link_t * | t, |
| uint16_t | ev ) |
Whether what ev, one TONE_LINK_EV_* bit, says still holds now.
A refused frame – TONE_LINK_EV_PIN_REFUSED for the first, TONE_LINK_EV_SETUP_REFUSED for the second – until the page is known to hold that frame as asked: not refused, and written and taken. A value stepped back on SETUP ends it once the IOmcu takes the frame, after TONE_LINK_SETTLE_MS and a poll. TONE_LINK_EV_PIN_BUSY until the tap is off as asked and held, or a status read under the first frame as asked shows its pin taken (FLAGS bit 1 clear). With no IOmcu answering they stand. True for every other event.
The caller takes back an alert it showed for such an event once this is false; tone_link_event() drops one waiting that is over.
| t | The link state. |
| ev | One TONE_LINK_EV_* bit. |
| unsigned tone_link_f_max | ( | const tone_link_t * | t | ) |
The upper end of the tone range asked, for the alerts' text.
| t | The link state. |
| unsigned tone_link_f_min | ( | const tone_link_t * | t | ) |
The lower end of the tone range asked, for the alerts' text.
| t | The link state. |
| uint16_t tone_link_flags | ( | const tone_link_t * | t | ) |
FLAGS as last read, 0 before any read.
| t | The link state. |
| bool tone_link_held_pin | ( | const tone_link_t * | t, |
| int * | pin ) |
The tap's pin the page holds by its last read or write, as the IOmcu reserves it (tone_page_pins()): the pin while ENABLE has the tap on and the last status read does not say the pin refused, -1 otherwise and while the IOmcu has no TONE page.
False, -1, while that is not known: no link, or no read yet. pin may be NULL.
| t | The link state. |
| pin | Receives the pin, or -1 while not known; may be NULL. |
| void tone_link_init | ( | tone_link_t * | t | ) |
Sets up the tone link state.
| t | The link state to set up. |
| void tone_link_lost | ( | tone_link_t * | t | ) |
The link went: nothing on the page is known, and nothing is read or written until it comes up again.
The beep history stays on screen.
| t | The link state. |
| uint32_t tone_link_missed | ( | const tone_link_t * | t | ) |
Counts the beeps the panel did not read.
| t | The link state. |
| bool tone_link_next | ( | tone_link_t * | t, |
| uint32_t | now_ms, | ||
| tone_link_op_t * | op ) |
The next exchange owed at now_ms, into op; false for none.
The caller makes the exchange and reports with tone_link_done().
| t | The link state. |
| now_ms | The time, in ms. |
| op | Receives the exchange owed. |
| unsigned tone_link_pin | ( | const tone_link_t * | t | ) |
The pin and the tone range asked, for the alerts' text.
| t | The link state. |
| uint32_t tone_link_read_count | ( | const tone_link_t * | t | ) |
Beeps read since init, and beeps the panel did not read: the ring moved past them, or the page no longer held them.
| t | The link state. |
| void tone_link_readout | ( | const tone_link_t * | t, |
| uint32_t | now_ms, | ||
| tone_readout_t * | r ) |
The screen's copy of everything above, at now_ms.
The status's values are filled only while tone_readout_t.read holds; the beeps and the missed count are the panel's own and stay.
| t | The link state. |
| now_ms | The time, in ms. |
| r | Receives the copy. |
| bool tone_link_settled | ( | const tone_link_t * | t | ) |
Whether nothing is owed: the page holds the set-up asked, less the frames it refused.
| t | The link state. |
| uint8_t tone_link_unheld | ( | const tone_link_t * | t | ) |
The frames whose values as asked are not the ones the page holds, TONE_LINK_ROWS_*: not written yet, or refused.
The comparison is want against held, the two this module writes from. 0 while no IOmcu answers and before the page has been read. An IOmcu without the page holds no tap, and a tap that is on is named.
| t | The link state. |
| void tone_link_want | ( | tone_link_t * | t, |
| const tone_setup_t * | w, | ||
| uint32_t | now_ms ) |
The set-up SETUP names now.
The tap enabled while an IOmcu without the page answers raises TONE_LINK_EV_NO_PAGE. A set-up with a value outside the page's range – a zeroed snapshot – is ignored: nothing is asked, and nothing is written for it.
| t | The link state. |
| w | The set-up SETUP names. |
| now_ms | The time, in ms. |
|
static |
The write owed now, or NONE, with its registers in regs.
retry counts a first frame owed again for a busy pin.
| t | The link state. |
| regs | Receives the registers of the write. |
| retry | true to count a first frame owed again for a busy pin. |
|
static |
Handles the result of a write.
| t | The link state. |
| w | The write. |
| result | The result: an acknowledgement, a NACK reason or no answer. |
| now_ms | The time, in ms. |