rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
port_mail.h
1/*
2 * The programming ports between the panel's control task and its UI
3 * task: the PROG page as the screens draw it (port_view.h), and the
4 * operator's asks for a port's PIN or FUNC on the way back
5 * (prog_link_ask()).
6 *
7 * The view crosses in two words under a generation count (a sequence
8 * lock): the control task makes the count odd, stores both words and
9 * makes it even again; the UI task takes a pair read between two equal,
10 * even counts and keeps its last view when 8 tries in a row are torn. A
11 * frame never draws one read's pins with another's functions.
12 *
13 * An ask crosses as one word: its number (1 to 255), the link epoch of
14 * the view it was made on, the port, the kind and the value. The control
15 * task hands a new number to prog_link_ask() once, and only in the epoch
16 * it was made in. Each link loss starts a new epoch and makes the last
17 * ask LOST, whether it was handed on or still waited in the word, so an
18 * ask made for one IOmcu is never written to the one that answers after
19 * the loss. How the ask stands crosses back in one word under the same
20 * number. The number wraps from 255 to 1, so a post first sets that word
21 * to WAITING under its number: a final state the word kept from the
22 * number's last use never stands for the new ask.
23 *
24 * One writer per side: port_mail_publish() and port_mail_lost() on the
25 * control task, port_mail_post() and port_mail_to_view() on the UI task;
26 * the ask's state word is the control task's but for that WAITING.
27 *
28 * SPDX-License-Identifier: MIT
29 */
30#pragma once
31
32#include <stdatomic.h>
33#include <stdbool.h>
34#include <stdint.h>
35
36#include "prog_link.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42typedef struct {
43 atomic_uint pins;
44 atomic_uint meta;
45 atomic_uint gen;
46 atomic_uint ask;
47 atomic_uint ask_state;
48 uint8_t taken;
49 unsigned epoch;
50 unsigned ui_epoch;
52
54#define PORT_MAIL_META_UNKNOWN 0x00FF7777u
55#define PORT_MAIL_INIT { 0xFFFFFFFFu, PORT_MAIL_META_UNKNOWN, 0u, 0u, 0u, \
56 0u, 0u, 0u }
57
64void port_mail_publish(port_mail_t *m, prog_link_t *pl);
65
68void port_mail_lost(port_mail_t *m);
69
75bool port_mail_post(port_mail_t *m, uint8_t seq, uint8_t port,
76 prog_link_ask_kind_t kind, uint16_t value);
77
79void port_mail_to_view(port_mail_t *m);
80
81#ifdef __cplusplus
82}
83#endif
Definition port_mail.h:42
unsigned epoch
Definition port_mail.h:49
unsigned ui_epoch
Definition port_mail.h:50
atomic_uint ask
Definition port_mail.h:46
atomic_uint ask_state
Definition port_mail.h:47
atomic_uint gen
Definition port_mail.h:45
atomic_uint pins
Definition port_mail.h:43
uint8_t taken
Definition port_mail.h:48
atomic_uint meta
Definition port_mail.h:44