Multitasking Demo Model

Introducing the Multitasking Demo

The demo model c166_multitasking illustrates both execution profiling and the preemptive multitasking scheduler with configurable overrun handling.

The model is multirate, having tasks running at 1 ms, 4 ms, and 16 ms. It is configured to use the preemptive multitasking scheduler.

A special feature of this model is that each task is designed to perform an increasing number of calculations to increase the processor loading until that task reaches a target turnaround time. This behavior ensures that task overruns occur to demonstrate the behavior of the model in this situation.

Each block in the model, labeled Load base rate, Load sub-rate 1, Load sub-rate 2 performs calculations, the result of which should always be 1 both in simulation and in real time. Any other result is a failure and should never occur.

The Test Rate Interaction blocks are designed to test whether data is transferred between tasks in a deterministic manner. In simulation, the output of each of these blocks is always zero, indicating that there is no drift between tasks running at different rates. When running in real time, under normal circumstances, the output is also zero; in this case the real-time behavior is deterministic and exactly matches the results in simulation. Even if task preemption and base-rate overruns occur, the output of these blocks will be zero so that the real-time behavior faithfully reproduces the results in simulation. The circumstance under which drift occurs is if sub-rate overruns occur during execution in real time; if this behavior is not desired, you should disallow sub-rate overruns by setting the maximum allowed number of sub-rate overruns to zero in the C166 Options (1) section in the Configuration Parameters dialog box (see Task Scheduler Overrun Options).

You can double-click the block provided in the model to switch between profiling over serial or CAN connections.

Running the Multitasking Demo

  1. Open the model by typing at the command line

    c166_multitasking

    If viewing in the Help browser, you can click the link to open the model. If you update the diagram you can see the sample-time colors.

  2. Select Simulation > Configuration Parameters.

    The Configuration Parameters dialog box appears.

  3. Select Embedded IDE Link TS in the tree and change the Build action to Create, Build and Execute Application Project. Click OK to dismiss the dialog box.

  4. Make sure the target is connected to the host PC via serial or CAN cable. The default setting in this demo model is serial. You can double-click the Switch Execution Profiling Connection block to toggle between blocks for serial and CAN. See below for instructions if using CAN.

  5. To build and run the model, select the model window, and then press Ctrl+B.

    Watch the messages in the command window as code is generated and loaded into the TASKING EDE, then the CrossView Pro Debugger starts, connects to the target, and downloads the code.

  6. In the CrossView window, click Run in the toolbar to start the application running on the target.

  7. At the command line, type

    profile_c166 ('serial')
    

    You will see messages in the command window as profile_c166 runs.

    When the data has been obtained the Help browser and a figure window appear, displaying the HTML report and the task execution profile.

  8. Scroll to view the HTML report on task timings and use the controls to zoom in on the MATLAB® graphic to examine the details of the task overruns.

If using CAN, be sure to use CAN channel 0 (not 1) on the PC. You can double-click the Switch Execution Profiling Connection block in the model to switch to CAN, and follow the same instructions as for a serial connection, except step 7 when the application is running. At the command line, type

profile_c166 ('CAN')

You will see command line messages as the function tests the CAN channel, and requests and collects profiling data. When using CAN, it can be useful to run a monitor program such as btest32 to verify that the model is running — for example you will see messages appearing on the CAN bus and you can see that you have connected the correct CAN channel.

Interpreting the MATLAB® Graphic

Dark shaded areas show the region where a task is executing. Light shaded areas show the region where a task is preempted by a higher priority task or ISR. Triangles indicate the beginning of a task. An example is shown following.

Zoom in to see the details of times that tasks are executing and being preempted, as shown in the following example.

.

The Generated HTML Report

See Definitions for the terms task turnaround time, task execution time, and concurrent task overruns.

All times are in seconds. The timer resolution is 4e-007 seconds and the measurement range is 0.026214 seconds.

The report contains the following information:

Examples are shown following.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS