rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Toggle main menu visibility
Loading...
Searching...
No Matches
can_selftest.h
1
/*
2
* The CAN (Controller Area Network) echo self-test: the first check when two
3
* nodes are wired together.
4
*
5
* It answers one question: do frames cross this bus intact? The initiator
6
* sends a frame with a sequence number and a payload, the responder sends it
7
* back unchanged, and the initiator compares it byte for byte. No page map,
8
* no registers, no state machine above it. A passing test with a link that
9
* does not work places the fault above the wire. A wrong bit timing, a
10
* missing terminator, a transceiver in the wrong mode and a dispatcher bug
11
* all present as a panel that shows no numbers; this test separates the
12
* first three from the fourth.
13
*
14
* The payloads exercise bit stuffing. CAN stuffs a complementary bit after
15
* five bits of the same polarity, so a marginal bus fails on long runs of one
16
* level. The first two payload bytes carry the sequence number; the other
17
* six carry one of four patterns selected by it (0x00, 0xFF, 0x55, 0xAA),
18
* and the echo is checked against the pattern it was sent with.
19
*
20
* The test runs at the lowest arbitration priority on a page the map does
21
* not use, so it can run beside normal traffic without delaying it.
22
*
23
* SPDX-License-Identifier: MIT
24
*/
25
26
#ifndef RCBENCH_CAN_SELFTEST_H
27
#define RCBENCH_CAN_SELFTEST_H
28
29
#include <stdbool.h>
30
#include <stdint.h>
31
32
#include "
link_can.h
"
33
34
#ifdef __cplusplus
35
extern
"C"
{
36
#endif
37
40
#define CAN_SELFTEST_PAGE 0x7Eu
41
43
#define CAN_SELFTEST_MIN_PROBES 8u
44
45
typedef
enum
{
46
CAN_SELFTEST_RUNNING = 0,
47
CAN_SELFTEST_OK,
49
CAN_SELFTEST_SILENT,
51
CAN_SELFTEST_CORRUPT,
54
CAN_SELFTEST_LOSSY,
63
CAN_SELFTEST_DROPPED,
64
} can_selftest_verdict_t;
65
66
typedef
struct
{
67
uint32_t sent;
68
uint32_t
echoed
;
69
uint32_t timed_out;
70
uint32_t
corrupt
;
71
uint32_t
stale
;
72
73
uint16_t
seq
;
74
uint16_t
outstanding
;
75
bool
waiting;
76
uint32_t sent_ms;
77
uint32_t timeout_ms;
78
79
uint32_t rtt_min_us;
80
uint32_t rtt_max_us;
81
88
uint32_t
bus_errors
;
89
}
can_selftest_t
;
90
91
void
can_selftest_init(
can_selftest_t
*st, uint32_t timeout_ms);
92
100
bool
can_selftest_probe(
can_selftest_t
*st, uint32_t now_ms,
101
link_can_frame_t
*out);
102
108
bool
can_selftest_rx(
can_selftest_t
*st,
const
link_can_frame_t
*f,
109
uint32_t rtt_us);
110
112
bool
can_selftest_tick(
can_selftest_t
*st, uint32_t now_ms);
113
114
can_selftest_verdict_t can_selftest_verdict(
const
can_selftest_t
*st);
115
const
char
*can_selftest_text(can_selftest_verdict_t v);
116
const
char
*can_selftest_hint(can_selftest_verdict_t v);
117
118
/* ----------------------------------------------- the far end's own numbers */
119
120
/*
121
* The IOmcu's view of the bus, carried across the bus in one 8-byte
122
* frame on the self-test page at the lowest priority, so one console shows
123
* both ends of a fault.
124
*
125
* It is polled: the IOmcu transmits only in answer to a request.
126
*/
127
typedef
struct
{
128
bool
up
;
130
uint8_t
tx_errors
;
131
uint8_t
rx_errors
;
132
uint8_t
flags
;
133
uint16_t
echoes
;
134
uint16_t
overflows
;
135
}
can_remote_status_t
;
136
138
bool
can_selftest_status_request(
link_can_frame_t
*out);
139
141
bool
can_selftest_status_reply(
const
link_can_frame_t
*in,
142
const
can_remote_status_t
*st,
143
link_can_frame_t
*out);
144
146
bool
can_selftest_status_parse(
const
link_can_frame_t
*in,
147
can_remote_status_t
*out);
148
164
uint16_t can_selftest_return_loss(uint16_t before, uint16_t after,
165
uint32_t heard);
166
167
/* ------------------------------------------------------------- responder */
168
174
bool
can_selftest_echo(
const
link_can_frame_t
*in,
link_can_frame_t
*out);
175
176
#ifdef __cplusplus
177
}
178
#endif
179
180
#endif
/* RCBENCH_CAN_SELFTEST_H */
link_can.h
The page protocol over CAN (Controller Area Network).
can_remote_status_t
Definition
can_selftest.h:127
can_remote_status_t::up
bool up
Definition
can_selftest.h:128
can_remote_status_t::rx_errors
uint8_t rx_errors
Definition
can_selftest.h:131
can_remote_status_t::echoes
uint16_t echoes
Definition
can_selftest.h:133
can_remote_status_t::tx_errors
uint8_t tx_errors
Definition
can_selftest.h:130
can_remote_status_t::overflows
uint16_t overflows
Definition
can_selftest.h:134
can_remote_status_t::flags
uint8_t flags
Definition
can_selftest.h:132
can_selftest_t
Definition
can_selftest.h:66
can_selftest_t::bus_errors
uint32_t bus_errors
Definition
can_selftest.h:88
can_selftest_t::outstanding
uint16_t outstanding
Definition
can_selftest.h:74
can_selftest_t::seq
uint16_t seq
Definition
can_selftest.h:73
can_selftest_t::corrupt
uint32_t corrupt
Definition
can_selftest.h:70
can_selftest_t::stale
uint32_t stale
Definition
can_selftest.h:71
can_selftest_t::echoed
uint32_t echoed
Definition
can_selftest.h:68
link_can_frame_t
One CAN frame: its identifier and up to 8 payload bytes.
Definition
link_can.h:93
shared
can
include
can_selftest.h
Generated by
1.18.0