reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
rti_common.h
Go to the documentation of this file.
1
12#if defined STANDALONE_RTI || defined LF_ENCLAVES
13#ifndef RTI_COMMON_H
14#define RTI_COMMON_H
15
16#include <errno.h> // Defines perror(), errno
17#include <assert.h>
18#include "low_level_platform.h" // Platform-specific types and functions
19#include "util.h" // Defines print functions (e.g., lf_print).
20#include "tag.h" // Time-related types and functions.
21#include "tracepoint.h" // Tracing related functions
22
24typedef enum execution_mode_t { FAST, REALTIME } execution_mode_t;
25
27typedef enum scheduling_node_state_t {
28 NOT_CONNECTED, // The scheduling node has not connected.
29 GRANTED, // Most recent MSG_TYPE_NEXT_EVENT_TAG has been granted.
30 PENDING // Waiting for upstream scheduling nodes.
31} scheduling_node_state_t;
32
34typedef struct minimum_delay_t {
35 int id; // ID of the upstream node.
36 tag_t min_delay; // Minimum delay from upstream.
37} minimum_delay_t;
38
49typedef struct scheduling_node_t {
50 uint16_t id; // ID of this scheduling node.
51 tag_t completed; // The largest logical tag completed by the scheduling node
52 // (or NEVER if no LTC has been received).
53 tag_t last_granted; // The maximum TAG that has been granted so far (or NEVER if none granted)
54 tag_t last_provisionally_granted; // The maximum PTAG that has been provisionally granted (or NEVER if none granted)
55 tag_t next_event; // Most recent NET received from the scheduling node (or NEVER if none received).
56 scheduling_node_state_t state; // State of the scheduling node.
57 uint16_t* upstream; // Array of upstream scheduling node ids.
58 interval_t* upstream_delay; // Minimum delay on connections from upstream scheduling nodes.
59 // Here, NEVER encodes no delay. 0LL is a microstep delay.
60 int num_upstream; // Size of the array of upstream scheduling nodes and delays.
61 uint16_t* downstream; // Array of downstream scheduling node ids.
62 int num_downstream; // Size of the array of downstream scheduling nodes.
63 execution_mode_t mode; // FAST or REALTIME.
64 minimum_delay_t* min_delays; // Array of minimum delays from upstream nodes, not including this node.
65 size_t num_min_delays; // Size of min_delays array.
66 int flags; // Or of IS_IN_ZERO_DELAY_CYCLE, IS_IN_CYCLE
67} scheduling_node_t;
68
74typedef struct rti_common_t {
75 // The scheduling nodes.
76 scheduling_node_t** scheduling_nodes;
77
78 // Number of scheduling nodes
79 int32_t number_of_scheduling_nodes;
80
81 // RTI's decided stop tag for the scheduling nodes
82 tag_t max_stop_tag;
83
84 // Number of scheduling nodes handling stop
85 int num_scheduling_nodes_handling_stop;
86
87 // Boolean indicating that tracing is enabled.
88 bool tracing_enabled;
89
90 // The RTI mutex for making thread-safe access to the shared state.
91 lf_mutex_t* mutex;
92} rti_common_t;
93
94typedef struct {
95 tag_t tag; // NEVER if there is no tag advance grant.
96 bool is_provisional; // True for PTAG, false for TAG.
97} tag_advance_grant_t;
98
105void initialize_rti_common(rti_common_t* rti_common);
106
119void _logical_tag_complete(scheduling_node_t* e, tag_t completed);
120
127void initialize_scheduling_node(scheduling_node_t* e, uint16_t id);
128
139void notify_downstream_advance_grant_if_safe(scheduling_node_t* e, bool visited[]);
140
154void notify_tag_advance_grant(scheduling_node_t* e, tag_t tag);
155
165void notify_advance_grant_if_safe(scheduling_node_t* e);
166
179void notify_provisional_tag_advance_grant(scheduling_node_t* e, tag_t tag);
180
212tag_advance_grant_t tag_advance_grant_if_safe(scheduling_node_t* e);
213
224void update_scheduling_node_next_event_tag_locked(scheduling_node_t* e, tag_t next_event_tag);
225
234tag_t earliest_future_incoming_message_tag(scheduling_node_t* e);
235
246tag_t eimt_strict(scheduling_node_t* e);
247
252bool is_in_zero_delay_cycle(scheduling_node_t* node);
253
258bool is_in_cycle(scheduling_node_t* node);
259
267void update_min_delays_upstream(scheduling_node_t* node);
268
276void invalidate_min_delays_upstream(scheduling_node_t* node);
277
281void free_scheduling_nodes(scheduling_node_t** scheduling_nodes, uint16_t number_of_scheduling_nodes);
282
283#endif // RTI_COMMON_H
284#endif // STANDALONE_RTI || LF_ENCLAVES
void * lf_mutex_t
Definition lf_arduino_support.h:118
Platform API support for the C target of Lingua Franca.
Definition tag.h:81
Time and tag definitions and functions for Lingua Franca.
int64_t interval_t
Definition tag.h:71
Definitions of tracepoint functions for use with the C code generator and any other code generator th...