Timed Interface Model -Create a simple Counter

Parent Previous Next

VisualSim                                                                                                                              


Timed Interface Model - Creating a simple Counter


What is Timed Interface?

We differentiate the working of the SystemC interface as two main cases:

  1. Blocking (Sync to Delta Cycles)
  2. Non-blocking (Sync to Events)

Blocking mode is that the VisualSim waits for a delta cycle response from SystemC code to proceed with an output in VisualSim.

In Non-blocking, VisualSim does not wait for a response from SystemC, or an asynchronous call from either an input from VisualSim, or an output from SystemC.  This mode is no longer supported.

Hence we call the blocking and non-blocking as sync to delta cycles and sync to events.

The blocking mode is represented by the presence of SC_Sim block, which has the Parameter to specify the time limit between each delta cycle.

In the case of blocking mode, both simulators are synchronized to allow them to exchange data during the synchronization points, there by making them synchronous to the clock time.

To understand the Timed Interface in more detail, let us construct a simple Counter model using the SC_Cosim block as shown in Figure 8 and is located under “demo/Interfaces/SystemC/Counter” directory of the VisualSim Install.

The model consists of a single SC_Cosim block, which exports the SystemC Counter SC_MODULE. The file path for the SystemC code namely ‘Counter.h’ is specified in the SC_File_Path parameter of the block.

Right click on the Counter block and select the ‘Open Block’ menu item to view the SystemC code for the Counter SC_MODULE. The SystemC code for the Counter SC_MODULE is located under “demo/Interfaces/SystemC/Counter” directory of the VisualSim install.

In the blocking mode of operation, both the VisualSim (VS) and SystemC (SC) simulators are allowed to exchange data only during the synchronization points there by making them synchronous with the clock time. In the case where one of the simulators could have the data ready to be exchanged before the other simulator reaches the synchronization point is halted until the delta cycle response from the other simulator their by making them to synchronous to delta cycles.

The code for the Counter SC_MODULE is as shown in the following figure:

 

Counter Open Block

Figure 1. Counter.h

The SystemC Counter SC_MODULE consists of a SC_THREAD namely do_Counter() which increments a variable of type ‘int’ starting from 1. The number of cycles that the do_Counter SC_THREAD executes is based on two more variables namely ‘deltaTime’ that denotes the Stop_Time of both the simulators and then the ‘delta_cycle_time’ that denotes the time resolution or delta-cycle time in which the model should run. For example, the ‘deltaTime’ and ‘delta_cycle_time’ can be 10 and 1 respectively to generate numbers from 1 to 10. In this model, the time base is ‘SC_NS’ making delta-cycles synchronous to nanosecond of time.

The SystemC SC_THREAD do_Counter consists of simple while loop that decrements the ‘deltaTime’ or the stop time of the simulators by the ‘delta_cycle_time’ for every cycle until the ‘deltaTime’ equals the ‘start_time’, which denotes the start time of both the simulators.

The code also has ‘wait (delta_cycle_time, SC_NS)’ which makes the do_Counter SC_THREAD to wait for the time equals to the 'delta_cycle_time’ in every cycle to make them run for more than delta-cycle during the simulation rather than to exit in a single delta-cycle.

In this model, the SC simulator is assumed to complete one delta-cycle when it resumes after the ‘wait’ statement in the SC_THREAD do_Counter for each cycle.

The VS simulator waits for this delta-cycle response from SC simulator to proceed with an output in VisualSim that is placed in the queue by the SystemC code. Setting the flag ‘SCEventComplete’ indicates the completion of each delta-cycle by the SC simulator.

Similarly, the SC simulator will wait for this delta-cycle response from VS simulator to proceed with an input from the VisualSim that is placed in the queue for the SystemC code to fetch. The VS simulator marks its completion of the delta-cycle by setting the flag ‘VSEventComplete’.

Configuring the Counter SC_Cosim block

This section explains as to how to configure the SC_Cosim to export your SystemC code in VisualSim. The SC_Cosim block is located in the Script_Language_Interface > SystemC. The block can be placed on the canvas in the same way as any other Java blocks. Once the SC_Cosim has been placed on the canvas, the block needs to be configured.

Right click on the SC_Cosim block and choose Customize > Configure to configure the block parameters as shown in the figure:

Configuring the SC_Cosim (Counter) block

Figure 2. Configuring the SC_Cosim “Counter” block

Configure the ports of the “Counter” SC_Cosim block

The Counter SC_MODULE consists of one input port and one output port of type “int” (refer the “demo/Interfaces/SystemC/Counter/Counter.h under the VisualSim install). Hence it is appropriate to create the same here.

Configuring the ports of the SC_Cosim ‘Counter’ block

Figure 3. Configuring the ports of the SC_Cosim ‘Counter’ block

The Table 1 & Table 2 shows the SystemC types and their equivalent Remote Types in VisualSim.

Export SystemC Code

We recommend to complete the settings for the C compiler (Only for the first time) before this section in order to obtain the full functionality of the SystemC blockset.

Creating an executable

After the parameters and the ports of the “Counter” SC_Cosim Block are configured, it is ready to export the SystemC code to VisualSim and compile them. Click the GNU menu Interface > Generate Wrapper (Figure 8) to export SystemC code into VisualSim.

Configuring the Executable Model

Once the SystemC code is exported into VisualSim, it is ready to simulate them to get the results.

Our example design consists of a single Counter SC_Module that generates numbers.

Now right click on the Transaction_Source block and select Customize > Configure to configure the block parameters as shown in the following figure:

 

Configuring the (Transaction_Source) block

Figure 4. Configuring the ‘Transaction_Source’ block

The parameter “Mean_Time” is set to ‘1.0E-9’ to generate traffic for every 1 nanosecond of time and then the parameter “Time_Distribution” is set to ‘Fixed (Mean)’.

Now right click the Statement_Select block and select Customize > Configure menu item to configure the block parameters as shown in the following figure:

 

Configuring the ‘Statement_Select’ block

Figure 5. Configuring the Statement_Select block

Now the parameter “Select_Field_Description” is set to ‘ID’ to extract the ‘ID’ Field of the incoming datastructure, which is of type ‘int’.

Now right click on the “SC_Sim” block and choose Customize > Configure item to configure the block parameters as shown in the following figure:

 

Configuring the (SC_Sim) block

Figure 6. Configuring the ‘SC_Sim’ block

Running the Executable Model

Connect all the blocks as shown in Figure 8 and then add a Digital simulator (located under ModelSetup).

Right click on the “Digital” block and choose Customize > Configure menu item to configure the block parameters as shown in the following figure.

 

Configuring the ‘DE Simulator’ block

Figure 7. Configuring the ‘DE Simulator’ block

The parameter stopTime of the ‘SC_Sim’ and the ‘Digital Simulator’ should be the same. But in the case of the “SC_Sim” block, the ‘Stop_Time’ parameter of the block is converted from a double value to the required unit based on the ‘Time_Base’.

 

Counter??Timed Interface model

Figure 8. Counter Timed Interface model

Click the “Run” in the IDE or press Ctrl+R to execute the model.