MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Guia do Utilizador

Consulte online ou descarregue Guia do Utilizador para Software MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER. MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER User`s guide [en] Manual do Utilizador

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 386
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes

Resumo do Conteúdo

Página 1 - Real-Time Workshop

ModelingSimulationImplementationReal-Time Workshop® For Use with SIMULINK ®User’s GuideVersion 3

Página 2 - How to Contact The MathWorks:

viiiExecutingModelsinReal-Time ... 7-9MultitaskingOperation... 7-10SingletaskingOperation ...

Página 3

3 Code Generation and the Build Process3-18Online Help. Placing your mouse over any of these field names or check boxesactivates a Help facility that

Página 4

The Real-Time Workshop User Interface3-19The RTW Tunable Parameters dialog box supports the following features:• Parameter tuning — de-inline any mode

Página 5

3 Code Generation and the Build Process3-20your Simulink model; then select Signal Properties under the Edit menu ofyour model. This opens theSignal P

Página 6

The Real-Time Workshop User Interface3-21- Imported Extern — declares the signal as extern. It must then be declaredfrom outside the generated code.-

Página 7

3 Code Generation and the Build Process3-22Configuring the Generated CodeAs an alternative to using the Code Generation Options dialog box, you cancon

Página 8

Template Makefiles3-23Template MakefilesThis section contains a description of how to work with and modify thetemplate makefiles that are used with th

Página 9

3 Code Generation and the Build Process3-24|>MEXEXT<|MEX-file extension. See the MATLABmexext command.|>MODEL_NAME<| Name of the Simulink

Página 10

Template Makefiles3-25In addition target specific tokens defined via the Real-Time Workshop page oftheSimulation Parameters dialog box are expanded. I

Página 11

3 Code Generation and the Build Process3-26Typically, build options are specified as a comment at the top of the templatemakefile you are using.You ne

Página 12 - Targeting Custom Hardware

Template Makefiles3-27then the make command that will be invoked is:mymake −f model.mkHOST— What platform this template makefile is targeted for. This

Página 13 - Real-Time Workshop Libraries

ixInteractively ... 8-19ConnectingtotheVxWorksTarget ... 8-19DownloadingtheReal-TimeProgram ...

Página 14 - Contents

3 Code Generation and the Build Process3-28• The third section defines the tokens make_rtw expands.• The fourth section contains themake rules used in

Página 15 - Real-Time Workshop Ada Coder

Template Makefiles3-29Figure 3-7: Structure of a Template Makefile#-- Section 1: Comments -------------------------------------------------------## D

Página 16 - Glossary

3 Code Generation and the Build Process3-30Customizing and Creating Template MakefilesTo customize or create a new template makefile, you can copy an

Página 17 - Foreword

Template Makefiles3-31You can use pattern matching expressions to make the dependency rules moregeneral. For example, using GNU Make you could have re

Página 18 - Foreword

3 Code Generation and the Build Process3-32Generic Real-Time TemplatesThe Real-Time Workshop includes a set of built-in template makefiles that areset

Página 19 - What Is MATLAB?

Generic Real-Time Templates3-33• USER_SRCS — Additional user sources, such as files needed by S-functions.For example, suppose you have an S-function

Página 20 - What Is Simulink?

3 Code Generation and the Build Process3-34• USER_SRCS — Additional user sources, such as files needed by S-functions.For example, suppose you have an

Página 21 - What Is Stateflow?

Generic Real-Time Templates3-35built with sfcn_lib1.c,andsfcn_lib2.c. (library routines for use withmany S-functions). You can build,my_sfcn.c using:m

Página 22

3 Code Generation and the Build Process3-36• USER_OBJS — Additional object (.obj) files, which are to be created from usersources, such as files neede

Página 23 - File menu

Generic Real-Time Templates3-37• OPTS — User-specific options, for example,make_rtw OPTS="−DMYDEFINE=1"• OPT_OPTS — grt_bc.tmf optimization

Página 24 - Installation

x10Targeting Custom HardwareIntroduction ...10-2Run-Time Interface ...1

Página 25 - System,gototheEnvironment

3 Code Generation and the Build Process3-38File and Function SplittingTo support compilers with file size limitations, the Real-Time Workshopprovides

Página 26

File and Function Splitting3-39You must turn off the TLC variable ShowEliminatedStatements for filesplitting to work. This is required because the#if

Página 27 - Where to Go from Here

3 Code Generation and the Build Process3-40Function SplittingSometimes a file may not be too large, but a single function contained in the filemight b

Página 28

File and Function Splitting3-41incrementing by one each time the function is split. For example, if youroriginal function isMdlOutput, the split funct

Página 29 - Introduction to the

3 Code Generation and the Build Process3-42

Página 30

4External ModeIntroduction ...4-2ExternalMode...4-3Getting Started with External Mode Using grt ...4-4Setting Up th

Página 31 - The Real-Time Workshop

4 External Mode4-2IntroductionExternal mode is a simulation mode provided by the Real-Time Workshop thatsupports on-the-fly parameter tuning in a real

Página 32 - Types of Output

Introduction4-3External ModeSimulink external mode is a mechanism that manages communicationbetween Simulink and stand-alone programs built with the R

Página 33

4 External Mode4-4Getting Started with External Mode Using grtThis section provides a step-by-step set of instructions for getting started withexterna

Página 34 - The Rapid Prototyping Process

Getting Started with External Mode Using grt4-5the Stop Time set to its default value. Set the Decimation to 1 (nodecimation).3 On the Workspace I/O p

Página 35

xi11Real-Time Workshop LibrariesIntroduction ...11-2Custom Code Library ...

Página 36

4 External Mode4-6select External Mode Control Panel under the Tools menu. This dialog boxopens.The top four buttons for use after you have started yo

Página 37 - Using External Mode

Getting Started with External Mode Using grt4-7To open the External Target Interface dialog box, click the Target Interfacebutton. The dialog box shou

Página 38 - Modeling Systems in Simulink

4 External Mode4-8The dialog box should look like this when you’re finished.Prior to building your model, you must select values for gainsA and B.Thee

Página 39 - Algorithm Design and Analysis

Getting Started with External Mode Using grt4-9Running External Mode on Your TargetTo run external mode, you must open an MS-DOS command prompt (on UN

Página 40

4 External Mode4-10External Mode GUIThe Real-Time Workshop provides an extensive graphical user interface (GUI),which includes four separate windows,

Página 41

External Mode GUI4-11Target InterfacePressing the Target Interface button activates the External Target Interfacedialog box.You must set the MEX-file

Página 42 - Make Utility

4 External Mode4-12External Signal & TriggeringPressing the Signal & Triggering button activates the External Signal &Triggeringdialog box

Página 43 - The Build Procedure

External Mode GUI4-13Trigger Signal Selection. You select a trigger signal by choosing it from the Signalselection list and pressing theTrigger signal

Página 44

4 External Mode4-14If you have selected a trigger, the Trigger signal panel activates.By default, any element of the first input port of the specified

Página 45 - Basic Features of example.rtw

External Mode GUI4-15Data ArchivingPressing the Data Archiving button opens the External Data Archivingdialog box.This panel supports various features

Página 46

xii ContentsChoosingaTarget ... 12-7Real-Time Code Format ...12-10UnsupportedBlocks...

Página 47 - Basic Features of example.c

4 External Mode4-16intermediate result. Since the trigger can fire at any time, writing intermediateresults to the workspace generally results in unpr

Página 48 - Bundled Target Systems

External Mode GUI4-17This picture shows the External Data Archiving dialog box with enabledarchiving.Unless you selectEnable archiving, entries for th

Página 49

4 External Mode4-18This picture shows the External Mode Control Panel with the batchdownload option activated:External Mode OperationWhen external mod

Página 50

External Mode GUI4-19The Simulink side initiates the parameter download operation by calling aprocedure on the external program side. In the general t

Página 51 - Getting Started with the

4 External Mode4-20LimitationsIn general, you cannot change a parameter if doing so results in a change in thestructure of the model. For example, you

Página 52

External Mode GUI4-21The following section discusses how to use external mode with real-timeprograms on a UNIX or PC system. Chapter 8, “Targeting Tor

Página 53

4 External Mode4-22Using the TCP ImplementationThis section describes how to use the TCP-based client/server implementationprovided with the Real-Time

Página 54 - 2. Customizing Generated Code

Using the TCP Implementation4-23Figure 4-2: TCP-based Client/Server Implementation for External ModeThe following sections discuss the details of how

Página 55 - 4. Validating Generated Code

4 External Mode4-24The External Interface MEX-FileYoumustspecifythenameoftheexternalinterfaceMEX-fileintheExternalTarget Interfacedialog box:You may b

Página 56 - 10. Parameter Tuning

Using the TCP Implementation4-25You must specify these options in order. For example, if you want to specify theverbosity level (the second argument),

Página 57

xiii13Real-Time Workshop Rapid Simulation TargetIntroduction ...13-2Building for the Rapid Simulation Targe

Página 58 - Simulation Parameters dialog

4 External Mode4-26Enabling External ModeTo enable external mode, display the Simulink block diagram and selectExternal from the Simulation menu:Next,

Página 59 - The Build Process

Using the TCP Implementation4-27Creating an External Mode Communication ChannelThe Real-Time Workshop provides support for TCP/IP through ext_comm.Whe

Página 61

5Data Logging and SignalMonitoringMAT-File Data Logging ...5-2Singletasking versus MultitaskingMAT-FileLogging...5-3C API for

Página 62 - The Simulink Model

5 Data Logging and Signal Monitoring5-2MAT-File Data LoggingFor the Real-Time Workshop targets that have access to a disk, you can useMAT-file logging

Página 63

MAT-File Data Logging5-3Singletasking versus Multitasking MAT-File LoggingWhen logging data you will notice differences in the logging of:• Noncontinu

Página 64 - Setting Program Parameters

5 Data Logging and Signal Monitoring5-4C API for Signal MonitoringSignal monitoring provides a second method for accessing block outputs in anexternal

Página 65

Using BlockIOSignals to Obtain Block Outputs5-5Using BlockIOSignals to Obtain Block OutputsThe BlockIOSignals data structure is declared as follows:ty

Página 66 - Inline parameters check

5 Data Logging and Signal Monitoring5-6The model code file model.bio defines an array of BlockIOSignals structures,for example:#include "bio_sig.

Página 67 - Data Logging

Using BlockIOSignals to Obtain Block Outputs5-7You must then write code that walks through the rtBIOSignals array andchooses the signals to be monitor

Página 68 - The UNIX Template Makefile

xiv ContentsGetting Started ... 14-6SettingOptionsforAdaCodeGeneration ... 14-7GeneratingAdaCode...

Página 69 - PC Template Makefiles

5 Data Logging and Signal Monitoring5-8continue; } } /*install/remove the signals*/ for (w = 0; w < blockInfo->signalWidth; w++) {

Página 70 - Generic Real-Time Modules

Using BlockIOSignals to Obtain Block Outputs5-9Below is an excerpt from an example routine that collects signals taken fromthe main simulation loop:/*

Página 71 - Nonlinear Blocks

5 Data Logging and Signal Monitoring5-10

Página 72

6Program ArchitectureIntroduction ...6-2Model Execution ...6-4ProgramTiming...6-13ProgramExecution...

Página 73

6 Program Architecture6-2IntroductionThe Real-Time Workshop generates two styles of code. One code style issuitable for rapid prototyping (and simulat

Página 74

Introduction6-3Third-party vendors supply additional targets for the Real-Time Workshop.Generally, these can be classified as rapid prototyping target

Página 75

6 Program Architecture6-4Model ExecutionBefore looking at the two styles of generated code, you need to have a high-levelunderstanding of how the gene

Página 76 - Tracing Generated Code Back

Model Execution6-5a given simulation time step. In minor time steps, the run-time interfaceintegrates the derivatives to update the continuous states.

Página 77

6 Program Architecture6-6During the ModelOutputs and ModelUpdate phases of model execution, onlyblocks that have hit the current point in time execute

Página 78 - Targeting dSPACE

Model Execution6-7Note that the multitasking execution assumes that all tasks are multiples ofthe base rate. Simulink enforces this when you have crea

Página 79 - PC chassisMonitor/keyboard

ForewordRelated Products and Documentation ...xviRequirements...xviHow to Use This Guide ...xxiTypographicalConventi

Página 80 - Real-Time Interface (RTI)

6 Program Architecture6-8The pseudocode below shows the execution of a model in a real-timesingletasking system where the model is run at interrupt le

Página 81

Model Execution6-9continuous blocks, then the integration step size determines the base samplerate.For example, if the model code is a controller oper

Página 82

6 Program Architecture6-10This code shows how a model executes in a real-time multitasking system(where the model is run at interrupt level).rtOneStep

Página 83 - Build Process

Model Execution6-11Running models at interrupt level in real-time multitasking environment isvery similar to the previous singletasking environment, e

Página 84

6 Program Architecture6-12occurs. The clock tick gives a clockSem (clock semaphore) to the model task(tSingleRate). The model task will wait for the s

Página 85 - Build button on the

Model Execution6-13EndMainLoop}main(){InitializationStart/spawn task "tSingleRate".Start clock that does a "semGive" on a clockSem

Página 86

6 Program Architecture6-14The following diagram illustrates interrupt timing.Figure 6-2: Task TimingThesampleintervalmustbelongenoughtoallowmodelcode

Página 87

Model Execution6-15Program ExecutionAs the previous section indicates, a real-time program may not require 100% ofthe CPU’s time. This provides an opp

Página 88

6 Program Architecture6-16that have a task identifier of 0. This results in differences in the logged valuesbetween singletasking and multitasking log

Página 89

Model Execution6-17name, parameter and signal storage class are included as part of the API forthe embedded style of code.The single largest differenc

Página 90

ForewordxviRelated Products and DocumentationRequirementsThe Real-Time Workshop®is a multiplatform product, running on MicrosoftWindows 95, Windows 9

Página 91

6 Program Architecture6-18model.reg), execute, the run-time interface starts execution by callingMdlStart. This routine is called once at start-up.The

Página 92 - Inline Parameters

Model Execution6-19• MdlTerminate(void) — MdlTerminate contains any block shutdown code.MdlTerminate is called by the run-time interface, as part of t

Página 93 - Make Command

6 Program Architecture6-20The general content of the rapid prototyping style of code for C is shown in thefollowing figure.Figure 6-3: Content of Mod

Página 94

Model Execution6-21A flow chart describing the execution of the rapid prototyping generated codeis shown below.Figure 6-4: Rapid Prototyping Executio

Página 95

6 Program Architecture6-22Block outputs can also go to the external output structure (rtY). The followingfigure shows the general mapping between thes

Página 96

Model Execution6-23The states structure has two sections: the first is for the continuous states;the second is for the discrete states.• Block Paramet

Página 97 - Options Button

6 Program Architecture6-24When compared with the rapid prototyping environment, these functions arevery similar.

Página 98 - System Target File Browser

Rapid Prototyping Program Framework6-25Rapid Prototyping Program FrameworkGenerating code for a Simulink model results in at least four files — model.

Página 99 - S3 in the generated

6 Program Architecture6-26Figure 6-6: The Rapid Prototyping Program ArchitectureThe Real-Time Workshop architecture consists of three parts. The firs

Página 100 - Tunable Parameters

Rapid Prototyping Program Framework6-27modules that implement the functions carried out by the system dependent,system independent, and application co

Página 101 - Signal Properties

Related Products and DocumentationxviiWhat Is MATLAB?MATLAB is a high-performance language for technical computing. Itintegrates computation, visualiz

Página 102

6 Program Architecture6-28Model Execution• Execute a background task, for example, communicate with the host duringexternal mode simulation or introdu

Página 103

Rapid Prototyping Program Framework6-29Model ExecutionAt each sample interval, the main program passes control to the modelexecution function, which e

Página 104 - .tlc) files. These files are

6 Program Architecture6-30Integration of Continuous States The real-time program calculates the next values for the continuous statesbased on the deri

Página 105 - Template Makefiles

Rapid Prototyping Program Framework6-31Application Modules for System Independent ComponentsThe system independent components include these modules:•

Página 106

6 Program Architecture6-32• Initialize a vector of sample times and sample time offsets and store thisvector in theSimStruct.• Store the values of the

Página 107

Rapid Prototyping Program Framework6-33Figure 6-8: Execution of the Model CodeThis diagram shows what functions are defined in the generated code and

Página 108 - Make Utilities

6 Program Architecture6-34automatically incorporates your non-inlined C code S-functions into theprogram if they adhere to the S-function API describe

Página 109 - Parameters

Rapid Prototyping Program Framework6-35Application Modules for Application ComponentsWhen the Real-Time Workshop generates code, it produces the follo

Página 110

6 Program Architecture6-36Embedded Program FrameworkThe embedded program framework and architecture is outlined by thefollowing figure.Figure 6-9: Th

Página 111

Embedded Program Framework6-37Note the similarity between this architecture and the rapid prototypingarchitecture on page 6-26. The main difference is

Página 112

How to Contact The MathWorks:508-647-7000 Phone508-647-7001 FaxThe MathWorks, Inc. Mail24 Prime Park WayNatick, MA 01760-1500http://www.mathworks.com

Página 113

ForewordxviiiWhat Is Simulink?Simulink is a software package for modeling, simulating, and analyzingdynamic systems. It supports linear and nonlinear

Página 115

7Models with MultipleSample RatesIntroduction ...7-2Single Versus Multitasking Environments ...7-3ExecutingMultitaskingModels...

Página 116

7 Models with Multiple Sample Rates7-2IntroductionEvery Simulink block can be classified according to its sample time as constant,continuous-time, dis

Página 117

Single- Versus Multitasking Environments7-3Single- Versus Multitasking EnvironmentsThere are two basic ways in which you can execute a fixed-step Simu

Página 118

7 Models with Multiple Sample Rates7-4Figure 7-1: Real-Time Program ExecutionThis chapter focuses on when and how the run-time interface executes you

Página 119

Single- Versus Multitasking Environments7-5Executing Multitasking ModelsIn cases where the continuous part of a model executes at a rate that isdiffer

Página 120 - File and Function Splitting

7 Models with Multiple Sample Rates7-6The following diagrams illustrate how mixed-rate systems are handled by theReal-Time Workshop in these two envir

Página 121

Single- Versus Multitasking Environments7-7Figure 7-3: Pseudomultitasking Using Overlapped InterruptsThis diagram illustrates how overlapped interrup

Página 122 - Function Split Threshold

7 Models with Multiple Sample Rates7-8SingletaskingIt is possible to execute the model code in a strictly singletasking manner.While this method is le

Página 123

Single- Versus Multitasking Environments7-9Simulating Models with SimulinkBefore Simulink simulates a model, it orders all of the blocks based upon th

Página 124

Related Products and DocumentationxixStateflow machine. This S-function is the agent Simulink interacts with forsimulation and analysis.The control be

Página 125 - External Mode

7 Models with Multiple Sample Rates7-10See “Multitasking and Pseudomultitasking” on page 7–5 for a description ofhow this works. It is important to un

Página 126 - Introduction

Sample Rate Transitions7-11Sample Rate TransitionsThere are two possible sample rate transitions that can exist within a model:• A faster block drivin

Página 127

7 Models with Multiple Sample Rates7-12In transitioning from slower to faster blocks, you must add Unit Delay blocksbetween slow to fast transitions a

Página 128

Sample Rate Transitions7-13Simulink does not execute in real-time, which means that it is not bound byreal-time constraints. Simulink waits for, or mo

Página 129

7 Models with Multiple Sample Rates7-14The sample time of the Zero Order Hold block must be set to 2 sec (i.e., thesample time of the slower block).Th

Página 130 - 4 External Mode

Sample Rate Transitions7-15As you can see from the preceding diagrams, Simulink can simulate modelswith multiple sample rates in an efficient manner.

Página 131 - Signals & Triggering

7 Models with Multiple Sample Rates7-16This timing diagram illustrates two problems:1 Execution of the slower block is split over more than one faster

Página 132

Sample Rate Transitions7-17Three key points about this diagram:1 Unit delay output runs in 1 sec task, but only at its rate (2 sec). The outputof the

Página 133 - A and B.WithA=2 and B=3,the

7 Models with Multiple Sample Rates7-18Note Inserting a Unit Delay block changes the model. The output of theslower block is now delayed by one time

Página 134 - External Mode Control Panel

8Targeting Tornado forReal-Time ApplicationsIntroduction ...8-2Confirming Your Tornado Setup Is Operational . . . . . . 8-2VxWorksLib

Página 135 - Target Interface

Forewordxxdiagrams. Stateflow brings system specification and design closer together. Itis easy to create designs, consider various scenarios, and it

Página 136

8 Targeting Tornado for Real-Time Applications8-2IntroductionThis chapter describes how to create real-time programs for execution underVxWorks, which

Página 137

Introduction8-3for additional information about installation and operation of VxWorks andTornado products.VxWorks LibrarySelecting VxWorks Support und

Página 138

8 Targeting Tornado for Real-Time Applications8-4There is a second sublibrary, the IO Devices library, that contains support forthese drivers:• Matrix

Página 139 - Data Archiving

Run-time Architecture Overview8-5Run-time Architecture OverviewIn a typical VxWorks-based real-time system, the hardware consists of a UNIXor PC host

Página 140

8 Targeting Tornado for Real-Time Applications8-6External ModeSimulink external mode provides a mechanism to download new parametervalues to the execu

Página 141

Run-time Architecture Overview8-7Note You may need to enter a routing table entry into VxWorks if your hostis not on the same local network (subnet)

Página 142 - Update Diagram

8 Targeting Tornado for Real-Time Applications8-8StethoScopeWith StethoScope, you can access the output of any block in the model (in thereal-time pro

Página 143

Run-time Architecture Overview8-9The program creates VxWorks tasks to run on the real-time system: onecommunicates with Simulink, the others execute t

Página 144

8 Targeting Tornado for Real-Time Applications8-10Multitasking. Optionally, the model can run as multiple tasks, one for eachsample rate in the model.

Página 145

Implementation Overview8-11Implementation OverviewTo implement and run a VxWorks-based real-time program using theReal-Time Workshop, you must:• Desig

Página 146 - Interface

How to Use This GuidexxiHow to Use This GuideTypographical ConventionsTo Indicate... This Guide Uses... ExampleNew terms Italics An array is an ordere

Página 147

8 Targeting Tornado for Real-Time Applications8-12Figure 8-3: Source Modules Used to Build the VxWorks Real-Time ProgramThis diagram illustrates the

Página 148 - MEX-File Optional Arguments

Implementation Overview8-13Adding Device Driver BlocksThe real-time program communicates with the I/O devices installed in theVxWorks target chassis v

Página 149 - Options on the Real-Time

8 Targeting Tornado for Real-Time Applications8-14Edit the following lines to reflect your setup.VX_TARGET_TYPE = 68kCPU_TYPE = MC68040Downloading Con

Página 150 - Possible Error Conditions

Implementation Overview8-15Specifying the Real-Time Build OptionsSet the real-time build options using the Solver and Real-Time Workshoppages of theSi

Página 151

8 Targeting Tornado for Real-Time Applications8-16Next, use the System Target File Browser to select the correct Real-TimeWorkshop page settings for T

Página 152

Implementation Overview8-17Build Command Options. You can specify build command options on the CodeGeneration Optionsdialog box. Click the Options but

Página 153 - Monitoring

8 Targeting Tornado for Real-Time Applications8-18• MATLAB MAT-file — to enable data logging during program execution,checkMAT-file logging. The progr

Página 154 - To File Block MAT-Files

Implementation Overview8-19Downloading and Running the Executable InteractivelyIf automatic downloading is disabled, you must use the Tornado tools to

Página 155

8 Targeting Tornado for Real-Time Applications8-20external mode during the build procedure.) It also initializes StethoScope if youselected this optio

Página 156 - C API for Signal Monitoring

Implementation Overview8-21The following table lists the arguments to this SimStruct.Table 8-1: Arguments to the rt_main SimStruct modelA pointer to

Página 157

ForewordxxiiInstallationYour platform-specific MATLAB Installation Guide provides essentially all ofthe information you need to install the Real-Time

Página 158

8 Targeting Tornado for Real-Time Applications8-22Calling rt_main. To begin program execution, call rt_main from WindSh.Forexample,sp(rt_main, vx_equa

Página 159

9Targeting DOS forReal-Time ApplicationsIntroduction ...9-2DOSDeviceDriversLibrary...9-3Implementation Overview ...

Página 160

9 Targeting DOS for Real-Time Applications9-2IntroductionThis chapter provides information that pertains specifically to using theReal-Time Workshop i

Página 161

Introduction9-3DOS Device Drivers LibrarySelecting DOS Device Drivers under the Real-Time Workshop library in theSimulink Library Browser opens the DO

Página 162

9 Targeting DOS for Real-Time Applications9-4Implementation OverviewThe Real-Time Workshop includes DOS run-time interface modules designedto implemen

Página 163 - Program Architecture

Implementation Overview9-5This diagram illustrates the code modules that are used to build a DOSreal-time program.To execute the code in real time, th

Página 164

9 Targeting DOS for Real-Time Applications9-6Hardware RequirementsThe hardware needed to develop and run a real-time program includes:• A workstation

Página 165

Implementation Overview9-7source code of the device drivers for the Keithley Metrabyte DAS 1600/1400Series I/O boards. See the “Device Driver Blocks”

Página 166 - Model Execution

9 Targeting DOS for Real-Time Applications9-8The fastest sample rate you can define is determined by the minimum valuefrom which the counter can count

Página 167

Device Driver Blocks9-9Device Driver BlocksThe real-time program communicates with external hardware via a set ofdevice drivers. These device drivers

Página 168

InstallationxxiiiIf you experience installation difficulties and have Web access, connect to TheMathWorkshomepage(http://www.mathworks.com). Look for

Página 169

9 Targeting DOS for Real-Time Applications9-10To access the device driver blocks, double-click on the sublibrary icon.The blocks in the library contai

Página 170

Device Driver Blocks9-11Analog Input (ADC) Block Parameters• Base I/O Address —Thebeginning of the I/O address spaceassigned to the board. The valuesp

Página 171

9 Targeting DOS for Real-Time Applications9-12• Sample Time (sec) — Device drivers are discrete blocks that require you tospecify a sample time. In th

Página 172

Device Driver Blocks9-13• Number of Channels — Number of DAC channels enabled. The DAS-1600Series I/O boards have two 12-bit DAC channels. The DAS-140

Página 173

9 Targeting DOS for Real-Time Applications9-14Digital Output Block Parameters• Base I/O Address —Thebeginning of the I/O address spaceassigned to the

Página 174

Device Driver Blocks9-15executed at the specified rate. Specifically, when the digital output block isexecuted, it causes corresponding boolean values

Página 175

9 Targeting DOS for Real-Time Applications9-16Building the ProgramOnce you have created your Simulink model and added the appropriate devicedriver blo

Página 176

Building the Program9-17workstation. You can verify this by checking the environment variable,WATCOM, which correctly points to the directory where th

Página 177

9 Targeting DOS for Real-Time Applications9-18

Página 178

10Targeting CustomHardwareIntroduction ...10-2Run-Time Interface ...10-4Creating System Target Files and Template Makef

Página 179

ForewordxxivMicrosoft Visual C/C++Define the environment variable MSDevDir to beMSDevDir=<path to compiler> for Visual C/C++ 4.2MSDevDir=<p

Página 180

10 Targeting Custom Hardware10-2IntroductionThis chapter contains information on targeting custom hardware andimplementing device driver blocks. By im

Página 181

Introduction10-3Note For examples of device drivers, see the S-functions supplied inmatlabroot/rtw/c/tornado/devices and matlabroot/rtw/c/dos/devices

Página 182

10 Targeting Custom Hardware10-4Run-Time InterfaceThere are two ways to target custom hardware:• Rapid prototyping• Embedded real-timeRapid prototypin

Página 183

Creating System Target Files and Template Makefiles10-5Creating System Target Files and Template MakefilesAssuming that you’ve created the directory/a

Página 184

10 Targeting Custom Hardware10-6Clicking the Build button causes the Real-Time Workshop to generate code asdictated bymytarget.tlc and compile it as d

Página 185

Implementing Device Drivers10-7Implementing Device DriversS-functions can be built into MEX-files or compiled and linked with other codeto become part

Página 186

10 Targeting Custom Hardware10-8You can add your own blocks to a device driver library by writing S-functionsthat implement device drivers for your pa

Página 187 - SimStruct,but

Implementing Device Drivers10-9- Reading values from an I/O device and assigning these values to theblock’s output vectory (ifitisanADC)- Writing valu

Página 188

10 Targeting Custom Hardware10-10Figure 10-1: Format of a Device Driver S-Function #define S_FUNCTION_NAME filenameDefine a name for the entry point

Página 189 - Initialization

Implementing Device Drivers10-11S_FUNCTION_NAME DefinitionThe statement#define S_FUNCTION_NAME namedefines the name of the function that is the entry

Página 190 - Components

Where to Go from HerexxvWhere to Go from HereChapter 1, “Introduction to the Real-Time Workshop,” is a quick introductionto the rapid prototyping proc

Página 191

10 Targeting Custom Hardware10-12Conditional CompilationsIn general, you can use an S-function in these environments:• Simulink• Real-TimeWhen you use

Página 192

Implementing Device Drivers10-13Next define a variable used to store the integer (which is the number ofchannels in this example):uint_T num_channels;

Página 193

10 Targeting Custom Hardware10-14This list describes the function of each macro in mdlInitializeSizes:• ssSetNumSFcnParams — The number of input param

Página 194 - The SimStruct Data Structure

Implementing Device Drivers10-15The following example illustrates the definition of mdlInitializeSizes for aDAC:static void mdlInitializeSizes(SimStru

Página 195 - — MdlInitializeSampleTimes

10 Targeting Custom Hardware10-16Initializing the I/O DeviceDevice driver S-functions use the mdlInitializeConditions function to:• Read parameters fr

Página 196 - Inlining S-Functions

Implementing Device Drivers10-17All S-functions call the mdlOutputs function to calculate block outputs. For adevice driver block, this function conta

Página 197

10 Targeting Custom Hardware10-18The Termination FunctionThe final required function is typically used only in DACs to zero the output atthe end of th

Página 198 - Embedded Program Framework

Implementing Device Drivers10-19The Public Registration FunctionThe include file cg_sfun.h defines a function that is the entry point for theS-functio

Página 199

10 Targeting Custom Hardware10-20Setting the MATLAB PathThe device driver blocks in a library can automatically change your MATLABpath to ensure that

Página 200

11Real-Time WorkshopLibrariesIntroduction ...11-2Custom Code Library ...11-4CustomModelCode ...11-4CustomS

Página 201 - Sample Rates

ForewordxxviChapter 12, “Configuring Real-Time Workshop for Your Application,”compares and contrasts various targets, including the generic real-time

Página 202

11 Real-Time Workshop Libraries11-2IntroductionThe Real-Time Workshop provides a library of functions that allow you greatflexibility in constructing

Página 203 - Solver options pull-down

Introduction11-3• S-Function Target — This block is intended for use in conjunction with theReal Time W S-function code format. See “S-Function Code F

Página 204

11 Real-Time Workshop Libraries11-4Custom Code LibraryThe Real-Time Workshop also provides a Custom Code library containingblocks that allow you to pl

Página 205 - Executing Multitasking Models

Custom Code Library11-5• model.h — Header File block•model.prm — Parameter File block•model.c — Source File block•model.reg — Registration File blockT

Página 206 - Highest Priority

11 Real-Time Workshop Libraries11-6Double clicking the Model Start Function block opens a the MdlStartFunction Custom Codedialog box.You can insert cu

Página 207

Custom Code Library11-7The code below is the MdlStart function for this example (mymodel).void MdlStart(void){ /* user code (Start function Header) *

Página 208 - Singletasking

11 Real-Time Workshop Libraries11-8• Subsystem Enable• Subsystem Disable• Subsystem Outputs• Subsystem Update• Subsystem DerivativesThe location of th

Página 209 - Executing Models in Real-Time

Interrupt Handling11-9Interrupt HandlingThe Real-Time Workshop provides blocks in the Interrupt Template librarythat allow you to model synchronous/as

Página 210 - Singletasking Operation

11 Real-Time Workshop Libraries11-10subsystem (or Stateflow Chart). The Asynchronous Interrupt block theninstalls the Task Synchronization block as th

Página 211 - Sample Rate Transitions

Interrupt Handling11-11concept:Figure 11-1: Using the Asynchronous Interrupt Block with Simulink’s Library Feature in the Rapid Prototyping Process B

Página 212 - T=2sT=1s

1Introduction to theReal-Time WorkshopIntroduction ...1-2The Real-Time Workshop ...1-3Real-TimeWorkshopApplications...

Página 213

11 Real-Time Workshop Libraries11-12generation on the board. You must match the interrupt level and vectorspecified in the Asynchronous Interrupt bloc

Página 214

Interrupt Handling11-13• VME Interrupt Offset Number(s) — the Real-Time Workshop uses thisnumber in the call tointConnect(INUM_TO_IVEC(#),...). You sh

Página 215

11 Real-Time Workshop Libraries11-14Asynchronous Interrupt Block Example - Simulation ModeThis example shows how the Asynchronous Interrupt block work

Página 216

Interrupt Handling11-15Asynchronous Interrupt Block Example - RTW ModeThis example shows the Asynchronous Interrupt block in RTW mode:Note that the si

Página 217

11 Real-Time Workshop Libraries11-16Locking and Unlocking ISRs. It is possible to lock ISRs so that they are notpreempted by a higher priority interru

Página 218 - Unit Delay

Interrupt Handling11-17• A semaphore is created to synchronize the downstream system to theexecution of the Task Synchronization block.• Code is added

Página 219 - Real-Time Applications

11 Real-Time Workshop Libraries11-18VxWorks system. In particular, the default priority of the model code is 30and, when multitasking is enabled, the

Página 220

Interrupt Handling11-19creates and initializes the synchronization semaphore. It also spawns thefunction-call subsystem as an independent task./* Crea

Página 221 - VxWorks Support library

11 Real-Time Workshop Libraries11-20Asynchronous Buffer BlockTheVxWorksDoubleBufferblocksaremeanttobeusedtointerfacesignalstoasynchronous function-cal

Página 222 - Help button on the

Interrupt Handling11-21Asynchronous Buffer Block ParametersThere are two kinds of Asynchronous Buffer blocks, a reader and a writer. Thepicture below

Página 223 - WindSh (the

iContentsForewordRelated Products and Documentation ... xviRequirements... xviWhatIsMATLAB? ...

Página 224

1 Introduction to the Real-Time Workshop1-2IntroductionThe Real-Time Workshop, for use with MATLAB and Simulink, produces codedirectly from Simulink m

Página 225

11 Real-Time Workshop Libraries11-22Asynchronous Buffer Block ExampleThis example shows how you might use the Asynchronous Buffer block tocontrol the

Página 226 - StethoScope

Interrupt Handling11-23This will cause blocks up- or downstream from it, which would otherwiseinherit from the function-call subsystem, to use the sam

Página 227 - VxWorks Tasks

11 Real-Time Workshop Libraries11-24Rate Transition Block ExampleThis picture shows a sample application of the Rate Transition block in an ISR:In thi

Página 228

Creating a Customized Asynchronous Library for Your System11-25Creating a Customized Asynchronous Library for Your SystemYou can use the Real-Time Wor

Página 229 - Implementation Overview

11 Real-Time Workshop Libraries11-26

Página 230

12Configuring Real-TimeWorkshop for YourApplicationIntroduction ...12-2Interaction between SimulinkandtheReal-TimeWorkshop ...

Página 231 - VxWorks Configuration

12 Configuring Real-Time Workshop for Your Application12-2IntroductionThis chapter discusses how Simulink interacts with the Real-Time Workshopand als

Página 232 - Downloading Configuration

Introduction12-3One of the key components of Simulink is its engine, which propagates datafrom one block to the next along signal lines. The data prop

Página 233 - Step Size

12 Configuring Real-Time Workshop for Your Application12-4This figure shows the propagation of the signal attributes associated with theInport block t

Página 234

Introduction12-5start time and Tfis the simulation stop time. If Tfis infinity, the defaultsample time is set to 0.2.To ensure a completely determinis

Página 235

The Real-Time Workshop1-3The Real-Time WorkshopThe Real-Time Workshop provides a real-time development environment thatfeatures:• A rapid and direct p

Página 236 - Initiating the Build

12 Configuring Real-Time Workshop for Your Application12-6generator to properly specify the rate at which f() should be executed as shownin theconnect

Página 237 - Running the Program

Introduction12-7target throughout development. The real-time format is the mostcomprehensive code format and supports almost all the built-in blocks.I

Página 238

12 Configuring Real-Time Workshop for Your Application12-8Table 12-1: Features Supported by Real-Time Workshop Targets and Code Formats Real-TimeReal

Página 239

Introduction12-9Executes inhardreal-timeXX X XNonreal-timeexecutableincludedXX X XMultipleinstantiationof one model(provided noStateflowblocks are iny

Página 240

12 Configuring Real-Time Workshop for Your Application12-10Real-Time Code FormatThe real-time code format (corresponding to the generic real-time targ

Página 241 - Targeting DOS for

Real-Time Code Format12-11Template Makefiles• drt.tmf• grt- grt_bc.tmf —BorlandC-grt_vc.tmf —VisualC-grt_watc.tmf —WatcomC-grt_unix.tmf —UNIXhost•osek

Página 242

12 Configuring Real-Time Workshop for Your Application12-12Real-Time malloc Code FormatThe real-time malloc code format (corresponding to the generic

Página 243

Real-Time malloc Code Format12-13Template Makefiles• grt_malloc- grt_malloc_bc.tmf — Borland C-grt_malloc_vc.tmf —VisualC-grt_malloc_watc.tmf —WatcomC

Página 244

12 Configuring Real-Time Workshop for Your Application12-14Embedded-C Code FormatThe embedded-C code format (corresponding to the embedded real-time t

Página 245

Embedded-C Code Format12-15• Select the Single output/update function check box. Combining the outputand update functions allows the Real-Time Worksho

Página 246 - Device Drivers

1 Introduction to the Real-Time Workshop1-4• High-speed stand-alone simulations.• Generation of portable C code for export to other simulation program

Página 247 - Simulink Host

12 Configuring Real-Time Workshop for Your Application12-16Unsupported BlocksThe embedded-C format does not support the following built-in blocks:• Co

Página 248 - Modifying Program Timing

Embedded-C Code Format12-17Template Makefiles• ert_bc.tmf —BorlandC•ert_vc.tmf —VisualC•ert_watc.tmf —WatcomC•ert_unix.tmf — UNIX host

Página 249 - Device Driver Blocks

12 Configuring Real-Time Workshop for Your Application12-18S-Function Code FormatThe S-function code format (corresponding to the RTW S-function targe

Página 250

S-Function Code Format12-19functionality of the sfun model. The picture below shows the sfun_sf blockembedded in a new model.After you have placed the

Página 251

12 Configuring Real-Time Workshop for Your Application12-20Restrictions• Hand-written S-functions without corresponding TLC files must containexceptio

Página 252 - [-10 10] volts. Refer

Optimizations Common to All Code Formats12-21Optimizations Common to All Code FormatsGeneral Modeling TechniquesThe following are techniques that you

Página 253

12 Configuring Real-Time Workshop for Your Application12-22Stateflow OptimizationsIf your model contains Stateflow blocks, select the Use Strong Data

Página 254 - [lo hi],for

Optimizations Common to All Code Formats12-23Diagnostic Page• Deselect the Disable optimized block I/O storage check box. Disablingoptimized block I/O

Página 255 - Including Device Driver Code

12 Configuring Real-Time Workshop for Your Application12-24vector. Note that you can override the inlining of individual parameter byusing theTunable

Página 256 - Building the Program

Optimizations Common to All Code Formats12-25• Select the Inline invariant signals check box. The Real-Time Workshop willnot generate code for blocks

Página 257

The Real-Time Workshop1-5a fixed, user-specified sample rate. Continuous time models are incorporatedinto this code with the simple provision that the

Página 258

12 Configuring Real-Time Workshop for Your Application12-26

Página 259 - Hardware

13Real-Time WorkshopRapid Simulation TargetIntroduction ...13-2Building for the Rapid Simulation Target ...13-4RunningaRapidSimula

Página 260

13 Real-Time Workshop Rapid Simulation Target13-2IntroductionThe Real-Time Workshop rapid simulation target (rsim) consists of a set oftarget files fo

Página 261

Introduction13-3you can easily write simple scripts that will run a set of simulations insequence while using new data sets. These scripts can be writ

Página 262 - Run-Time Interface

13 Real-Time Workshop Rapid Simulation Target13-4Building for the Rapid Simulation TargetBy specifying the system target file (rsim.tlc)andthetemplate

Página 263

Building for the Rapid Simulation Target13-5real-time target, on the other hand, is a starting point for targeting a newprocessor.A single build of yo

Página 264

13 Real-Time Workshop Rapid Simulation Target13-6at the MATLAB prompt. Typew = 100;zeta = 0.5;to set parameters. Copy a test data file by typing!matla

Página 265 - Implementing Device Drivers

Building for the Rapid Simulation Target13-7Replacing Input Signal Data. New data for a From File block can be placed in astandard MATLAB MAT-file. As

Página 266

13 Real-Time Workshop Rapid Simulation Target13-8This picture shows the resulting plot.As a result the new data file is read and the simulation progre

Página 267 - Required Functions

Building for the Rapid Simulation Target13-9<-o> Specifying a New Output Filename for the SimulationIf you have specified Save to Workspace opti

Página 268

1 Introduction to the Real-Time Workshop1-6The Rapid Prototyping ProcessThe Real Time Workshop allows you to do rapid prototyping, a process thatallow

Página 269 - Defining the SimStruct

13 Real-Time Workshop Rapid Simulation Target13-10incorrect simulation results. In this case, where model structure has changed,you must regenerate th

Página 270

Building for the Rapid Simulation Target13-11<-s> Specifying a New Stop Time for an rsim SimulationIf a new stop time is not provided, the simul

Página 271

13 Real-Time Workshop Rapid Simulation Target13-12From Workspace data must be contained in a structure variable with thefollowing fields:var.timevar.s

Página 272

Building for the Rapid Simulation Target13-13Simulation PerformanceIt is not possible to predict accurately the simulation speed-up of an rsimsimulati

Página 273 - Initializing Sample Times

13 Real-Time Workshop Rapid Simulation Target13-14demonstrate how rsim canbecalledrepeatedlywithinanM-fileforMonteCarlo simulations.

Página 274 - Initializing the I/O Device

14Real-Time WorkshopAda CoderIntroduction ...14-2Real-Time Workshop Ada Coder Applications . . . . . . . 14-3SupportedCompilers...

Página 275 - DAC Outputs

14 Real-Time Workshop Ada Coder14-2IntroductionThis chapter presents an introduction to the Real-Time Workshop Ada Coder.It compares and contrasts the

Página 276 - The Termination Function

Introduction14-3Real-Time Workshop Ada Coder ApplicationsLike the Real-Time Workshop, the Real-Time Workshop Ada Coder supports avariety of real-time

Página 277

14 Real-Time Workshop Ada Coder14-4All Simulink blocks are automatically converted to code, with the exception of:• MATLAB function blocks• Any contin

Página 278

Introduction14-5generation. You can, however, perform explicit upcasting using the DataType Conversion block in Simulink.S-FunctionsS-functions provid

Página 279 - Libraries

The Rapid Prototyping Process1-7The traditional approach to real-time design and implementation typicallyinvolves multiple teams of engineers, includi

Página 280

14 Real-Time Workshop Ada Coder14-6Getting Started This section illustrates, through a simple example, how to transform aSimulink model into a stand-a

Página 281

Getting Started14-7Setting Options for Ada Code GenerationYou must specify the correct options before you generate Ada code from thismodel. These are

Página 282 - Custom Code Library

14 Real-Time Workshop Ada Coder14-8Alternatively, you can specify the settings on the Real-Time Workshop pagemanually by following these steps:1 Selec

Página 283

Getting Started14-9Generated FilesThis table lists the Ada files generated by the Real-Time Workshop Ada Coderfrom the counter demonstration (counters

Página 284 - Function Custom Code

14 Real-Time Workshop Ada Coder14-10Create model times2 using these blocks:• Sine Wave (sample time = 0.1)•timestwo S-function (provided in the matlab

Página 285

Getting Started14-11The times2 model contains a simple S-function, called timestwo,thattakestheinput sine wave signal and doubles its amplitude. The T

Página 286

14 Real-Time Workshop Ada Coder14-12Configuring the Template MakefileTemplate makefiles specify the compiler, link, and make directives native tothe t

Página 287 - Interrupt Handling

Getting Started14-13Application Modules Required for the Real-Time ProgramBuilding the real-time program requires a number of support files in additio

Página 288

14 Real-Time Workshop Ada Coder14-14Tunable ParametersIf you select Inline parameters on the Real-Time Workshop page, the Tunableparametersbutton acti

Página 289

Getting Started14-15- ImportedExtern — the variable is assumed to be declared in the packagespecification entered in theStorage Type Qualifier field.

Página 290

1 Introduction to the Real-Time Workshop1-8The figure below shows the rapid prototyping process in more detail.Figure 1-2: The Rapid Prototyping Deve

Página 291

14 Real-Time Workshop Ada Coder14-16To change the storage class of a signal, select it in your Simulink model; thenselectSignal Properties under the E

Página 292

Getting Started14-17specification. The generated code accesses this signal asRT_U.Signal_Name.- ExportedGlobal — declares the signal as a global varia

Página 293

14 Real-Time Workshop Ada Coder14-18Code ValidationAfter completing the build process, the stand-alone version of thecountersdemo model is ready for c

Página 294

Code Validation14-19The “!” character passes the command that follows it to the operating system.This command, therefore, runs the stand-alone version

Página 295

14 Real-Time Workshop Ada Coder14-20Analyzing Data with MATLABPoints to consider when data logging:• The Ada Coder only supports data logging to a mat

Página 296

Supported Blocks14-21Supported BlocksThe Real-Time Workshop Ada Coder supports the following Simulink blocks.Discrete BlocksDiscrete-Time Integrator D

Página 297

14 Real-Time Workshop Ada Coder14-22Nonlinear BlocksBacklash QuantizerCoulomb & Viscous Friction RelayDeadZone SaturationManual Switch (must Break

Página 298

Supported Blocks14-23SinksDisplay — no code is generated forthis blockTo FileScope — matrix data logging only(double arrays)To Workspace — matrix data

Página 299

14 Real-Time Workshop Ada Coder14-24

Página 300

AReal-Time WorkshopDirectory Tree

Página 301

The Rapid Prototyping Process1-9This highly productive development cycle is possible because the Real-TimeWorkshop is closely tied to MATLAB and Simul

Página 302 - Rate Transition Block Example

A Real-Time Workshop Directory TreeA-2Real-Time Workshop Directory TreeThe files provided to implement real-time and generic real-time applicationsres

Página 303 - Library for Your System

Real-Time Workshop Directory TreeA-3The matlabroot/rtw/c Directorymatlabroot/rtw/ctlcgrtdostornadolibsrctoolssrcrtwsfcnertgrt_mallocwindowsosek_leorsi

Página 304

A Real-Time Workshop Directory TreeA-4Directory Purposematlabroot/rtw/c/dosFiles for targeting DOSmatlabroot/rtw/c/ertFiles for targeting embedded C c

Página 305 - Application

Real-Time Workshop Directory TreeA-5The matlabroot/simulink DirectoryThe matlabroot/toolbox DirectoryDirectory Purposematlabroot/simulink/includeInclu

Página 306

A Real-Time Workshop Directory TreeA-6The matlabroot/extern DirectoryDirectory Purposematlabroot/extern/includeInclude files used to build the targetm

Página 307

BGlossary

Página 308

B GlossaryB-2Application Modules − With respect to Real-Time Workshop programarchitecture, these are collections of programs that implement functionsc

Página 309

B-3Generic Real-Time − An environment where model code is generated for areal-time system, and the resulting code is simulated on your workstation.(No

Página 310

B GlossaryB-4Makefiles − Files that contain a collection of commands that allow groups ofprograms, object files, libraries, etc. to interact. Makefile

Página 311

B-5Target File − A file that is compiled and executed by the Target LanguageCompiler. A combination of these files describes how to transform theReal-

Página 312

1 Introduction to the Real-Time Workshop1-10You can monitor signals using Scope blocks while running external mode.Simply connect Scope blocks to sign

Página 313

B GlossaryB-6

Página 314 - Real-Time Code Format

I-1IndexAapplication modulesapplication specific layer 6-35common layer 6-31definition of 6-25Asynchronous Buffer block 11-20Asynchronous Interrupt bl

Página 315

IndexI-2device driver blocks 9-9adding to model 9-15device drivers 9-6digital input block parameters 9-13digital output block parameters 9-14hardware

Página 316 - Real-Time malloc Code Format

IndexI-3under DOS 7-3under VxWorks 7-3interrupt service routine (ISR) 9-5locking and unlocking 11-16interrupt templates library 11-9LlibraryCustom Cod

Página 317

IndexI-4program buildingDOSreal-time 9-16VxWorksbuild command options 8-17real-time options 8-14setting step size 8-15program executiondata logging fu

Página 318 - Embedded-C Code Format

IndexI-5sample tiime overlaps 7-15S-functionsAPI 6-34device driver 10-9format of 10-8inlining 1-4, 10-7locating source code for 6-34models containing

Página 319 - Local block outputs

IndexI-6UUNIX 2-18template makefiles 2-18Vvirtual blocks 1-18VxWorksapplication overview 8-5build command options 8-17configuringfor external mode (so

Página 320 - System Target File

The Rapid Prototyping Process1-11Algorithm Design and AnalysisFrom the block diagrams developed during the modeling stage, you can extractstate-space

Página 321

iiThe Rapid Prototyping Process ... 1-6KeyAspectsofRapidPrototyping... 1-6RapidPrototypingforDigitalSigna

Página 322 - S-Function Code Format

1 Introduction to the Real-Time Workshop1-12Open Architecture of the Real-Time WorkshopThe Real-Time Workshop is an open and extensible system designe

Página 323

Open Architecture of the Real-Time Workshop1-13Figure 1-3: The Real-Time Workshop’s Open ArchitectureMATLABSimulinkReal-Time Workshop BuildTargetLang

Página 324 - Restrictions

1 Introduction to the Real-Time Workshop1-14Target Language CompilerTo generate code, the Real-Time Workshop invokes the Target LanguageCompiler (TLC)

Página 325 - General Modeling Techniques

Open Architecture of the Real-Time Workshop1-15S-FunctionsS-functions allow you to add custom code to your Simulink model. You canembed the code direc

Página 326 - Simulation Parameters

1 Introduction to the Real-Time Workshop1-16options, and additional information for the destination (target) of thegenerated executable.Themodel.mk fi

Página 327 - Real-Time Workshop Page

Open Architecture of the Real-Time Workshop1-17A First Look at Real-Time Workshop FilesAn example of a Simulink model is this block diagram:Figure 1-4

Página 328

1 Introduction to the Real-Time Workshop1-18example.rtw,whichisthe.rtw file associated with “A Simple Simulink Model”on page 1-17:Note thatmodel.rtw f

Página 329 - Compiler Options

Open Architecture of the Real-Time Workshop1-19Language Compiler Reference Guide, which contains detailed descriptions ofthe contents ofmodel.rtw file

Página 330

1 Introduction to the Real-Time Workshop1-20assigning buffers to each input and output. Compare this to the MdlOutputsfunction generated with buffer o

Página 331 - Rapid Simulation Target

Open Architecture of the Real-Time Workshop1-21Using Stateflow and Blocksets with the Real-Time WorkshopStateflow is a graphical design and developmen

Página 332

iii4.ValidatingGeneratedCode ... 2-55. Incorporating Generated Code into Legacy Code . . . . . . . . . . 2-56.IncorporatingLeg

Página 333

1 Introduction to the Real-Time Workshop1-22

Página 334 - File Browser

2Getting Started with theReal-Time WorkshopIntroduction ...2-2Where to Find Information in This Manual ...2-3Basic Concepts in the

Página 335

2 Getting Started with the Real-Time Workshop2-2IntroductionThis chapter begins a discussion of basic concepts used in real-timedevelopment and relate

Página 336 - Build buttonontheReal-Time

Where to Find Information in This Manual2-3Where to Find Information in This ManualThis section discusses typical requirements for producing real-time

Página 337

2 Getting Started with the Real-Time Workshop2-4• Write a harness program (i.e., main)• Install a C compilerA bundled harness program is supplied for

Página 338

Where to Find Information in This Manual2-5LibMdlRegCustomCode, LibSystemInitializeCustomCode, LibSystemOutputCustomCode, LibSystemUpdateCustomCode, L

Página 339

2 Getting Started with the Real-Time Workshop2-66. Incorporating Legacy Code into Generated CodeLegacy code, or hand-written code, is existing code th

Página 340

Where to Find Information in This Manual2-7• External mode — you can tune parameters from Simulink while running thegenerated code on a target process

Página 341

2 Getting Started with the Real-Time Workshop2-8Basic Concepts in the Real-Time WorkshopBefore going through a step-by-step example of how to target s

Página 342

Basic Concepts in the Real-Time Workshop2-9target environments and the system target files and template makefilesassociated with each example environm

Página 343 - Simulation Performance

ivTargeting dSPACE ... 2-28Real-TimeInterface(RTI) ... 2-30Building a Real-Time Executable

Página 344 - Carlo simulations

2 Getting Started with the Real-Time Workshop2-10the Real-Time Workshop page. Finally, if the host on which you are runningmatches theHOST macro speci

Página 345 - Ada Coder

Basic Concepts in the Real-Time Workshop2-11and program building. Therefore, before you generate code and build aprogram, you must verify that the mod

Página 346

2 Getting Started with the Real-Time Workshop2-12Building Generic Real-Time ProgramsThis example describes how to generate C code from a Simulink mode

Página 347

Building Generic Real-Time Programs2-13This is the Simulink model that appears:Figure 2-1: Simulink Model of an F14 AircraftThe model employs a Signa

Página 348

2 Getting Started with the Real-Time Workshop2-14Setting Program ParametersAfter displaying the f14 model, select Parameters from the Simulationpull-d

Página 349

Building Generic Real-Time Programs2-15Note Alternatively, you can select RTW Options from the Tools pull-downmenu. This brings you directly to the R

Página 350 - Getting Started

2 Getting Started with the Real-Time Workshop2-16WhenyouclickontheBuild button in the Simulation Parameters dialog box,the Real-Time Workshop invokes

Página 351

Building Generic Real-Time Programs2-17substitute the numerical values of the model parameters in place of thevariable names. It also instructs Simuli

Página 352 - Generating Ada Code

2 Getting Started with the Real-Time Workshop2-18a MATLAB MAT-file. You can load this data into MATLAB for analysis. See“Blocks That Depend on Absolut

Página 353 - Generated Files

Building Generic Real-Time Programs2-19grt_unix.tmf is designed to be used by GNU Make, which is located inmatlabroot/bin/arch/make (except for Linux

Página 354 - Parameters field blank)

vFile and Function Splitting ... 3-38FileSplitting ... 3-38FunctionSplitting ...

Página 355 - Generating the Ada Code

2 Getting Started with the Real-Time Workshop2-20Generic Real-Time ModulesThese source modules are automatically linked by the makefile, model.mk.Them

Página 356

Blocks That Depend on Absolute Time2-21Blocks That Depend on Absolute TimeSome Simulink blocks use the value of absolute time (i.e., the time from the

Página 357

2 Getting Started with the Real-Time Workshop2-22In addition, data logging time (in the Workspace I/O page of the SimulationParametersdialog box) also

Página 358

Code Validation2-23Code ValidationAfter completing the build process, the stand-alone version of the f14 model isready for comparison with the Simulin

Página 359

2 Getting Started with the Real-Time Workshop2-24Then look at the workspace variables:whoYour variables are:rt_Pilot_G_force rt_tout rt_Angle_of_attac

Página 360 - Signal_Name is declared in

Code Validation2-25Comparing Simulation and Generic Real-Time ResultsYour Simulink simulations and generic real-time code should produce nearlyidentic

Página 361

2 Getting Started with the Real-Time Workshop2-26Comparing Pilot_G_force to rt_Pilot_G_force produces:max(abs(rt_Pilot_G_force-Pilot_G_force))ans = 1

Página 362 - Code Validation

Code Validation2-27Use the MATLAB open_system command to trace the generated code back tothe model. For example,open_system('<S3>') op

Página 363

2 Getting Started with the Real-Time Workshop2-28Targeting dSPACEdSPACE, a company that specializes in real-time hardware and softwareproducts, market

Página 364

Targeting dSPACE2-29Figure 2-3: A PC Setup Including a Target SystemFigure 2-4: The dSPACE PHS BusMotherboard “host”Embedded cards(target system)PC

Página 365 - Supported Blocks

viCreating an External Mode Communication Channel . . . . . . 4-27Rebuildingtheext_commMEX-file ... 4-275Data Logging and Signal Mon

Página 366

2 Getting Started with the Real-Time Workshop2-30Real-Time Interface (RTI)When using the Real-Time Workshop with dSPACE hardware, you mustgenerate tar

Página 367

Targeting dSPACE2-31system target file and template makefile. For the current example, in theReal-Time Workshop page of the dialog box, specify:• Syst

Página 368

2 Getting Started with the Real-Time Workshop2-32This picture shows the Control Desk Control Panel and a sample of ControlDesk plots:Figure 2-5: The

Página 369 - Directory Tree

3Code Generation and theBuild ProcessIntroduction ...3-2Automatic Program Building ...3-3The Real-Time Workshop User Interfa

Página 370

3 Code Generation and the Build Process3-2IntroductionThe Real-Time Workshop simplifies the process of building applicationprograms. One of the Real-T

Página 371

Automatic Program Building3-3Automatic Program BuildingThe Real-Time Workshop automates the task of building a stand-aloneprogram from your Simulink m

Página 372

3 Code Generation and the Build Process3-4Theshadedboxinthefigurebelowoutlinesthesesteps:Figure 3-1: The Build ProcessThe task of creating a stand-al

Página 373

Automatic Program Building3-5When you click the Build button on the Real-Time Workshop page on theSimulation Parameters dialog box, these steps are ca

Página 374 - Directory Purpose

3 Code Generation and the Build Process3-6The Real-Time Workshop User InterfaceYou work with the Real-Time Workshop by interacting with and modifyingf

Página 375

The Real-Time Workshop User Interface3-7System Target FileUse the System target file fieldtospecifythetypeofcodeandtargetforwhichyou are generating co

Página 376

viiRapid Prototyping System Dependent Components . . . . . . . . 6-27ThemainFunction ... 6-27Initialization ...

Página 377

3 Code Generation and the Build Process3-8This table lists the options available.Table 3-2: Target Language Compiler Optional Variables Variable Desc

Página 378 - B Glossary

The Real-Time Workshop User Interface3-9−aFunctionInlineType="mode"Controls how functions are inlined. Thereare two modes:•CodeInsertion• Pr

Página 379

3 Code Generation and the Build Process3-10Inline ParametersInlining parameters refers to a mode where blocks with a constant sample timeare removed f

Página 380

The Real-Time Workshop User Interface3-11Retaining the model.rtw FileWhen modifying the target files, you will need to look at the model.rtw file. Top

Página 381

3 Code Generation and the Build Process3-12select the target appropriate to your application. This is a picture of thebrowser with the generic real-ti

Página 382

The Real-Time Workshop User Interface3-13Table 3-3: Targets Available from the System Target File BrowserTarget/Code Format System Target FileTemplat

Página 383

3 Code Generation and the Build Process3-14Generic Real-Timefor UNIXgrt.tlc grt_unix.tmf make_rtw 3and12Generic Real-Time(dynamic) for PC/UNIXgrt_mall

Página 384 - See Rsim 13-2

The Real-Time Workshop User Interface3-15Options ButtonThere is an Options button on the Real-Time Workshop page of theSimulation Parameters dialog bo

Página 385 - SimStruct data structure

3 Code Generation and the Build Process3-16Generation Options dialog box that varies depending on which system targetfile configuration you selected i

Página 386

The Real-Time Workshop User Interface3-17Verbose builds. This feature forces command line display of code generationstages and compiler output.Invaria

Comentários a estes Manuais

Sem comentários