Global Sources
EE Times-India
Stay in touch with EE Times India
 
EE Times-India > Embedded
 
 
Embedded  

How to generate C code automatically

Posted: 13 Sep 2011     Print Version  Bookmark and Share

Keywords:C code  C++  MATLAB 

The foundation of any design workflow is idea exploration. This process aids in the creation of compelling products with unique value propositions that separate them from competition. For engineers, exploration of design ideas takes the form of prototyping and testing algorithm variations to evaluate their behavioural and functional effect on the final product design. Such evaluation narrows the set of algorithm alternatives and helps identify the one that eventually make its way into the design of the entire system.

The speed with which an engineer can design and assess algorithm variations is critical to efficient optimisation of the design. Some engineers use the high level interpreted language of MATLAB to express their ideas during design exploration as it allows focus on algorithm behaviour instead of low-level programming details.

As product development evolves from algorithm exploration to system design, integration, and implementation on hardware, the design specifications are typically translated by hand into a language such as C or C++. The C programming language has broad popularity and is widely accepted as the language of choice for many development phases including system design, application software development, and embedded software implementation.

Why translate to C/C++?
Often engineers translate MATLAB algorithms to C/C++ code to create stand-alone software prototypes, integrate MATLAB algorithms with other software written in C/C++, or deliver specifications to embedded software engineers for implementation. Generating C automatically (and nearly instantaneously) from MATLAB speeds design exploration and product development iterations.

Why is manual conversion troublesome?
The pitfalls of manual translation stem from differences in the programming paradigms of MATLAB and C. MATLAB has a succinct syntax and native data types for the vector and matrix processing operations used in embedded signal processing and control algorithms. The equivalent C code requires multiple loops to process individual data samples, resulting in many lines of C code for a single line of MATLAB code. Equally important, the polymorphic and dynamically typed behaviour that makes MATLAB flexible and easy to use is not readily accessible in the more statically typed C language without detailed programming. These differences make manual translation a time-consuming and complex process.

Manual translation also results in multiple copies of the same algorithm written in different languages. The engineer must verify that these copies remain equivalent throughout multiple design iterations. The cost of verifying and updating revisions to accommodate requirement changes quickly becomes prohibitive, often resulting in errors and a design that diverges from the original specification.

Advantages
Automating translation of MATLAB code to C code overcomes most, if not all, of the problems associated with manual translation. Automatic MATLAB-to-C code generation offers the following advantages:
 • Design engineers spend more time innovating and tuning high-level algorithms in MATLAB rather than writing and debugging low-level C code
 • The equivalence of MATLAB algorithms and generated C code is easily maintained during design iterations
 • C code is produced much faster and is free of the errors that are frequently introduced by hand coding

The automatic translation workflow from MATLAB allows engineers to maintain "one truth"—and elaborate it directly within MATLAB to incorporate implementation details such as specifying data types and sizes of input and output variables. Design iterations become easier because engineers continue to use the interactive debugging and visualisation capabilities in MATLAB throughout the process. The significant cost of producing and verifying hand-written C code can be eliminated for common design workflow uses such as prototyping algorithms as stand-alone executables, integrating algorithms as reusable libraries, and accelerating parts of the algorithm's execution in MATLAB.

Three-step workflow
Translating MATLAB code to C code (automatically or by hand) involves making decisions on multiple implementation details in the algorithm such as data type management, fixed-point math support, and static/dynamic memory allocation. Choices made by engineers when working with these details help satisfy various implementation requirements and enable the engineers to manage trade-offs between reducing memory footprint and improving processor utilisation or performance.

1 • 2 • 3 Next Page Last Page



Comment on "How to generate C code automatically"
Comments:  
*  You can enter [0] more charecters.
*Verify code:
 
 
Webinars

Seminars

Visit Asia Webinars to learn about the latest in technology and get practical design tips.

 

Go to top             Connect on Facebook      Follow us on Twitter      Follow us on Orkut

 
Back to Top