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 tag_t last_DNET; // Most recent DNET.
57 scheduling_node_state_t state; // State of the scheduling node.
58 uint16_t* immediate_upstreams; // Array of immediate upstream scheduling node ids.
59 interval_t* immediate_upstream_delays; // Minimum delay on connections from immdediate upstream scheduling nodes.
60 // Here, NEVER encodes no delay. 0LL is a microstep delay.
61 uint16_t num_immediate_upstreams; // Size of the array of immediate upstream scheduling nodes and delays.
62 uint16_t* immediate_downstreams; // Array of immediate downstream scheduling node ids.
63 uint16_t num_immediate_downstreams; // Size of the array of immediate downstream scheduling nodes.
64 execution_mode_t mode; // FAST or REALTIME.
65 int flags; // One of IS_IN_ZERO_DELAY_CYCLE, IS_IN_CYCLE
66} scheduling_node_t;
67
73typedef struct rti_common_t {
74 // The scheduling nodes.
75 scheduling_node_t** scheduling_nodes;
76
77 // Number of scheduling nodes
78 uint16_t number_of_scheduling_nodes;
79
80 // Matrix of minimum delays between pairs of nodes.
81 // Rows represent upstream nodes and Columns represent downstream nodes.
82 // FOREVER_TAG means there is no path, and ZERO_TAG means there is no delay.
83 // This could be NULL if the matrix is not being used, so accesses should test for NULL first.
84 tag_t* min_delays;
85
86 // RTI's decided stop tag for the scheduling nodes
87 tag_t max_stop_tag;
88
89 // Number of scheduling nodes handling stop
90 int num_scheduling_nodes_handling_stop;
91
92 // Boolean indicating that tracing is enabled.
93 bool tracing_enabled;
94
95 // Boolean indicating that DNET is enabled.
96 bool dnet_disabled;
97
98 // The RTI mutex for making thread-safe access to the shared state.
99 lf_mutex_t* mutex;
100} rti_common_t;
101
102typedef struct {
103 tag_t tag; // NEVER if there is no tag advance grant.
104 bool is_provisional; // True for PTAG, false for TAG.
105} tag_advance_grant_t;
106
113void initialize_rti_common(rti_common_t* rti_common);
114
127void _logical_tag_complete(scheduling_node_t* e, tag_t completed);
128
135void initialize_scheduling_node(scheduling_node_t* e, uint16_t id);
136
147void notify_downstream_advance_grant_if_safe(scheduling_node_t* e, bool visited[]);
148
162void notify_tag_advance_grant(scheduling_node_t* e, tag_t tag);
163
173void notify_advance_grant_if_safe(scheduling_node_t* e);
174
187void notify_provisional_tag_advance_grant(scheduling_node_t* e, tag_t tag);
188
220tag_advance_grant_t tag_advance_grant_if_safe(scheduling_node_t* e);
221
232void update_scheduling_node_next_event_tag_locked(scheduling_node_t* e, tag_t next_event_tag);
233
242tag_t earliest_future_incoming_message_tag(scheduling_node_t* e);
243
254tag_t eimt_strict(scheduling_node_t* e);
255
262void update_min_delays();
263
273tag_t get_dnet_candidate(tag_t next_event_tag, tag_t minimum_delay);
274
291tag_t downstream_next_event_tag(scheduling_node_t* node, uint16_t node_sending_new_net_id);
292
298void notify_downstream_next_event_tag(scheduling_node_t* e, tag_t tag);
299
304bool is_in_zero_delay_cycle(scheduling_node_t* node);
305
310bool is_in_cycle(scheduling_node_t* node);
311
316void invalidate_min_delays();
317
321void free_scheduling_nodes(scheduling_node_t** scheduling_nodes, uint16_t number_of_scheduling_nodes);
322
323#endif // RTI_COMMON_H
324#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:78
Time and tag definitions and functions for Lingua Franca.
int64_t interval_t
Definition tag.h:68
Definitions of tracepoint functions for use with the C code generator and any other code generator th...