Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

Model Function Prototypes Example

The following procedure demonstrates how to use the Configure Model Functions button on the Interface pane of the Configuration Parameters dialog box to control the model function prototypes that the Real-Time Workshop Embedded Coder software generates for your Simulink model.

  1. Open a MATLAB session and launch the rtwdemo_counter demo model.

  2. In the rtwdemo_counter Model Editor, double-click the Generate Code Using Real-Time Workshop Embedded Coder (double-click) button to generate code for an ERT-based version of rtwdemo_counter. The code generation report for rtwdemo_counter appears.

  3. In the code generation report, click the link for rtwdemo_counter.c.

  4. In the rtwdemo_counter.c code display, locate and examine the generated code for the rtwdemo_counter_step and the rtwdemo_counter_initialize functions:

    /* Model step function */
    void rtwdemo_counter_step(void)
    {
     ...
    }
    /* Model initialize function */
    void rtwdemo_counter_initialize(void)
    {
     ...
    }

    You can close the report window after you have examined the generated code. Optionally, you can save rtwdemo_counter.c and any other generated files of interest to a different location for later comparison.

  5. From the rtwdemo_counter model, open the Configuration Parameters dialog box.

  6. Navigate to the Real-Time Workshop > Interface pane and click the Configure Model Functions button. The Model Interface dialog box appears.

  7. In the initial (Default model initialize and step funtions) view of the Model Interface dialog box, click the Validate button to validate and preview the default function prototype for the rtwdemo_counter_step function. The function prototype arguments under Step function preview should correspond to the default prototype in step 4.

  8. In the Model Interface dialog box, set Function specification field to Model specific C prototypes. Making this selection switches the dialog box from the Default model initialize and step functions view to the Model specific C prototypes view.

  9. In the Model specific C prototypes view, click the Get Default Configuration button to activate the Configure model initialize and step functions subpane.

  10. In the Configure model initialize and step functions subpane, change Initialize function name to rtwdemo_counter_cust_init.

  11. In the Configure model initialize and step functions subpane, in the row for the Input argument, change the value of Category from Value to Pointer and change the value of Qualifier from none to const *. The preview reflects your changes.

  12. Click the Validate button to validate the modified function prototype. The Validation subpane displays a message that the validation succeeded.

  13. Click OK to exit the Model Interface dialog box.

  14. Generate code for the model. When the build completes, the code generation report for rtwdemo_counter appears.

  15. In the code generation report, click the link for rtwdemo_counter.c.

  16. Locate and examine the generated code for the rtwdemo_counter_custom and rtwdemo_counter_cust_init functions:

    /* Customized model step function */
    void rtwdemo_counter_custom(const int32_T *arg_Input, int32_T *arg_Output)
    {
     ...
    }
     /* Model initialize function */
    void rtwdemo_counter_cust_init(void)
    {
     ...
    }
  17. Verify that the generated code is consistent with the function prototype modifications that you specified in the Model Interface dialog box.

  


Related Products & Applications

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