Embedded Systems Design Europe - June/July 2008 - (Page 20) memory as memory pool managers, avoid these problems, but introduce more complexity and possible defects into the system. Given these issues, embedded software developers traditionally frown upon dynamic memory allocation, especially in software for mission-critical systems and avionics. Many embedded software projects forbid the use of dynamic memory allocation entirely. In MATLAB, you don’t need to think about memory allocation. The MATLAB interpreter handles details of array memory and data types, leaving the algorithm developer free to concentrate on the algorithm itself. In fact, typical MATLAB users don’t even worry about array sizes, as MATLAB will automatically resize arrays as required. For this article, however, we’ll identify two types of MATLAB arrays: fixed-size arrays and variable-size arrays. Fixed-size arrays are MATLAB arrays for which the dimensions remain fixed during run time. Variable-size arrays change in size or shape during run time. Some MATLAB examples are shown in Listing 4. Variable-size arrays are an extremely useful feature of MATLAB, and most non-trivial MATLAB programs make use of them; sometimes you simply don’t know how large an array (such as an image or resampled buffer) will be until run time. Although the MATLAB language doesn’t explicitly distinguish between fixedsize arrays and variable-size arrays, you’ll see that this distinction becomes critical when translating to C. EMBEDDED C FOR FIXED-SIZE ARRAYS When translating MATLAB code to C, you must choose how to allocate memory for your data. If the MATLAB code uses a fixed-size array, where the array size doesn’t change during run time, the translation is a simple matter of allocating an equivalent array in C. Because the array size is known at compile time, you can allocate the 20 Listing 4 Fixed- and variable-size arrays in MATLAB. % % F is a fixed-size array F=[1 2; % F is 2x2 0 0]; F(2,:)=[3 4]; % overwrite the second row % % V is a variable-size array V=[1 2]; % V is 1x2 V(2,:)=[3 4]; % append another row to V Listing 5 Look-up table (MATLAB). function y=lut_example(ind) % % map one integer to another % look up table N=1025; LUT=(0:N-1)+N; ind=mod(abs(ind),N); y=LUT(ind+1); Listing 6 Look-up table (C, stack allocation). // // map one integer to another int lut_stack(int ind) { int N=1025; int n; int lut[N]; // stack allocation // // look up table for (n=0;n<N;n++) { lut[n]=n+N; } ind=ind % N; return (lut[ind]); } array statically or on the stack, and there’s no need to resort to dynamic allocation. For example, the MATLAB function in Listing 5 maps one integer to another via a simple look-up table (LUT), which is a vector of fixed size. The equivalent C code, with LUT allocated on the stack, is shown in Listing 6. Similarly, you can allocate LUT in static memory, as shown in Listing 7. A tool we developed for MAT- LAB-to-C translation takes the same approach to fixed-size arrays. When the size of a MATLAB array is known ahead of time, it simply allocates the equivalent array in C. By default, the translation tool uses the size of the array to determine whether to allocate the array on the stack, statically, or dynamically. However, you have complete control over this behavior, and, for example, can direct the translator to avoid all dynamic memory alloca- JUNE – JULY 2008 | embedded systems design europe | www.embedded.com/europe http://www.embedded.com/europe
Table of Contents Feed for the Digital Edition of Embedded Systems Design Europe - June/July 2008 Embedded Systems Design Europe - June 2008 Contents Work in Progress to Define Compact PCI Plus Power.org Demonstrates New Tools Project Supports Multi-core System Programming Altium Links Electronic to Mechanical Design PLDs Look to Cut Power Budget and Costs Project to Provide Coverage Analysis Tool Microsoft Details Windows Embedded Update Cover Feature: Leveraging Virtual Hardware Platforms for Software Allocating Memory in MATLAB-to-C Code MDD & IDEs: Making the Twain Meet in Embedded System Designs Debugging Mixed Signal Designs for Infrequent & Random Events Why Open Source is the Natural Choice for High-security Systems Bringing the Benefits of Low Power CPUs to Modular Design New Products Advertising Contacts Embedded Systems Design Europe - June/July 2008 Embedded Systems Design Europe - June/July 2008 - Embedded Systems Design Europe - June 2008 (Page 1) Embedded Systems Design Europe - June/July 2008 - Embedded Systems Design Europe - June 2008 (Page 2) Embedded Systems Design Europe - June/July 2008 - Contents (Page 3) Embedded Systems Design Europe - June/July 2008 - Contents (Page 4) Embedded Systems Design Europe - June/July 2008 - Contents (Page 5) Embedded Systems Design Europe - June/July 2008 - Project Supports Multi-core System Programming (Page 6) Embedded Systems Design Europe - June/July 2008 - Project Supports Multi-core System Programming (Page 7) Embedded Systems Design Europe - June/July 2008 - Altium Links Electronic to Mechanical Design (Page 8) Embedded Systems Design Europe - June/July 2008 - Altium Links Electronic to Mechanical Design (Page 9) Embedded Systems Design Europe - June/July 2008 - PLDs Look to Cut Power Budget and Costs (Page 10) Embedded Systems Design Europe - June/July 2008 - PLDs Look to Cut Power Budget and Costs (Page 11) Embedded Systems Design Europe - June/July 2008 - Microsoft Details Windows Embedded Update (Page 12) Embedded Systems Design Europe - June/July 2008 - Microsoft Details Windows Embedded Update (Page 13) Embedded Systems Design Europe - June/July 2008 - Cover Feature: Leveraging Virtual Hardware Platforms for Software (Page 14) Embedded Systems Design Europe - June/July 2008 - Cover Feature: Leveraging Virtual Hardware Platforms for Software (Page 15) Embedded Systems Design Europe - June/July 2008 - Cover Feature: Leveraging Virtual Hardware Platforms for Software (Page 16) Embedded Systems Design Europe - June/July 2008 - Cover Feature: Leveraging Virtual Hardware Platforms for Software (Page 17) Embedded Systems Design Europe - June/July 2008 - Allocating Memory in MATLAB-to-C Code (Page 18) Embedded Systems Design Europe - June/July 2008 - Allocating Memory in MATLAB-to-C Code (Page 19) Embedded Systems Design Europe - June/July 2008 - Allocating Memory in MATLAB-to-C Code (Page 20) Embedded Systems Design Europe - June/July 2008 - Allocating Memory in MATLAB-to-C Code (Page 21) Embedded Systems Design Europe - June/July 2008 - MDD & IDEs: Making the Twain Meet in Embedded System Designs (Page 22) Embedded Systems Design Europe - June/July 2008 - MDD & IDEs: Making the Twain Meet in Embedded System Designs (Page 23) Embedded Systems Design Europe - June/July 2008 - MDD & IDEs: Making the Twain Meet in Embedded System Designs (Page 24) Embedded Systems Design Europe - June/July 2008 - MDD & IDEs: Making the Twain Meet in Embedded System Designs (Page 25) Embedded Systems Design Europe - June/July 2008 - MDD & IDEs: Making the Twain Meet in Embedded System Designs (Page 26) Embedded Systems Design Europe - June/July 2008 - Debugging Mixed Signal Designs for Infrequent & Random Events (Page 27) Embedded Systems Design Europe - June/July 2008 - Debugging Mixed Signal Designs for Infrequent & Random Events (Page 28) Embedded Systems Design Europe - June/July 2008 - Debugging Mixed Signal Designs for Infrequent & Random Events (Page 29) Embedded Systems Design Europe - June/July 2008 - Debugging Mixed Signal Designs for Infrequent & Random Events (Page 30) Embedded Systems Design Europe - June/July 2008 - Why Open Source is the Natural Choice for High-security Systems (Page 31) Embedded Systems Design Europe - June/July 2008 - Why Open Source is the Natural Choice for High-security Systems (Page 32) Embedded Systems Design Europe - June/July 2008 - Why Open Source is the Natural Choice for High-security Systems (Page 33) Embedded Systems Design Europe - June/July 2008 - Bringing the Benefits of Low Power CPUs to Modular Design (Page 34) Embedded Systems Design Europe - June/July 2008 - Bringing the Benefits of Low Power CPUs to Modular Design (Page 35) Embedded Systems Design Europe - June/July 2008 - Bringing the Benefits of Low Power CPUs to Modular Design (Page 36) Embedded Systems Design Europe - June/July 2008 - New Products (Page 37) Embedded Systems Design Europe - June/July 2008 - New Products (Page 38) Embedded Systems Design Europe - June/July 2008 - New Products (Page 39) Embedded Systems Design Europe - June/July 2008 - New Products (Page 40) Embedded Systems Design Europe - June/July 2008 - New Products (Page 41) Embedded Systems Design Europe - June/July 2008 - New Products (Page 42) Embedded Systems Design Europe - June/July 2008 - Advertising Contacts (Page 43) Embedded Systems Design Europe - June/July 2008 - Advertising Contacts (Page 44)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.