www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/GenerateCodeUsingEmbeddedCoderExample.m
%% Generate Code Using Embedded Coder(R) % This example shows how to select a target for a Simulink(R) model, % configure options, generate C code for embedded systems, and view % generated files. % % The model represents an 8-bit counter that feeds a triggered subsystem % that is parameterized by constant blocks |INC|, |LIMIT|, and |RESET|. |Input| and % |Output| represent I/O for the model. The |Amplifier| subsystem amplifies the % input signal by gain factor |K|, which updates when signal |equal_to_count| is |true|. % % Copyright 2008-2015 The MathWorks, Inc. %% % *1.* Open the model. model='rtwdemo_rtwecintro'; open_system(model) %% % *2.* Open the *Configuration Parameters* dialog box from the model editor % by clicking *Simulation > Model Configuration Parameters*. % % Alternately, type the following commands at the MATLAB(R) command prompt. cs = getActiveConfigSet(model); openDialog(cs); %% % *3.* Select the *Code Generation* node. % % <<../rtw_codegen_pane_ert.png>> %% % *4.* In the *Target Selection* pane, click *Browse* to select a target. % % You can generate code for a particular target environment or purpose. % Some built-in targeting options are provided using system target files, % which control the code generation process for a target. % % <<../rtw_browse_stf_button_ert.jpg>> % % <<../rtw_target_selection_ert.jpg>> %% % *5.* Select the *Embedded Real-Time (ERT)* target and click *Apply*. % % The ERT target includes a utility to specify and prioritize code % generation settings based on your application objectives. %% % *6.* In the *Code Generation Advisor* pane, click *Set Objectives*. % % You can set and prioritize objectives for the generated code. For % example, while code traceability might be a very important criterion % for your application, you might not want to prioritize it at the cost % of code execution efficiency. % % <<../rtw_check_model_ert_nobuild.png>> %% % *7.* In the *Set Objectives* pane, select *Execution efficiency* and % *Traceability*. Click *OK*. % % You can select and prioritize a combination of objectives before generating % code. % % <<../rtw_objectives_selection_ert.jpg>> %% % *8.* In the model window, press *Ctrl+B* to generate code. %% % *9.* View the code generation report that appears. % % The report includes |rtwdemo_rtwecintro.c|, associated utility and header % files, and traceability and validation reports. % % <<../rtw_report_ert.jpg>> %% % The figure below contains a portion of |rtwdemo_rtwecintro.c| % % <<../ag_rtwdemo_rtwecintro_ertstep.png>> %% % *10.* Close the model. bdclose(model) rtwdemoclean;