Creating Custom Cblock

Parent Previous Next

VisualSim                                                                                                                               

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
  1. 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.
  2. Right click the Custom_C block and select Customize > Configure or press Ctrl+E to configure the block as shown below.

 

Configuring??the Custom_C block

Figure 1. Configuring the Custom_C block

  1. Right click the Custom_C block and select Configure Arguments and add the arguments as shown below:

C or C++ Arguments Configuration for Record Model

Figure 2: C\C++ Arguments Configuration for Record Model

  1. Click “Commit” to save the settings.
  2. Now click the button on the GUI menu item Interface > Generate Wrapper for code generation and compilation.
  3. 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.

  1. The Blocks directory is provided under VS_C_Library directory to hold “. dll” files, which are in the PATH.
  2. 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.
  3. 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.

 

Record Model

Figure 3: Record Model

  1. 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.

Result of Record??Model

Figure 4: Result of Record Model