The article demonstrates how modeling design patterns can be used to generate efficient C code
|8 Oct 2009||Linda Webb||
A key step in Model-Based Design is the generation of C code and deployment of an algorithm onto a target processor in the production environment. There are many different ways to implement the same algorithm in a Simulink® model; the quality of the generated C code will depend on
Using a do-while loop as an example, this article focuses on optimizing the algorithm at stage A. We demonstrate how modeling design patterns can be used to generate efficient C code. You can further optimize your algorithms when compiling C source code into object code by using Target Function Libraries. For details, see the paper “Generating Target-Optimized Code Using Target Function Libraries.
A modeling design pattern is much like a software design pattern used in object-oriented literature. It is a template containing modeling elements that can be reused in commonly recurring design problems. Figure 2 shows an example of a modeling design pattern for do-while logic implemented in Stateflow®. This pattern can be used to generate the common do-while loop construct in the C code.
By Bill Chou, The MathWorks
This article was published in MATLAB Digest, September 2009