Main Content

Asynchronous Events

Asynchronous Support

Normally, you time models from which you plan to generate code from a periodic interrupt source (for example, a hardware timer). Blocks in a periodically clocked single-rate model run at a timer interrupt rate (the base rate of the model). Blocks in a periodically clocked multirate model run at the base rate or at multiples of that rate.

Many systems must also support execution of blocks in response to events that are asynchronous with respect to the periodic timing source of the system. For example, a peripheral device might signal completion of an input operation by generating an interrupt. The system must service such interrupts, for example, by acquiring data from the interrupting device.

This topic explains how to use blocks to model and generate code for asynchronous event handling, including servicing of hardware-generated interrupts, maintenance of timers, asynchronous read and write operations, and spawning of asynchronous tasks under a real-time operating system (RTOS). This block library demonstrates integration with an example RTOS (VxWorks®). Although the blocks target an example RTOS, this chapter provides source code analysis and other information you can use to develop blocks that support asynchronous event handling for an alternative target RTOS.[1]

Block Library for Calls to an Example Real-Time Operating System

The next figure shows the blocks in the vxlib1 block library.

The key blocks in the library are the Async Interrupt and Task Sync blocks. These blocks are targeted for an example RTOS (VxWorks). You can use them, with modification, to support your RTOS applications.


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.

To implement asynchronous support for an RTOS other than the example RTOS, use these guidelines and the example code in Create a Customized Asynchronous Library to adapt the Interrupt Template library blocks for your RTOS.

The Interrupt Template library includes blocks that you can use to:

  • Generate interrupt-level code — Async Interrupt block

  • Spawn an RTOS task that calls a function call subsystem — Task Sync block

The use of protected and unprotected Rate Transition blocks in asynchronous contexts is discussed in Rate Transitions and Asynchronous Blocks. For general information on rate transitions, see Time-Based Scheduling and Code Generation.

Generate Code Using Library Blocks for RTOS Integration

To generate an example RTOS compatible application from a model that contains Interrupt Template library blocks, use these model configuration parameter settings for your model:

  • Set System target file (SystemTargetFile) to ert.tlc (requires Embedded Coder®).

  • Select Generate code only (GenCodeOnly).

  • Select Generate an example main program (GenerateSampleERTMain).

  • Set Target operating system (TargetOS) to VxWorksExample.

Examples and Additional Information

  • Example model rtwdemo_async, which uses the tornado.tlc system target file and Interrupt Template block library. To open the model, type rtwdemo_async at the MATLAB® command prompt.

  • Example model rtwdemo_async_mdlreftop, which uses the tornado.tlc system target file and Interrupt Template block library. To open the model, type rtwdemo_async_mdlreftop at the MATLAB command prompt.

  • Time-Based Scheduling and Code Generation discusses general multitasking and rate transition issues for periodic models.

  • The Embedded Coder documentation discusses the ert.tlc system target file, including task execution and scheduling.

  • For detailed information about the system calls to the example RTOS (VxWorks) mentioned in this topic, see VxWorks system documentation on the Wind River® website.

Related Topics

[1] VxWorks is a registered trademark of Wind River Systems, Inc.