Task Sync
Run code of downstream function-call subsystem or Stateflow chart by spawning an example RTOS (VxWorks) task
Libraries:
Simulink Coder /
Asynchronous /
Interrupt Templates
Description
The Task Sync block spawns an example RTOS (VxWorks) task that
calls a function-call subsystem or Stateflow® chart. Typically, you place the Task Sync block between an
Async Interrupt block and a function-call subsystem block or Stateflow chart. Alternatively, you could connect the Task Sync block to
the output port of a Stateflow diagram that has an event, Output to Simulink
, configured as
a function call.
The Task Sync block:
Uses the RTOS (VxWorks) system call
taskSpawn
to spawn an independent task. When the task is activated, it calls the downstream function-call subsystem code or Stateflow chart. The block callstaskDelete
to delete the task during model termination.Creates a semaphore to synchronize the connected subsystem with execution of the block.
Wraps the spawned task in an infinite
for
loop. In the loop, the spawned task listens for the semaphore by usingsemTake
. The first call tosemTake
specifiesNO_WAIT
. This setting lets the task determine whether a secondsemGive
has occurred before the completion of the function-call subsystem or chart. This sequence indicates that the interrupt rate is too fast or the task priority is too low.Generates synchronization code (for example,
semGive()
). This code lets the spawned task run. The task in turn calls the connected function-call subsystem code. The synchronization code can run at interrupt level. The connection between the Async Interrupt and Task Sync blocks accomplishes this operation and triggers execution of the Task Sync block within an ISR.Supplies absolute time if blocks in the downstream algorithmic code require it. The time comes from the timer maintained by the Async Interrupt block or comes from an independent timer maintained by the task associated with the Task Sync block.
When you design your application, consider when timer and signal input values could be taken for the downstream function-call subsystem that is connected to the Task Sync block. By default, the time and input data are read when the RTOS (VxWorks) activates the task. For this case, the data (input and time) are synchronized to the task itself. If you select the Synchronize the data transfer of this task with the caller task option and the Task Sync block driver is an Async Interrupt block, the time and input data are read when the interrupt occurs (that is, within the ISR). For this case, data is synchronized with the caller of the Task Sync block.
Note
Use the blocks in the Interrupt Templates block library (Async Interrupt and Task Sync) for simulation and code generation. These blocks provide starting point examples to help you develop custom blocks for a target environment.
Ports
Input
Output Arguments
Parameters
Version History
Introduced in R2006a