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_channel_stage.c
Go to the documentation of this file.
1
6
7#include <string.h>
8
9#include "rte/oal/memory/rte_mem_util.h"
10#include "rte/utils/safestate/rte_safestate.h"
11
13
15
17
19
21static rte_status_t stage_entry(ab_gp_channel_context_t *ctx, ab_gp_stage_dest_kind_t dest_kind,
22 rte_example_relay_kind_t relay_kind, uint8_t relay_index,
23 const uint8_t *bytes, size_t size);
24
27{
29
30 if (ctx == NULL)
31 {
32 return;
33 }
34 ctx->staged_send_count = 0U;
35}
36
37rte_status_t ab_gp_channel_stage_peer(ab_gp_channel_handle_t handle, const uint8_t *bytes, size_t size)
38{
40
41 if (ctx == NULL || bytes == NULL || size == 0U)
42 {
43 return RTE_STATUS_INVALID_PARAM;
44 }
46}
47
49 const uint8_t *payload, size_t size)
50{
52 uint8_t frame[PEER_WIRE_FRAME_SIZE];
53
54 if ((ctx == NULL) || (payload == NULL) || (size == 0U) || (size > (sizeof(frame) - 1U)))
55 {
56 return RTE_STATUS_INVALID_PARAM;
57 }
58 rte_mem_set(frame, 0, sizeof(frame));
59 frame[0] = kind;
60 rte_mem_copy(&frame[1], payload, size);
61 return stage_entry(ctx, AB_GP_STAGE_DEST_CROSSCOMPARE, RTE_EXAMPLE_RELAY_KIND_TRAIN, 0U, frame, sizeof(frame));
62}
63
65 uint8_t index, const uint8_t *bytes, size_t size)
66{
68
69 if (ctx == NULL || bytes == NULL || size == 0U || kind >= RTE_EXAMPLE_RELAY_KIND_COUNT)
70 {
71 return RTE_STATUS_INVALID_PARAM;
72 }
73 return stage_entry(ctx, AB_GP_STAGE_DEST_RELAY, kind, index, bytes, size);
74}
75
77{
79 rte_status_t first_error = RTE_STATUS_OK;
80 uint32_t i;
81
82 if (ctx == NULL)
83 {
84 return RTE_STATUS_INVALID_PARAM;
85 }
86 /* Internal invariant, not a runtime condition a caller can trigger:
87 * ctx->staged_send_count is only ever incremented by stage_entry()'s
88 * own already-checked-bounds logic (it refuses to grow the count past
89 * AB_GP_MAX_STAGED_SENDS_PER_CYCLE, returning RTE_STATUS_RESOURCE_EXHAUSTED
90 * instead). Violating this here would mean memory corruption or a
91 * logic bug elsewhere wrote past this file's own control-flow
92 * guarantees - safeAPIFreamwork's RTE_ASSERT() (unlike a plain
93 * return-code check) exists exactly for this class of "should be
94 * structurally impossible" invariant. */
95 RTE_ASSERT(ctx->staged_send_count <= (uint32_t)AB_GP_MAX_STAGED_SENDS_PER_CYCLE);
96
97 for (i = 0U; i < ctx->staged_send_count; i++)
98 {
99 const ab_gp_staged_send_t *entry = &ctx->staged_sends[i];
100 rte_status_t status;
101
102 if (entry->dest_kind == AB_GP_STAGE_DEST_PEER)
103 {
104 status = ab_gp_channel_send_peer(handle, entry->bytes, entry->size);
105 }
106 else if (entry->dest_kind == AB_GP_STAGE_DEST_CROSSCOMPARE)
107 {
108 status = ab_gp_channel_send_crosscompare(handle, entry->bytes[0], &entry->bytes[1], entry->size - 1U);
109 }
110 else
111 {
112 status = ab_gp_channel_send_relay(handle, entry->relay_kind, entry->relay_index, entry->bytes,
113 entry->size);
114 }
115 if ((status != RTE_STATUS_OK) && (first_error == RTE_STATUS_OK))
116 {
117 first_error = status;
118 }
119 }
120 ctx->staged_send_count = 0U;
121 return first_error;
122}
123
125{
127
128 if (ctx == NULL)
129 {
130 return;
131 }
132 ctx->staged_send_count = 0U;
133}
134
136 rte_example_relay_kind_t relay_kind, uint8_t relay_index,
137 const uint8_t *bytes, size_t size)
138{
139 ab_gp_staged_send_t *entry;
140
142 {
143 return RTE_STATUS_RESOURCE_EXHAUSTED;
144 }
145 if (size > sizeof(entry->bytes))
146 {
147 return RTE_STATUS_INVALID_PARAM;
148 }
149
150 entry = &ctx->staged_sends[ctx->staged_send_count];
151 entry->dest_kind = dest_kind;
152 entry->relay_kind = relay_kind;
153 entry->relay_index = relay_index;
154 rte_mem_copy(entry->bytes, bytes, size);
155 entry->size = size;
156 ctx->staged_send_count++;
157 return RTE_STATUS_OK;
158}
rte_status_t ab_gp_channel_send_peer(ab_gp_channel_handle_t handle, const uint8_t *bytes, size_t size)
Sends a frame over the A<->B peer channel.
rte_status_t ab_gp_channel_send_relay(ab_gp_channel_handle_t handle, rte_example_relay_kind_t kind, uint8_t index, const uint8_t *bytes, size_t size)
Sends an envelope over a specific C relay channel.
rte_status_t ab_gp_channel_send_crosscompare(ab_gp_channel_handle_t handle, uint8_t kind, const uint8_t *payload, size_t size)
Sends a frame over the dedicated A<->B cross-compare channel.
struct ab_gp_channel_context_s * ab_gp_channel_handle_t
Opaque handle over this component's own static per-process context.
rte_status_t ab_gp_channel_stage_peer(ab_gp_channel_handle_t handle, const uint8_t *bytes, size_t size)
Queues a peer-link send for this cycle - does not transmit yet.
void ab_gp_channel_stage_reset(ab_gp_channel_handle_t handle)
Clears this cycle's pending-send queue.
void ab_gp_channel_discard_pending_sends(ab_gp_channel_handle_t handle)
Discards every send queued this cycle without transmitting it, then clears the queue.
rte_status_t ab_gp_channel_stage_crosscompare(ab_gp_channel_handle_t handle, uint8_t kind, const uint8_t *payload, size_t size)
Queues a crosscompare-link send for this cycle - does not transmit yet.
rte_status_t ab_gp_channel_commit_pending_sends(ab_gp_channel_handle_t handle)
Transmits every send queued this cycle (through the real ab_gp_channel_send_peer()/_send_relay()),...
static rte_status_t stage_entry(ab_gp_channel_context_t *ctx, ab_gp_stage_dest_kind_t dest_kind, rte_example_relay_kind_t relay_kind, uint8_t relay_index, const uint8_t *bytes, size_t size)
rte_status_t ab_gp_channel_stage_relay(ab_gp_channel_handle_t handle, rte_example_relay_kind_t kind, uint8_t index, const uint8_t *bytes, size_t size)
Queues a relay-link send for this cycle - does not transmit yet.
Stage-then-commit output queue for this cycle's own DECISION output (ADR-034): the peer AB_SAMPLE and...
#define PEER_WIRE_FRAME_SIZE
#define AB_GP_MAX_STAGED_SENDS_PER_CYCLE
Stage-then-commit output queue (ADR-034) - see ab_gp_channel_stage.h.
ab_gp_stage_dest_kind_t
@ AB_GP_STAGE_DEST_RELAY
@ AB_GP_STAGE_DEST_CROSSCOMPARE
@ AB_GP_STAGE_DEST_PEER
#define RTE_EXAMPLE_RELAY_KIND_COUNT
Definition site_config.h:50
rte_example_relay_kind_t
Which client type a C<->A/C<->B relay link/port belongs to - this project's own dedicated-channel-per...
Definition site_config.h:39
@ RTE_EXAMPLE_RELAY_KIND_TRAIN
Definition site_config.h:40
Central application context owned by composition root (main.c).
ab_gp_staged_send_t staged_sends[AB_GP_MAX_STAGED_SENDS_PER_CYCLE]
ab_gp_stage_dest_kind_t dest_kind
uint8_t bytes[AB_GP_STAGED_SEND_BYTES_SIZE]
rte_example_relay_kind_t relay_kind