Generate Code with Annotations or Comments
You can use the HDL Coder™ software to add text annotations to generated code in the form of model annotations, text comments, or requirements comments.
When you enter text directly on the block diagram as Simulink® annotations, HDL Coder renders the text from these Simulink annotations as plain text comments in generated code. The comments are generated at the same level in the model hierarchy as the subsystem that contains the annotations.
See Annotate Models for more information about annotations.
When you provide a description for the signals in your Simulink model, the generated HDL code displays these descriptions as comments above the signal declaration statements. To specify a description for the signal, right-click the signal and select Properties to open the Signal Properties dialog box. Then, select the Documentation tab, and in the Description section, enter a description for the signal. For the signal description, use ASCII characters. Non-ASCII characters in the generated code may potentially interfere with downstream synthesis and lint tools. In some cases, due to optimizations that act on the signals, the generated code may not translate all signal descriptions to HDL comments or may create replicas of HDL comments for certain signal descriptions.
If enter text comments in your model by using a DocBlock block and entering text comments, HDL Coder renders the text from the DocBlock block in the generated code as plain text comments. The comments are generated at the same level in the model hierarchy as the subsystem that contains the DocBlock block.
Set the Document type parameter of the DocBlock to
Text. HDL Coder does not support the
For more information about the DocBlock block, see DocBlock.
Requirement Comments and Hyperlinks
By using the Requirements Toolbox™, you can assign requirements to blocks and generate them as comments in the generated code. For example:
Open the model
hdlcoder_simple_up_counterusing this command:
Create a new requirement set named
Delay_requirements.slreqxby using the Requirements Editor (Requirements Toolbox) with these details:
Custom ID: 1
Summary: Requirement 1
Description: Sample text 1
Similarly, create another requirement with these details:
Custom ID: 2
Summary: Requirement 2
Description: Sample text 2
For more information, see Author Requirements in MATLAB or Simulink (Requirements Toolbox).
Right-click the Delay block named
Delay. From the context menu, select Requirements > Open Outgoing Links dialog.
Link the requirements for block. Click the New button. Enter details about the requirement by using the Description, Document type, Document, and Location (Type/Identifier) properties.
Click Apply and OK.
To include requirements as hyperlinked comments in the generated code, in the Configuration Parameters dialog box, select these model configuration parameters:
Generate traceability report
Include requirements in block comments
Alternatively, if you generate code from the command line, set the
The generated code shows the requirements as comments for the Delay block in the
hdlcoder_simple_up_countermodel. The comments include links to the requirements associated with the block and in the original model.
-- <S1>/Delay -- Block requirements for <S1>/Delay -- 1. Requirements 1 -- 2. Requirements 2 Delay_process : PROCESS (clk, reset) BEGIN IF reset = '1' THEN Delay_out1 <= to_unsigned(16#00#, 8); ELSIF clk'EVENT AND clk = '1' THEN IF enb = '1' THEN Delay_out1 <= Switch1_out1; END IF; END IF; END PROCESS Delay_process;