Main Content

Asynchronous Events

Asynchronous Support

通常情况下,你的时间模型,你打算generate code from aperiodicinterrupt 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 areasynchronous对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 thevxlib1块库。

The key blocks in the library are theAsync InterruptandTask Syncblocks. These blocks are targeted for an example RTOS (VxWorks). You can use them, with modification, to support your RTOS applications.

Note

You can use the blocks in thevxlib1library (Async InterruptandTask Sync) for simulation and code generation. These blocks provide starting point examples to help you develop custom blocks for your target environment.

To implement asynchronous support for an RTOS other than the example RTOS, use the guidelines and example code are provided to help you adapt thevxlib1library blocks to target your RTOS. This topic is discussed inCreate a Customized Asynchronous Library.

Thevxlib1library includes blocks you can use to

  • Generate interrupt-level code —Async Interruptblock

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

  • Enable data integrity when transferring data between blocks running as different tasks —Protected RTblock

  • Use an unprotected/nondeterministic mode when transferring data between blocks running as different tasks —Unprotected RTblock

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

Access the Block Library for RTOS Integration

To access the example RTOS (VxWorks) block library, enter the MATLAB®commandvxlib1.

Generate Code Using Library Blocks for RTOS Integration

To generate an example RTOS compatible application from a model containingvxlib1library blocks, use the following model configuration parameter settings for your model.

  • SetSystem target file(SystemTargetFile) toert.tlc(requires an Embedded Coder®license).

  • SelectGenerate code only(GenCodeOnly).

  • SelectGenerate an example main program(GenerateSampleERTMain).

  • SetTarget operating system(TargetOS) toVxWorksExample.

Examples and Additional Information

Additional information relevant to the topics in this chapter can be found in

  • Thertwdemo_asyncmodel, which uses thetornado.tlcsystem target file andvxlib1块库。To open this example, typertwdemo_asyncat the MATLAB command prompt.

  • Thertwdemo_async_mdlreftopmodel, which uses thetornado.tlcsystem target file andvxlib1块库。To open this example, typertwdemo_async_mdlreftopat 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 theert.tlcsystem target file, including task execution and scheduling.

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

Related Topics


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