Main Task: Partition and Flow Control for C
This section describes how different generated modules are put together into a single thread, and what is the control flow of the main task. The whole execution starts with an initialization phase, where all components are initialized: the timer, the threads scheduler (if needed) and basic activity tasks are created. In addition the user_init procedure is called.
The
user_init
procedure resides in a file calleduser_activities.c.
When you generate code, the Code Generator automatically creates theuser_activities.c
file and the user_init procedure. Prior to executing the model, you may initialize values in theuser_init
procedure.After the initialization phase, the main-task starts processing in a cyclic manner, where every cycle corresponds to a single “go-step.” In every cycle, all the concurrent state machines are traversed, process their inputs and generate outputs, issue timing requests and take the necessary state transitions.
This is how the main program looks:
if (pr_make_step()) /* if system is in stable status,
pr_pause; it enters the pause mode, waiting
for external inputs */The C function
pr_make_step
returns TRUE when system is in a stable status.The main program is written as a task, which calls all the state machines within the profile.
pr_initialize
is the initialization procedure, andpr_make_step
completes a single-step of the whole system. Note the user-tasks, including basic activities are processing independently, as well as the asynchronous timer.The following diagram shows the calling sequence within the main task:
The C procedure
pr_make_step
follows:The
pr_make_step
procedure activates all the functions that complete the execution of a step.