This example shows how to configure a model such that the code generator produces an example main program that you can customize for deployment on bare-board target hardware (does not have an operating system). When you select the model configuration parameter Generate an example main program, the code generator produces the example file ert_main.c
or ert_main.cpp
. This file includes:
main()
function for the generated program
Task scheduling code that determines how and when block computations execute on each time step of the model
Operation of the main
program and the scheduling algorithm depend primarily on:
Whether the model is a single-rate or multirate model
Whether the model solver mode is set to single-tasking or multitasking
For more information, see Deploy Generated Standalone Executable Programs To Target Hardware.
Alternatively, you can configure a model to generate an example main program for deployment on target hardware that is running the VxWorks® operating system or threaded code that runs on your host operating system. The example file ert_main.c
that the code generator produces, shows how to deploy the generated example code.
You can customize a generated main program by using a custom file processing (CFP) template. Consider using a template file to:
Assemble generated code in buffers
Call an API to obtain buffered code into specific sections of generated source and header files
For more information, see File customization template.
Open the example model rtwdemo_examplemain
.
open_system('rtwdemo_examplemain');
1. Open the Embedded Coder app.
2. Select model configuration parameter Generate an example main program. When you select this parameter, you enable parameter Target operating system.
3. Set parameter Target operating system to BareBoardExample
, VxWorksExample
, or NativeThreadsExample
. For more information, see Target operating system.
4. Consider whether you want to specify a custom file processing template. To configure a template, specify the file name and extension for your template TLC file as a string for model configuration parameter File customization template.
Generate and inspect the code.
Augment the generated code with hand code as needed.