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 thevxlib1
library (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 thevxlib1
library blocks to target your RTOS. This topic is discussed inCreate a Customized Asynchronous Library.
Thevxlib1
library 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 containingvxlib1
library 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
The
rtwdemo_async
model, which uses thetornado.tlc
system target file andvxlib1
块库。To open this example, typertwdemo_async
at the MATLAB command prompt.The
rtwdemo_async_mdlreftop
model, which uses thetornado.tlc
system target file andvxlib1
块库。To open this example, typertwdemo_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 chapter, see VxWorks system documentation on the Wind River®website.
Related Topics
- Time-Based Scheduling and Code Generation
- Generate Interrupt Service Routines
- Spawn and Synchronize Execution of RTOS Task
- Pass Asynchronous Events in RTOS as Input To a Referenced Model
- Timers in Asynchronous Tasks
- Import Asynchronous Event Data for Simulation
- Rate Transitions and Asynchronous Blocks
- Create a Customized Asynchronous Library
- Asynchronous Support Limitations
[1]VxWorks is a registered trademark of Wind River Systems, Inc.