Creating Custom_C block
In this segment, we focus on creating a Custom_C block that
calls a C function which returns a Structure. This model demonstrates
how to access the “C structure” defined in a native C program using
the Custom_C block.
The C code for the function
that returns a “C structure” is available in the file “Record.c” under
VS_C_Library/Record directory of VisualSim. The tool does not generate
this file and it should be made available by the Designers who wish to
interface his/her code with VisualSim.
Starting Example
Steps for Creating Record Model
- Open a new VisualSim Block Diagram Editor (BDE) and place the Custom_C block on the canvas. Custom_C is located under Full Library > System_Language > C_and_CPP > Custom_C directory.
- Right click the Custom_C block and select Customize > Configure or press Ctrl+E to configure the block as shown below.
Figure 1. Configuring the Custom_C block
- Right click the Custom_C block and select Configure Arguments and add the arguments as shown below:
Figure 2: C\C++ Arguments Configuration for Record Model
- Click “Commit” to save the settings.
- Now click the button on the GUI menu item Interface > Generate Wrapper for code generation and compilation.
- Now a new folder named “Record” is automatically created under UserNativeC directory.
Successful
compilation of the sources files creates a
Jni<libraryname>I<return argument name>.dll file under
Blocks directory. The file extension “. Dll” indicates that the file is
a dynamic link library (dll).
Note:
Open the “vsout.txt” file under the libraryDirectory to check for
errors caused by an unsuccessful compilation process. These could help in
correcting any mistakes in the interface C code.
- The Blocks directory is provided under VS_C_Library directory to hold “. dll” files, which are in the PATH.
- Now drag and drop
“Text_Display(Non-Buffered)” block from “Results > TextDisplay” to
view the output. Similarly, drag the “Const” input block from Full
Library > Math Operations > Math and Trig.
- Add Untimed Digital Simulator
to the canvas and double click the SDF simulator to change the number of
iterations from 0 to 1. Finally connect the blocks as shown in
the figure below.
Figure 3: Record Model
- To run the Record model, click the run button or Press Ctrl+R. The output for the record model is shown in the following figure.
Figure 4: Result of Record Model