RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_startup_timestamp.h File Reference

The site startup timestamp A and B agree over the A/B peer link (ADR-040 step 5a): the agreement rule and the codec of the PEER_MSG_KIND_STARTUP_TS payload. Pure, no I/O (the ab_gp_standby_policy pattern); the exchange itself is exchange_startup_timestamp() in ab_gp_channel_negotiate.c. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "rte/utils/types/rte_types.h"
Include dependency graph for ab_gp_startup_timestamp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AB_GP_STARTUP_TS_FRESH_MS   3000U
#define AB_GP_STARTUP_TS_WAIT_MS   3000U
#define AB_GP_STARTUP_TS_READ_SLICE_MS   20U
#define AB_GP_STARTUP_TS_MAX_SLICES   ((AB_GP_STARTUP_TS_WAIT_MS / AB_GP_STARTUP_TS_READ_SLICE_MS) + 1U)
#define AB_GP_STARTUP_TS_PAYLOAD_SIZE   9U

Functions

rte_timestamp_ms_t ab_gp_startup_timestamp_agree (rte_timestamp_ms_t own_now_ms, rte_timestamp_ms_t sibling_ts_ms, bool have_sibling)
 The site startup timestamp this channel uses given its own clock and the sibling's value.
void ab_gp_startup_timestamp_encode (uint8_t *buf, bool is_reply, rte_timestamp_ms_t ts_ms)
 Encodes a STARTUP_TS payload.
bool ab_gp_startup_timestamp_decode (const uint8_t *buf, size_t size, bool *is_reply, rte_timestamp_ms_t *ts_ms)
 Decodes a STARTUP_TS payload.

Detailed Description

The site startup timestamp A and B agree over the A/B peer link (ADR-040 step 5a): the agreement rule and the codec of the PEER_MSG_KIND_STARTUP_TS payload. Pure, no I/O (the ab_gp_standby_policy pattern); the exchange itself is exchange_startup_timestamp() in ab_gp_channel_negotiate.c.

Both channels of a site present one timestamp to their independent inter-site tie-break (REQ-DUAL-NEGOTIATOR-003 / REQ-SITEROLE-014: older site wins), so A and B reach the same ONLINE/STANDBY verdict. The rule is the one the former /tmp/rte_site_<site>_ts.dat file applied: the sibling's value is adopted only when it is not newer than this process's own and less than AB_GP_STARTUP_TS_FRESH_MS older; otherwise the own value is kept, so a channel restarting next to a long-running sibling keeps a fresh timestamp. The rule is symmetric, so a simultaneous exchange gives both sides the same value.

Definition in file ab_gp_startup_timestamp.h.

Macro Definition Documentation

◆ AB_GP_STARTUP_TS_FRESH_MS

#define AB_GP_STARTUP_TS_FRESH_MS   3000U

A sibling value this much older than the own one (or more) is a long-running sibling, not a joint start: own kept.

Definition at line 24 of file ab_gp_startup_timestamp.h.

◆ AB_GP_STARTUP_TS_WAIT_MS

#define AB_GP_STARTUP_TS_WAIT_MS   3000U

Longest wait for the sibling's STARTUP_TS frame at start-up before the own value is used alone.

Definition at line 27 of file ab_gp_startup_timestamp.h.

◆ AB_GP_STARTUP_TS_READ_SLICE_MS

#define AB_GP_STARTUP_TS_READ_SLICE_MS   20U

The exchange reads the peer link in slices this long (ms).

Definition at line 30 of file ab_gp_startup_timestamp.h.

◆ AB_GP_STARTUP_TS_MAX_SLICES

#define AB_GP_STARTUP_TS_MAX_SLICES   ((AB_GP_STARTUP_TS_WAIT_MS / AB_GP_STARTUP_TS_READ_SLICE_MS) + 1U)

Hard bound on the exchange's read slices, independent of the clock: the loop ends after this many slices even if rte_timer_now() stalls or fails, so the wait is bounded by construction (AB_GP_STARTUP_TS_WAIT_MS worth of slices plus one).

Definition at line 35 of file ab_gp_startup_timestamp.h.

◆ AB_GP_STARTUP_TS_PAYLOAD_SIZE

#define AB_GP_STARTUP_TS_PAYLOAD_SIZE   9U

PEER_MSG_KIND_STARTUP_TS payload: is_reply(1) | timestamp_ms(8, little endian).

Definition at line 38 of file ab_gp_startup_timestamp.h.

Function Documentation

◆ ab_gp_startup_timestamp_agree()

rte_timestamp_ms_t ab_gp_startup_timestamp_agree ( rte_timestamp_ms_t own_now_ms,
rte_timestamp_ms_t sibling_ts_ms,
bool have_sibling )

The site startup timestamp this channel uses given its own clock and the sibling's value.

Parameters
own_now_msthis process's own monotonic time at start-up
sibling_ts_msthe sibling's startup timestamp (ignored when have_sibling is false)
have_siblinga sibling value was received
Returns
sibling_ts_ms when have_sibling, sibling_ts_ms <= own_now_ms and (own_now_ms - sibling_ts_ms) < AB_GP_STARTUP_TS_FRESH_MS; own_now_ms otherwise

Definition at line 7 of file ab_gp_startup_timestamp.c.

◆ ab_gp_startup_timestamp_encode()

void ab_gp_startup_timestamp_encode ( uint8_t * buf,
bool is_reply,
rte_timestamp_ms_t ts_ms )

Encodes a STARTUP_TS payload.

Parameters
bufout, at least AB_GP_STARTUP_TS_PAYLOAD_SIZE bytes
is_replyfalse for a request, true for the reply
ts_msthe timestamp carried

Definition at line 20 of file ab_gp_startup_timestamp.c.

◆ ab_gp_startup_timestamp_decode()

bool ab_gp_startup_timestamp_decode ( const uint8_t * buf,
size_t size,
bool * is_reply,
rte_timestamp_ms_t * ts_ms )

Decodes a STARTUP_TS payload.

Parameters
bufthe payload bytes
sizenumber of bytes available in buf
is_replyout: false for a request, true for a reply
ts_msout: the timestamp carried
Returns
true when size is at least AB_GP_STARTUP_TS_PAYLOAD_SIZE and the is_reply byte is 0 or 1; false otherwise (the out parameters are then left unchanged)

Definition at line 36 of file ab_gp_startup_timestamp.c.