reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
modes.h
Go to the documentation of this file.
1
21#ifndef MODES_H
22#define MODES_H
23
24#ifdef MODAL_REACTORS
25
26#include <stddef.h>
27#include <stdbool.h>
28
29#include "lf_types.h"
30#include "tag.h"
31
32typedef struct event_t event_t;
33typedef struct reaction_t reaction_t;
34typedef struct trigger_t trigger_t;
35
38
50#define _LF_SET_MODE_WITH_TYPE(mode, change_type) \
51 do { \
52 ((self_base_t*)self)->_lf__mode_state.next_mode = mode; \
53 ((self_base_t*)self)->_lf__mode_state.mode_change = change_type; \
54 } while (0)
55
58
59/* Typedef for reactor_mode_t struct, used for representing a mode. */
61/* Typedef for reactor_mode_state_t struct, used for storing modal state of reactor and/or its relation to enclosing
62 * modes. */
64/* Typedef for mode_state_variable_reset_data_t struct, used for storing data for resetting state variables nested in
65 * modes. */
67
73
104
141
172
175typedef struct environment_t environment_t;
176
179
187
195
203
212
221void _lf_initialize_mode_states(environment_t* env, reactor_mode_state_t* states[], int states_size);
222
235void _lf_process_mode_changes(environment_t* env, reactor_mode_state_t* states[], int states_size,
236 mode_state_variable_reset_data_t reset_data[], int reset_data_size,
238
246
261 int reset_reactions_size, reactor_mode_state_t* states[], int states_size);
262
273
281
282#else /* IF NOT MODAL_REACTORS */
283/*
284 * Reactions and triggers must have a mode pointer to set up connection to enclosing modes,
285 * also when they are precompiled without modal reactors in order to later work in modal reactors.
286 * Hence define mode type as void in the absence of modes to treat mode pointer as void pointers for that time being.
287 */
288typedef void reactor_mode_t;
289#endif /* MODAL_REACTORS */
290#endif /* MODES_H */
int64_t instant_t
Time instant.
Definition tag.h:101
void _lf_add_suspended_event(event_t *event)
Add a suspended event to the list of suspended events.
bool _lf_mode_is_active(reactor_mode_t *mode)
Check whether a mode is active.
void _lf_handle_mode_triggered_reactions(environment_t *env)
Handle the mode triggered reactions in the environment.
void _lf_handle_mode_changes(environment_t *env)
Handle the mode changes in the environment.
void _lf_process_mode_changes(environment_t *env, reactor_mode_state_t *states[], int states_size, mode_state_variable_reset_data_t reset_data[], int reset_data_size, trigger_t *timer_triggers[], int timer_triggers_size)
Process the mode changes in the environment.
void _lf_handle_mode_shutdown_reactions(environment_t *env, reaction_t **shutdown_reactions, int shutdown_reactions_size)
Handle the mode shutdown reactions in the environment.
void _lf_initialize_modes(environment_t *env)
Initialize the modes in the environment.
void _lf_handle_mode_startup_reset_reactions(environment_t *env, reaction_t **startup_reactions, int startup_reactions_size, reaction_t **reset_reactions, int reset_reactions_size, reactor_mode_state_t *states[], int states_size)
Handle the mode startup reset reactions in the environment.
lf_mode_change_type_t
Type of the mode change.
Definition modes.h:72
void _lf_initialize_mode_states(environment_t *env, reactor_mode_state_t *states[], int states_size)
Initialize the mode states in the environment.
void _lf_terminate_modal_reactors(environment_t *env)
Terminate the modal reactors in the environment.
@ reset_transition
Definition modes.h:72
@ history_transition
Definition modes.h:72
@ no_transition
Definition modes.h:72
Type definitions that are widely used across different parts of the runtime.
Execution environment.
Definition environment.h:52
int timer_triggers_size
Number of timer triggers allocated.
Definition environment.h:186
int reset_reactions_size
Number of reset reactions allocated.
Definition environment.h:231
trigger_t ** timer_triggers
Array of timer triggers.
Definition environment.h:179
reaction_t ** startup_reactions
Array of startup reactions.
Definition environment.h:194
int startup_reactions_size
Number of startup reactions allocated.
Definition environment.h:201
reaction_t ** reset_reactions
Array of reset reactions.
Definition environment.h:224
reaction_t ** shutdown_reactions
Array of shutdown reactions.
Definition environment.h:209
int shutdown_reactions_size
Number of shutdown reactions allocated.
Definition environment.h:216
Event activation record to push onto the event queue.
Definition lf_types.h:354
A struct to store data for resetting state variables nested in modes.
Definition modes.h:146
size_t size
The size of the variable to be reset (in bytes).
Definition modes.h:170
reactor_mode_t * mode
Pointer to the enclosing mode for this reset data.
Definition modes.h:152
void * source
Pointer to the data source for resetting the variable.
Definition modes.h:164
void * target
Pointer to the target variable to be reset.
Definition modes.h:158
Reaction activation record to push onto the reaction queue.
Definition lf_types.h:195
A struct to store state of the modes in a reactor instance and/or its relation to enclosing modes.
Definition modes.h:109
reactor_mode_t * initial_mode
Pointer to the initial mode for this state.
Definition modes.h:121
lf_mode_change_type_t mode_change
A mode change type flag.
Definition modes.h:139
reactor_mode_t * next_mode
Pointer to the next mode to activate at the end of this step (if set).
Definition modes.h:133
reactor_mode_t * current_mode
Pointer to the currently active mode (only locally active).
Definition modes.h:127
reactor_mode_t * parent_mode
Pointer to the next enclosing mode (if exists).
Definition modes.h:115
A struct to represent a single mode instace in a reactor instance.
Definition modes.h:78
reactor_mode_state_t * state
Pointer to a struct with the reactor's mode state for this mode instance.
Definition modes.h:84
uint8_t flags
Bit vector for several internal flags related to the mode.
Definition modes.h:102
char * name
Name of this mode (null-terminated string).
Definition modes.h:90
instant_t deactivation_time
The logical time when the mode was deactivated (left).
Definition modes.h:96
Trigger struct representing an output, timer, action, or input.
Definition lf_types.h:391
Time and tag definitions and functions for Lingua Franca.