| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop Embedded Coder |
| Contents | Index |
| Learn more about Real-Time Workshop Embedded Coder |
| On this page… |
|---|
Example Settings and Resulting Generated Files provides example settings for one data object of a model. Eight examples are listed so that you can see the generated files that result from a wide variety of settings. Four examples from this table are discussed below in more detail. These discussions provide adequate information for understanding the effects of any settings you might choose. For illustration purposes, the four examples assume that we are dealing with an overall system that controls engine idle speed.
The next figure shows that the software component of this example system consists of two modules, IAC (Idle Air Control), and IO (Input-Output).

The code in the IO module controls the system's IO hardware. Code is generated only for the IAC module. (Some other means produced the code for the IO module, such as hand-coding.) So the code in IO is external to MPF, and can illustrate legacy code. To simplify matters, the IO code contains one source file, called IO.c, and one header file, called IO.h.
The IAC module consists of two Stateflow charts, spd_filt and iac_ctrl. The spd_filt chart has two signals (meas_spd) and filt_spd), and one parameter (a). The iac_ctrl chart also has two signals (filt_spd and iac_cmd) and a parameter (ref_spd). (The parameters are not visible in the top-level charts.) One file for each chart is generated. This example system allows us to illustrate referencing from file to file within the MPF module, and model to external module. It also illustrates the case where there is no such referencing.

Proceed to the discussion of the desired example settings:
These settings and the generated files that result are shown as Example Settings 1 in Example Settings and Resulting Generated Files. As you can see from the table, this example illustrates the case in which only one .c source file (for each chart) is generated.
So, for the IAC model, select the following settings. Accept the Data defined in source file in the Data definition field and the Data declared in source file in the Data declaration field on the Data Placement pane of the Configuration Parameters dialog box. Accept the default Not specified selection in the Module naming field. Accept the default blank settings for the Owner, Definition file and Header file fields on the Model Explorer. For Memory section, accept Default. Now the Read-Write priority is in effect. Generate code. The next figure shows the results in terms of definition and declaration statements.

The code generator generated a spd_filt.c for the spd_filt chart and iac_ctrl.c for the iac_ctrl chart. As you can see, MPF placed all definitions of data objects for the spd_filt chart in spd_filt.c. It placed all definitions of data objects for the iac_ctrl chart in iac_ctrl.c.
However, notice real_T filt_spd. This data object is defined in spd_filt.c and declared in iac_ctrl.c. That is, since the Read-Write priority is in effect, filt_spd is defined in the file that first writes to its address. And, it is declared in the file that reads (uses) it. Further, real_T meas_spd is defined in both spd_filt.c and the external IO.c. And, real_T iac_cmd is defined in both iac_ctrl.c and IO.c.
See tables Effects of Ownership Settings and Example Settings and Resulting Generated Files. In the Read-Write Example, there are several instances where the same data object is defined in more than one .c source file, and there is no declaration (extern) statement. This would result in compiler errors during link time. But in this example, we configure MPF Ownership rules so that adequate linking can take place. Notice the Example Settings 2 row in Example Settings and Resulting Generated Files. Except for the ownership settings, assume these are the settings you made for the model in the IAC module. Since this example has no Definition file or Header file specified, now Ownership takes priority. (If there were a Definition file or Header file specified, MPF would ignore the ownership settings.)
On the Data Placement pane of the Configuration Parameters dialog box, select User specified in the Module naming field, and specify IAC in the Module name field (case sensitive). Open the Model Explorer (by issuing the MATLAB command daexplr) and, for all data objects except meas_spd and iac_cmd, type IAC in the Owner field (case sensitive). Then, only for the meas_spd and iac_cmd data objects, type IO as their Owner (case sensitive). Generate code.
The results are shown in the next figure. Notice the extern real_T meas_spd statement in spd_filt.c, and extern real_T iac_cmd in iac_ctrl.c. MPF placed these declaration statements in the correct files where these data objects are used. This allows the generated source files (spd_filt.c and iac_ctrl.c) to be compiled and linked with IO.c without errors.

These settings and the generated files that result are shown as Example Settings 3 in Example Settings and Resulting Generated Files. Since this example has no Definition file specified, it allows us to describe the effects of the Header file setting. (If there were a Definition file, MPF would ignore the Header file setting.) The focus of this example is to show how the Header file settings result in the linking of the two chart source files to the external IO files, shown in the next figure. (Also, ownership settings will be used to link the two chart files with each other.)
As you can see in the figure, the meas_spd and iac_cmd identifiers are defined in IO.c and declared in IO.h. Both of these identifiers are external to the generated .c files. You open the Model Explorer and select both the meas_spd and iac_cmd data objects. For each of these data objects, in the Header file field, specify IO.h, since this is where these two objects are declared. This setting ensures that the spd_filt.c source file will compile and link with the external IO.c file without errors.
Now we configure the ownership settings. In the Model Explorer, select the filt_spd data object and set its Owner field to IAC. Then, on the Data Placement pane of the Configuration Parameters dialog box, select User specified in the Module naming field, and specify IAC in the Module Name field. This ensures that the spd_filt source file will link to the iac_ctrl source file. Generate code. See the figure below.

Since you specified the IO.h filename for the Header file field for the meas_spd and iac_ctrl objects, the code generator assumed correctly that their declarations are in IO.h. So the code generator placed #include IO.h in each source file: spd_filt.c and iac_ctrl.c. So these two files will link with the external IO files. Also, due to the ownership settings that were specified, the code generator places the real_T filt_spd = 0.0; definition in spd_filt.c and declares the filt_spd identifier in iac_ctrl.c with extern real_T iac_cmd;. Consequently, the two source files will link together.
These settings and the generated files that result are shown as Example Settings 4 in Example Settings and Resulting Generated Files. Notice that a definition filename is specified. The settings in the table only apply to the data object called a. You have decided that you do not want this object defined in spd_filt.c, the generated source file for the spd_filt chart. (There are many possible organizational reasons one might want an object declared in another file. It is not important for this example to specify the reason.)
For this example, assume the settings for all data objects are the same as those indicated in Header File Example, except for the data object a. The description below identifies only the differences that result from this.
Open the Model Explorer, and select data object a. In the Definition file field you specify any desired filename. Choose filter_constants.c. Generate code. The results are shown in the next figure.

The code generator generates the same files as in the Header File Example, and adds a new file, filter_constants.c. Data object a now is defined in filter_constants.c, rather than in the source file spd_filt.c, as it is in the example. This data object is declared with an extern statement in global.h
![]() | Data Placement Rules | Data Placement Rules and Effects | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |