Automating the generation of code - Embedded.com

Automating the generation of code

The MathWorks Real-Time Workshop Embedded Coder version 2 enablesthe generation, test, and deployment of highly efficient productionC code for use in real-time embedded systems. Central to the tool isa concise code format with minimal memory and computationalrequirements.

The generated code ROM and RAM size and execution speed arecomparable to optimized, hand-written C code. Real-Time WorkshopEmbedded Coder provides a reduction in development time whileincreasing reliability. It also enables customization, documentation,test, and validation of the generated code, all within the Simulinkenvironment.

It is fully compatible with Stateflow and Stateflow Coder. Itgenerates code for discrete-time Simulink models and includescomments and tags that link code segments back to the block diagram.Symbol names and function boundaries can be preserved to increasereadability. It can be configured either for use with legacy code andcalibration systems or to generate code for an entire project.

Often when designing for implementation on microcontrollers, DSPs,or other production CPUs beyond the scope of rapid prototyping andhardware-in-the-loop systems, additional design considerations becomenecessary. The tool extends the model-based design capabilities ofSimulink, Stateflow, and Real-Time Workshop by adding a softwareengineering dimension to Simulink, specifically for deploying complexembedded systems.

The embedded real-time (ERT) code format produces C code optimizedfor minimal RAM and ROM usage and high CPU throughput. This differsfrom standard Real-Time Workshop code formats, which can includeadditional overhead to support continuous-time systems, signalviewing, and other rapid prototyping-specific debugging features.

Embedded Coder's ERT code format removes these facilities toachieve the smallest footprint possible for the generated code. ERTsupports single-, multi-, and asynchronous rates, as well as singletasking and multitasking. A model generated with the ERT code formatcan represent a stand-alone application or a component feature in alarger system.

In a single operation, the tool generates code for a specifiedsubsystem block in a model, and automatically creates an associatedSimulink S-function. This allows importation of the generated codeback into Simulink for validation with the plant model. Using the newblock as a direct replacement for the original controller subsystem,closed-loop simulations can be run to validate the simulationperformance of the code to be deployed. This step is typically usedfor unit testing prior to running generated code on a chosenmicrocontroller.

HTML code generation reporting

Real-Time Workshop Embedded Coder creates a comprehensive HTMLcode generation report. This report describes code modules andidentifies optimizations applied during code generation for a model.A summary section includes version, date, and options used duringcode generation. When selected options result in non-optimal code,further code optimizations that are available are highlighted. Thisis an indication that applying the noted optimizations can furtherimprove code efficiency. Another section includes a table ofgenerated source files. When viewed in the MATLAB Help browser,hyperlinks in the source files link to the relevant blocks in themodel, making the code extremely traceable.

There is a flexible environment that gives control over thegenerated code. Control is provided for variable naming, data types,storage class, and other attributes of parameters and signals usingthe Simulink Data Class Designer to create Simulink data objects.

In production or fast-turnaround development environments, it isessential to be able to read, understand, and customize the generatedcode. To do this the tool allows the control of function boundaries,preservation of expressions, and application of optimizations onmultiple blocks for further reductions in code size. Each of thesefeatures enables the adjustment of the style, structure, and size ofthe generated code. The origin of the generated code can be traced toblocks and signals in the model.

High-level coding optimizations that are often difficult to applyduring manual coding can also be used. Custom blocks can be added asinlined S-functions or wrapper-style S-functions that are typicallyused for developing a custom library of I/O device drivers.

With the ERT code format, further reductions in code size can beachieved by eliminating initialization and shutdown code that may beunnecessary for a particular application.

Real-Time Workshop Embedded Coder supports Simulink discrete-timeblocks, Stateflow, and blocks from the Fixed-Point Blockset. Simulinkcontinuous-time blocks are not supported.

To use the tool, Matlab 6.1, Simulink 4.1, Real-Time Workshop 4.1are required as well as a host platform C compiler (Microsoft VisualC/C++ or Watcom C/C++), and a cross-compiler for the targetprocessor.

Stateflow Coder 4.1 is also required when generating code forSimulink models containing Stateflow charts.


First Embedded Coder add-on targetsMPC555

The Embedded Target for Motorola MPC555 is an add-on product foruse with the Real-Time Workshop Embedded Coder. It provides acomplete and unified set of tools for developing embeddedapplications for the Motorola MPC555 processor.

This tool will accelerate embedded product development on theMPC555 platform by providing the ability to test, analyse and refineautomatically generated code from The MathWorks Real-Time WorkshopEmbedded Coder directly on the microcontroller.

Prior to Embedded Target for Motorola MPC555, designing with32-bit microcontrollers could be a lengthy process. Engineers couldspend three months or more developing code suitable for use on theMCU The MathWorks says it now takes only minutes to automaticallygenerate the code, download it, and get it running on a third-partyevaluation board.

Embedded Target for MPC555 allows users to perform severaladditional functions that provide all the pieces necessary fordesigners to deploy their code.

These functions include:

Processor-in-the-loop co-simulation, which provides engineers withthe ability to evaluate software running on the processor;

Mid- to late-cycle design, analysis and refinement for productionmicrocontrollers, which allows for the fine-tuning of algorithms andthe ability to make feature enhancements to product designs currentlyin production, enabling users to avoid capital expenditures forgeneric target rapid prototyping tools; and

Application deployment, which provides initialisation and driversoftware for the MPC555 processor, allowing the application to runeither on an evaluation board or on hardware that will be used inproduction.


Published in Embedded Systems (Europe) June 2002

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.