rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
heartbeat.h
Go to the documentation of this file.
1
32
33#pragma once
34
35#include <stdbool.h>
36#include <stdint.h>
37
46#define HEARTBEAT_PERIOD_MS 20u
47
57#define HEARTBEAT_MIN_GAP_MS 4u
58#define HEARTBEAT_MAX_GAP_MS 150u
59
67#define HEARTBEAT_GOOD_RUN 4u
68
79#define HEARTBEAT_SETTLE_MS \
80 (HEARTBEAT_GOOD_RUN * HEARTBEAT_PERIOD_MS + HEARTBEAT_PERIOD_MS)
81
82/* ------------------------------------------------------- the panel's end */
83
84typedef struct {
85 uint32_t last_ms;
86 bool level;
87 bool started;
89
97
114bool heartbeat_gen_step(heartbeat_gen_t *g, uint32_t now_ms, bool alive);
115
116/* ------------------------------------------------ the IOmcu's end */
117
118typedef struct {
119 uint32_t last_edge_ms;
120 uint32_t good_run;
122 bool alive;
123 /* Kept for the status page: a line that is rejected is worth being able
124 * to ask about, and "how" narrows a fault far faster than "not alive". */
125 uint32_t rejected_fast;
126 uint32_t rejected_slow;
128
135
146void heartbeat_mon_edge(heartbeat_mon_t *m, uint32_t now_ms);
147
159bool heartbeat_mon_alive(heartbeat_mon_t *m, uint32_t now_ms);
void heartbeat_mon_edge(heartbeat_mon_t *m, uint32_t now_ms)
Record an edge on the safety line.
Definition heartbeat.c:74
bool heartbeat_mon_alive(heartbeat_mon_t *m, uint32_t now_ms)
Whether the line may be believed now.
Definition heartbeat.c:121
void heartbeat_mon_init(heartbeat_mon_t *m)
Start not alive, with no edge seen.
Definition heartbeat.c:67
void heartbeat_gen_init(heartbeat_gen_t *g)
Start held low: nothing downstream may run until this loop asks for it.
Definition heartbeat.c:25
bool heartbeat_gen_step(heartbeat_gen_t *g, uint32_t now_ms, bool alive)
Advance the generator; returns the level the pin should be driven to.
Definition heartbeat.c:32
Definition heartbeat.h:84
bool level
Definition heartbeat.h:86
bool started
Definition heartbeat.h:87
uint32_t last_ms
Definition heartbeat.h:85
Definition heartbeat.h:118
uint32_t rejected_slow
Definition heartbeat.h:126
uint32_t rejected_fast
Definition heartbeat.h:125
bool have_edge
Definition heartbeat.h:121
uint32_t good_run
Definition heartbeat.h:120