Link Generated Code to Requirements
Link generated code to model element requirements. Using configuration parameters, you can specify whether to include requirement descriptions as comments in the generated code.
Open Model
Open the model CodeRequirementsLinks
. The model contains Simulink® and Stateflow® elements with associated requirements.
model='CodeRequirementsLinks';
open_system(model);
View Requirements
You can view requirements linked to the model by using the Requirements Editor. In the Simulink Editor, open the Requirements Manager app. On the Requirements tab, click Requirements Editor. You can view requirements specific to model objects by using the object context menu. Right-click an element and select Requirements > Open Outgoing Links dialog. To view the requirements, use these commands:
1. To view the requirements for the DiscretePulseGenerator
block, right-click the DiscretePulseGenerator
block and select Requirements > Open Outgoing Links dialog to open Outgoing Links Editor. Using Outgoing Links Editor, you can create, edit, and delete requirements traceability links.
clockblock='CodeRequirementsLinks/clock'; clockblockh=get_param(clockblock,'handle'); rmi('edit',clockblockh);
2. To view the requirements, open the Signal Editor block by double-clicking it.
sigeblock='CodeRequirementsLinks/Signal Editor';
open_system(sigeblock)
3. To view the requirements for the Stateflow® state, open the Outgoing Links Editor.
state=find(sfroot,'-isa','Stateflow.State','-and','Tag','req_state'); rmi('edit',state.id);
4. To view the requirements for the Stateflow transition, open the Outgoing Links Editor.
trans=find(sfroot,'-isa','Stateflow.Transition','-and','Tag','req_trans'); rmi('edit',trans.id);
5. To view the requirements for the Stateflow function, open the Outgoing Links Editor.
func=find(sfroot,'-isa','Stateflow.Function','-and','Tag','req_function'); rmi('edit',func.id);
Close the open windows.
close_system(sigeblock);
Set Configuration Parameters
Open the Configuration Parameters dialog box Code Generation > Comments pane. View the configuration parameter settings.
model = bdroot; configSet = getActiveConfigSet(model); openDialog(configSet);
Generate Code
Generate code for the model.
slbuild('CodeRequirementsLinks')
### Starting build procedure for: CodeRequirementsLinks ### Successful completion of build procedure for: CodeRequirementsLinks Build Summary Top model targets: Model Build Reason Status Build Duration ======================================================================================================================== CodeRequirementsLinks Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 28.196s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 31.445s
In the generated code, view the comments containing the requirements. To view all the requirements, click the hyperlinked requirement comment.
coder.example.extractLines('CodeRequirementsLinks_ert_rtw/CodeRequirementsLinks.c',... '/* Function for Chart:','return result;',1,0);
/* Function for Chart: '<Root>/rebound_elimination' */ static real_T rebound_fcn(real_T prev_in, real_T prev_out, real_T curr_in) { real_T result; /* Graphical Function 'rebound_fcn': '<S2>:2': * 1. Result Computation */ /* Transition: '<S2>:4' */ if (prev_in == curr_in) { /* Transition: '<S2>:5' */ result = curr_in; } else { /* Transition: '<S2>:6' */ /* Transition: '<S2>:7' */ result = prev_out; }
Related Topics
- View and Link Requirements in Simulink (Requirements Toolbox)