real-time workshop embedded coder 5...simulators. full support is provided for the integration of...
Post on 02-Jan-2021
3 Views
Preview:
TRANSCRIPT
Real-Time Workshop® Embedded Coder generates C code from Simulink® and Stateflow® models that has the clarity and efficiency of professional handwritten code. The generated code is exceptionally compact and fast—essential requirements for embedded systems, on-target rapid prototyping boards, microprocessors used in mass production, and real-time simulators. Full support is provided for the integration of legacy applications, functions, and data.
You can use Real-Time Workshop Embedded Coder to specify, deploy, and verify production- quality software. The generated code is ANSI/ISO C-compliant, enabling it to run on any microprocessor or real-time operating system (RTOS). Embedded target products (avail-able separately) extend Real-Time Workshop Embedded Coder with target-specific support packages.
Generate C and C++ code optimized for embedded systems
KEy fEATURES
■ Generates ANSI/ISO C and C++ code along with executables from Simulink and Stateflow models with memory usage, exe-cution speed, and readability comparable to handwritten code
■ Extends Real-Time Workshop® and Stateflow® Coder with the optimizations and code configuration features essential for production deployment
■ Supports all Simulink data objects and data dictionary capabil-ities, including user-defined storage classes, types, and aliases
■ Provides target function library code customizations for generating processor-specific code
■ Concisely partitions multirate code for efficient scheduling with or without an RTOS
■ Includes extensible module packaging features and custom data objects
■ Provides a rich set of commenting capabilities with hyperlinks for bidirectional tracing of code to models and requirements
■ Verifies code by automatically importing it into Simulink for software-in-the-loop testing
■ Generates code documentation within Simulink Model Explorer and as stand-alone reports using Simulink report generation capabilities
Fault-Tolerant Fuel Control System - Fixed Point
Accelerating the pace of engineering and science
Resources
visit www.mathworks.com
technical support www.mathworks.com/support
online user community www.mathworks.com/matlabcentral
Demos www.mathworks.com/demos
training services www.mathworks.com/training
thirD-party proDucts anD services www.mathworks.com/connections
WorlDWiDe contactswww.mathworks.com/contact
e-mail info@mathworks.com
Real-Time Workshop® Embedded Coder 5
A fixed-point model with its generated code and an S-function
block for software-in-the-loop testing. Real-Time Workshop
Embedded Coder enables you to generate, document, review,
and test code for complex embedded systems.
Fault-Tolerant Fuel Control System - Fixed Point
Working with Real-Time Workshop Embedded CoderReal-Time Workshop Embedded Coder provides intrinsic code generation support for Simulink and Stateflow, including continuous-time, discrete-time, and event-based models. You interact with Real-Time Workshop Embedded Coder and configure code generation settings using the Simulink Model Explorer. From the Model Explorer, you can:
Generate code for your Simulink models or subsystems
Select a Real-Time Workshop Embedded Coder target
Configure the target for code generation
Manage multiple configuration sets
The Model Advisor in Simulink checks your model configuration and offers advice on how to optimize or tune a configuration set based on your stated goals or style.
•
•
•
•
Selecting TargetsReal-Time Workshop Embedded Coder uses target template files to translate your Simulink and Stateflow model into production- quality C code. The target templates specify the environment in which your generated code will run. The Embedded Real-Time Target included with Real-Time Workshop Embedded Coder generates ANSI/ISO C code and can be configured for floating-point and fixed-point code. You can also extend Embedded Real-Time Target for use in specific applications. You can generate code for any microprocessor by specifying integer word sizes and other required target characteristics or by choosing from a list of targets with predefined settings.
Code Deployment and VerificationYou can use MathWorks link and target products (available separately) to automate deployment and verification of generated code for third-party IDEs and microproces-sors. For more information on link and target products, visit www.mathworks.com/products/rtwembedded/related.html
Specifying the microprocessor for code deployment, either from a predefined list or using generic target settings.
Real-Time Workshop Embedded Coder generates code for virtually all 8-, 16-, and 32-bit microprocessors.
Defining and Managing Custom DataReal-Time Workshop Embedded Coder uses the following data specification and data dictionary capabilities in Simulink when generating code:
Simulink data objects—provides predefined storage classes, including const, volatile, exported global, imported global, #define, structure, bitfield (bit packed structure), and get and set access methods
Module packaging data objects—provides preconfigured attributes for advanced data objects typically used in mass production, such as memory segments to calibrate or tune lookup tables
User data types—lets you create abstract types for complex data
As a result, you can precisely control how model data appears in the generated code, interface with legacy data of any complexity, and augment or replace Simulink built-in types.
The following tools help you design and implement a data dictionary:
Custom Storage Class Designer—lets you graphically create custom definitions and declarations to import data structures into the generated code, export data, conserve memory, or automatically generate data exchange standards, such as ASAM/ASAP2
Simulink Data Object Wizard—analyzes Simulink and Stateflow charts and auto-populates the workspace with appropriate data objects
Real-Time Workshop Embedded Coder gives you access to ASAP2 data exchange files in Simulink, enabling you to export model data with arbitrarily complex data definitions using the ASAP2 standard. You can modify the built-in facilities to produce other data exchange mechanisms.
Model Explorer, populated with a wide variety of data objects. Model
Explorer enables you to quickly create, edit, and view a data dictionary
in Simulink.
A custom storage class created using the Customer Storage Class Designer. It lets you design,
view, and validate arbitrarily complex data types using an intuitive graphical interface.
Executing Code in a Real-Time Production EnvironmentReal-Time Workshop Embedded Coder provides a complete, optimized framework for incorporating generated code into your real-time execution environment. The gener-ated code is target-independent and can be executed with or without an RTOS and in single, multitasking, or asynchronous mode.
Generating a Main ProgramAn extensible main program is generated based on information you provide for deploying the code in your real-time environment. This program lets you generate and build a complete customized executable from your model.
Grouping RatesReal-Time Workshop Embedded Coder generates single-rate or multirate code using periodic sample times specified in the model. For multirate, multitasking models, it employs a strategy called rate grouping that generates separate functions for the base rate task and for each sub-rate task in the model.
Model and code demonstrating the predefined custom storage classes provided with Real-Time Workshop
Embedded Coder. The generated code uses bitfields for the comparison logic in the model as defined by custom storage classes, improving code efficiency.
www.mathworks.com
/* Data with custom storage class ConstVolatile */
extern const volatile real_T O2limit;
extern const volatile real_T pressurelimit;
extern const volatile real_T rpmlimit;
extern const volatile real_T templimit;
/* Struct data */
typedef struct sensors_tag {
real_T temp;
real_T pressure;
real_T O2;
real_T rpm;
} sensors_struct;
/* Bitfield data */
typedef struct alarms_tag {
unsigned int tempalarm:1;
unsigned int pressurealarm:1;
unsigned int O2alarm:1;
unsigned int rpmalarm:1;
} alarms_bitfield;
/* Model step function */
void cscdemo_step(void)
{
/* RelationalOperator: ‘<Root>/Relational Operator’ incorporates:
* Constant: ‘<Root>/Constant’
* Inport: ‘<Root>/In1’
*/
alarms.tempalarm = (templimit >= sensors.temp);
/* RelationalOperator: ‘<Root>/Relational Operator1’ incorporates:
* Constant: ‘<Root>/Constant1’
* Inport: ‘<Root>/In2’
*/
alarms.pressurealarm = (pressurelimit <= sensors.pressure);
/* RelationalOperator: ‘<Root>/Relational Operator2’ incorporates:
* Constant: ‘<Root>/Constant2’
* Inport: ‘<Root>/In3’
*/
alarms.O2alarm = (O2limit <= sensors.O2);
/* RelationalOperator: ‘<Root>/Relational Operator3’ incorporates:
* Constant: ‘<Root>/Constant3’
* Inport: ‘<Root>/In4’
*/
alarms.rpmalarm = (rpmlimit >= sensors.rpm);
}
Model and code demonstrating ISO C
target math extensions and reusable func-
tion optimizations. Real-Time Workshop
Embedded Coder improves code
efficiency by using target- specific and
portable code optimizations.
Optimizing and Packaging CodeReal-Time Workshop Embedded Coder lets you control function boundaries, preserve expressions, and apply optimizations on multiple blocks to further reduce code size. Data can be communicated to the generated code as global data or as function arguments. You can trace the generated code to blocks and signals in your model.
Real-Time Workshop Embedded Coder optimization options enable you to:
Generate processor-specific code for math functions and operators
Reuse code for exporting to legacy or external environments
Eliminate unnecessary initialization, termi-nation, logging, and error-handling code
Combine output/update functions to reduce code size
Remove floating-point code from integer-only applications
Real-Time Workshop Embedded Coder provides module packaging features that let you package the generated code to comply with specific software styles and standards. You can control the internal organization and format of each generated file and determine how global data is defined and referenced.
Templates and symbols let you specify the contents and placement of comments and sections of code within the generated code files.
•
•
•
•
•
/* Model step function */
void ecdemo1_step(Parameters *rtP, BlockIO *rtB, D_Work *rtDWork,
PrevZCSigStates *rtPrevZC, real32_T rtU_input, real32_T *rtY_output)
{
/* local block i/o variables */
uint8_T rtb_sum_out;
uint8_T rtb_switch_out;
boolean_T rtb_equal_to_count;
/* Sum: ‘<Root>/Sum’ incorporates:
* Constant: ‘<Root>/INC’
* UnitDelay: ‘<Root>/X’
*/
rtb_sum_out = 1U + (rtDWork->X);
/* RelationalOperator: ‘<Root>/RelOpt’ incorporates:
* Constant: ‘<Root>/LIMIT’
*/
rtb_equal_to_count = (rtb_sum_out != rtP->LIMIT);
/* SubSystem: ‘<Root>/Computation’ */
if ((rtb_equal_to_count && !rtPrevZC->Computation_ZCE)) {
/* Rounding: ‘<S1>/trunc’ incorporates:
* Gain: ‘<S1>/gain’
* Trigonometry: ‘<S1>/sin’
* Abs: ‘<S1>/abs’
* Inport: ‘<Root>/input’
*/
rtB->output = floorf(((sinf(fabsf(rtU_input))) * 343.0F));
}
rtPrevZC->Computation_ZCE = (ZCSigState) rtb_equal_to_count;
/* Outport: ‘<Root>/output’ */
(*rtY_output) = rtB->output;
/* Switch: ‘<Root>/Switch’ incorporates:
* Constant: ‘<Root>/RESET’
*/
if (rtb_equal_to_count) {
rtb_switch_out = rtb_sum_out;
} else {
rtb_switch_out = 0U;
}
/* UnitDelay Block: <Root>/X */
rtDWork->X = rtb_switch_out;
}
Verifying and Documenting Your CodeReal-Time Workshop Embedded Coder offers several capabilities for verifying your generated code. These include:
Ability to import generated code back into Simulink as an S-function for software-in-the-loop testing with a plant model
User-controlled comments and descriptions to improve code readability and traceability
Support for including requirements in the generated code
Persistent identifier names to minimize code differences between model revisions
•
•
•
•
Real-Time Workshop Embedded Coder documents the generated code in an HTML report that comprehensively describes the code modules and model configuration settings applied during code generation. The report includes a summary section and a table of generated source files, annotated with hyperlinks. When viewed in the MATLAB® Help browser, these hyperlinks cause the corresponding blocks to be highlighted in the associated Simulink model, making the code easy to trace and review. You can also highlight the code from the blocks for bidi-rectional tracing. Automated HTML report generation keeps documentation up to date with your code.
Code samples showing blocks folded into the switch block
operation, increasing CPU throughput. Expression folding
occurs for scalar and element-wise vector operations.
9881v04 09/07
© 2007 MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, Embedded MATLAB, and PolySpace are trademarks of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders.
Resources
visit www.mathworks.com
technical support www.mathworks.com/support
online user community www.mathworks.com/matlabcentral
Demos www.mathworks.com/demos
training services www.mathworks.com/training
thirD-party proDucts anD services www.mathworks.com/connections
WorlDWiDe contactswww.mathworks.com/contact
e-mail info@mathworks.com
Accelerating the pace of engineering and science
/* Model step function */
void slsfexpr_step(void)
{
/* Stateflow: ‘<Root>/Chart’ incorporates:
* Logic: ‘<Root>/Logical Operator’
* RelationalOperator: ‘<Root>/Relational Operator1’
* RelationalOperator: ‘<Root>/Relational Operator’
* Constant: ‘<Root>/Constant’
* Constant: ‘<Root>/Constant1’
* Lookup: ‘<Root>/Look-Up Table’
* Gain: ‘<Root>/Gain’
* Lookup2D: ‘<Root>/Look-Up Table (2-D)’
*/
if(((UPPER >= rtU.input2) || (rtU.input2 <= LOWER))) {
output = rt_Lookup(T1Break, 11, input1 * 2.0, T1Data);
} else {
output = rt_Lookup2D_Normal(T2Break, 3, T2Break, 3, T2Data,
input3, input4);
}
}
Required ProductsMATLABSimulinkReal-Time Workshop
Related ProductsSignal Processing Blockset. Design and simulate signal processing systems and devices
Simulink® Fixed Point. Design and simulate fixed-point systems
Simulink® Report Generator. Automatically generate documentation for Simulink and Stateflow models
Simulink® Verification and Validation. Develop designs and test cases mapped to requirements and measure test coverage
Stateflow Coder. Generate C code from Stateflow charts
For more information on related products, visit www.mathworks.com/products/rtwembedded
Platform and System RequirementsFor platform and system requirements, visit www.mathworks.com/products/rtwembedded ■
top related