rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
link_host.h
Go to the documentation of this file.
1
12#ifndef RCBENCH_LINK_HOST_H
13#define RCBENCH_LINK_HOST_H
14
15#include <stdbool.h>
16#include <stddef.h>
17#include <stdint.h>
18
19#include "link_msg.h"
20#include "link_pages.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
30#define LINK_HOST_TIMEOUT_MS 1000u
31
35typedef struct {
36 /* The outstanding question, kept so an answer to an older one cannot be
37 * mistaken for an answer to this one. */
38 bool pending;
39 uint8_t op;
40 uint8_t page;
41 uint8_t offset;
42 uint8_t count;
43
44 uint32_t sent_ms;
45 uint32_t last_reply_ms;
46 bool escalated;
47
48 uint32_t polls;
49 uint32_t replies;
50 uint32_t mismatches;
51 uint32_t nacks;
52 uint32_t timeouts;
53
54 /*
55 * Reassembly. A CAN (Controller Area Network) frame carries four
56 * registers, so a reply to a 13-register read arrives as four messages,
57 * each with its own offset and count. There is no sequence to follow
58 * and no continuation to wait for: the window asked for is known here,
59 * and a bit is set as each part of it lands.
60 */
61 uint16_t acc[LINK_MAX_REGS];
62 uint32_t acc_seen;
64
71void link_host_init(link_host_t *h, uint32_t now_ms);
72
87bool link_host_read(link_host_t *h, uint8_t page, uint8_t offset,
88 uint8_t count, uint32_t now_ms, link_msg_t *out);
101bool link_host_write(link_host_t *h, uint8_t page, uint8_t offset,
102 uint8_t count, const uint16_t *regs, uint32_t now_ms,
103 link_msg_t *out);
104
124bool link_host_accept(link_host_t *h, const link_msg_t *part, uint32_t now_ms,
125 link_msg_t *whole);
126
142bool link_host_tick(link_host_t *h, uint32_t now_ms);
143
153
165bool link_host_pending(const link_host_t *h);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* RCBENCH_LINK_HOST_H */