| Real-Time Workshop® | ![]() |
Spawn VxWorks task to run code of downstream function-call subsystem or Stateflow® chart
Interrupt Templates, VxWorks
The Task Sync block spawns a 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 might 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 performs the following functions:
Uses the 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 calls taskDelete 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, using semTake. The first call to semTake specifies NO_WAIT. This allows the task to determine whether a second semGive has occurred prior to the completion of the function-call subsystem or chart. This would indicate that the interrupt rate is too fast or the task priority is too low.
Generates synchronization code (for example, semGive()). This code allows the spawned task to run. The task in turn calls the connected function-call subsystem code. The synchronization code can run at interrupt level. This is accomplished through the connection between the Async Interrupt and Task Sync blocks, which triggers execution of the Task Sync block within an ISR.
Supplies absolute time if blocks in the downstream algorithmic code require it. The time is supplied either by the timer maintained by the Async Interrupt block, or by 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 should 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 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 is driven by 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.
The first argument passed to the VxWorks taskSpawn system call. VxWorks uses this name as the task function name. This name also serves as a debugging aid; routines use the task name to identify the task from which they are called.
The VxWorks task priority to be assigned to the function-call subsystem task when spawned. VxWorks priorities range from 0 to 255, with 0 representing the highest priority.
Note The Simulink® software does not simulate asynchronous task behavior. The task priority of an asynchronous task is for code generation purposes only and is not honored during simulation. |
Maximum size to which the task's stack can grow. The stack size is allocated when VxWorks spawns the task. Choose a stack size based on the number of local variables in the task. You should determine the size by examining the generated code for the task (and all functions that are called from the generated code).
If not checked (the default),
The block maintains a timer that provides absolute time values required by the computations of downstream blocks. The timer is independent of the timer maintained by the Async Interrupt block that calls the Task Sync block.
A Timer resolution option appears.
The Timer size option specifies the word size of the time counter.
If checked,
The block does not maintain an independent timer, and does not display the Timer resolution field.
Downstream blocks that require timers use the timer maintained by the Async Interrupt block that calls the Task Sync block (see Using Timers in Asynchronous Tasks in the Real-Time Workshop® documentation). The timer value is read at the time the asynchronous interrupt is serviced, and data transfers to blocks called by the Task Sync block and execute within the task associated with the Async Interrupt block. Therefore, data transfers are synchronized with the caller.
The resolution of the block's timer in seconds. This option appears only if Synchronize the data transfer of this task with the caller task is not checked. By default, the block gets the timer value by calling the VxWorks tickGet function. The default resolution is 1/60 second. The tickGet resolution for your BSP might be different. You should determine the tickGet resolution for your BSP and enter it in the Timer resolution field.
The number of bits to be used to store the clock tick for a hardware timer. The size can be 32bits (the default), 16bits, 8bits, or auto. If you select auto, the Real-Time Workshop software determines the timer size based on the settings of Application lifespan (days) and Timer resolution.
By default, timer values are stored as 32-bit integers. However, when Timer size is auto, you can indirectly control the word size of the counters by setting the Application lifespan (days) option. If you set Application lifespan (days) to a value that is too large for the code generator to handle as a 32-bit integer of the specified resolution, it uses a second 32-bit integer to address overflows.
For more information, see Controlling Memory Allocation for Time Counters. See also Using Timers in Asynchronous Tasks.
A call from an Async Interrupt block.
A call to a function-call subsystem.
Async Interrupt
Asynchronous Support in the Real-Time Workshop documentation
![]() | System Update | Unprotected RT | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |