How to make block description of a simulink function block displayed above function header?

Hi everyone,
I'm using simulink function block to generate C code. For simulink function block, I add a brief function description to the block as shown below on the left side.
After code generation, the function description is inserted inside the function body.
So, I want to know if there is a way to display this description above the function header instead of inside the function body?
Thanks!

 Accepted Answer

I think I get you point. You can modify the CODE TEMPLATES FILE in Configuration Parameters(Code Generation->Templates-Code templates-Source file template) to do what you want.

5 Comments

Hi Zhichuan,
Thanks for your reply!
I tried to customize the code generation template file by modifying the section Function Banner as shown below.
%%Custom function banner section (optional)
Customize function banners by using the following predefined tokens:
%%%<ModelName>, %<FunctionName>, %<FunctionDescription>, %<Arguments>,
%%%<ReturnType>, %<GeneratedFor>, %<BlockDescription>.
<FunctionBanner style="doxygen_qt">
Function Name : %<FunctionName>
Block Description : %<BlockDescription>
Arguments : %<Arguments>
Return Type of Function : %<ReturnType>
</FunctionBanner>
But the block description is still displayed inside the function body in the generated code:
/*!
* Function Name : test_timestwo
* Block Description :
* Arguments : uint32_T rtu_u)
* Return Type of Function : uint32_T
*/
uint32_T test_timestwo(uint32_T rtu_u)
{
/*
* Block description for '<Root>/timestwo':
* This function multiplies the input with two and then outputs the result as return value.
*
* Input:
* u: uint32
*
* Return:
* y: uint32
*/
return rtu_u << 1;
}
Could you please give me more details about how to solve this problem?
  • Possible reason is that Custom function banner section is valid for generated functions. Thus, you should set the funciton, uint32_T test_timestwo(uint32_T rtu_u)", as an atomic unit and specify the function name as you want.
  • Please attach you model and related files. I need to know more details about your models.
  • The system target file ert.tlc is mostly used in my job. Custom function banner section in ert_code_template.cgt is as following:
%%Custom function banner section (optional)
Customize function banners by using the following predefined tokens:
%%%<ModelName>, %<FunctionName>, %<FunctionDescription>, %<Arguments>,
%%%<ReturnType>, %<GeneratedFor>, %<BlockDescription>.
<FunctionBanner style="classic">
%<FunctionDescription>
%<BlockDescription>
</FunctionBanner>
Generated code is as following:
23 /*
24 * Output and update for atomic system: '<Root>/Subsystem'
25 * Block description for: '<Root>/Subsystem'
26 * Subsystem Description: This is block description
27 */
28 real32_T test_Subsystem(real32_T rtu_aa)
29 {
30 /* Gain: '<S1>/Gain' */
31 return StructPointer->a * rtu_aa;
32 }
Hello Zhichuan,
Thank you very much for the answer!
The simulink model (version: R2018a) and the code generation template file are availible in the attachment. The system target file of the model is ert.tlc, that has never been modified.
Thanks! qxj
Hi, qxj
I've saved your model with previous version in 2017b with the help of others. After running your model in 2017b , I found that the generated code is different from yours in 2018a, which makes me confused.
1 /*
2 * File: test_2017b_timestwo.c
3 *
4 * Code generated for Simulink model 'test_2017b'.
5 *
6 * Model version : 1.23
7 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017
8 * C/C++ source code generated on : Fri Oct 26 08:51:02 2018
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: Intel->x86-64 (Windows64)
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 *
15 *
16 * TLC version : 8.13 (Jul 25 2017)
17 */
18
19 #include "test_2017b_timestwo.h"
20
21 /* Include model header file for global data */
22 #include "test_2017b.h"
23 #include "test_2017b_private.h"
24
25 /*!
26 * Function Name : test_2017b_timestwo
27 * Block Description : Block description for: '<Root>/timestwo'
28 * This function multiplies the input with two and then outputs the result as return value.
29 *
30 * Input:
31 * u: uint32
32 *
33 * Return:
34 * y: uint32
35 * Arguments : uint32_T rtu_u
36 * Return Type of Function : uint32_T
37 */
38 uint32_T test_2017b_timestwo(uint32_T rtu_u)
39 {
40 return rtu_u << 1;
41 }
42
43 /*
44 * File trailer for generated code.
45 *
46 * [EOF]
47 */
48
Hi Zhichuan,
after code generation by using MATLAB R2017b, I also got the same result as you.
So, I have to draw a conclusion, that this problem is a side effect due to MATLAB version.
If you have any idea in the future, please tell me how to solve it. Thanks for your help again!
qxj

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!