Loading...
Searching...
No Matches
clock_alignment.c
Go to the documentation of this file.
30_Static_assert(sizeof(union usher_clock_reply_union) == USHER_CLOCK_REPLY_MSG_SIZE, "Clock reply wire size");
31_Static_assert(sizeof(union usher_pose_clocked_union) == USHER_POSE_CLOCKED_MSG_SIZE, "Clocked pose wire size");
34static bool same_token(union usher_clock_request_union first, union usher_clock_request_union second)
36 return first.data.token_low == second.data.token_low && first.data.token_high == second.data.token_high;
39bool clock_alignment_request(struct clock_alignment *clock, union usher_clock_request_union token, uint64_t sent_us)
43 || same_token(token, clock->pending_token) || same_token(token, clock->mapped_token)) return false;
50bool clock_alignment_reply(struct clock_alignment *clock, const uint8_t *payload, size_t length, uint64_t received_us)
52 if (clock == NULL || !clock->pending || payload == NULL || length != USHER_CLOCK_REPLY_MSG_SIZE) return false;
58 if (received_us < clock->sent_us || received_us > UINT64_MAX - CLOCK_ALIGNMENT_MAX_AGE_US - 10000
62 const uint64_t service_min_us = (uint64_t)service_us * 1000000 / (1000000 + CLOCK_ALIGNMENT_DRIFT_PPM);
75bool clock_alignment_map(const struct clock_alignment *clock, union usher_clock_request_union token,
78 if (clock == NULL || interval == NULL || !clock->valid || !same_token(token, clock->mapped_token)
79 || now_us < clock->received_us || now_us - clock->received_us > CLOCK_ALIGNMENT_MAX_AGE_US) return false;
bool clock_alignment_reply(struct clock_alignment *clock, const uint8_t *payload, size_t length, uint64_t received_us)
Validate a flight-controller clock reply and establish a mapping anchor.
Definition clock_alignment.c:50
bool clock_alignment_request(struct clock_alignment *clock, union usher_clock_request_union token, uint64_t sent_us)
Register a newly transmitted clock probe.
Definition clock_alignment.c:39
static bool same_token(union usher_clock_request_union first, union usher_clock_request_union second)
Compare opaque wire tokens without depending on host structure padding.
Definition clock_alignment.c:34
bool clock_alignment_map(const struct clock_alignment *clock, union usher_clock_request_union token, uint32_t fc_us, uint64_t now_us, struct clock_interval *interval)
Project a controller timestamp into a conservative USHER time interval.
Definition clock_alignment.c:75
Bounded mapping between flight-controller microseconds and USHER monotonic time.
Stateful evidence for at most one pending and one accepted clock probe.
Definition clock_alignment.h:47
union usher_clock_request_union pending_token
Definition clock_alignment.h:48
union usher_clock_request_union mapped_token
Definition clock_alignment.h:49
Inclusive USHER monotonic-time bounds for a mapped controller timestamp.
Definition clock_alignment.h:41
Definition usher_protocol.h:298
struct usher_clock_reply_union::@260221177250276350221210364003171064301345176114 data
union usher_clock_request_union request
Definition usher_protocol.h:300
struct usher_clock_request_union::@124322121054031044024143305010352315355331137256 data
Definition usher_protocol.h:307