quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif VPI Interface File

Shown for VCS. Let me know if you want for modelsim or NcSim.

   

space.gif


  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include "vpi_user.h"
  4 
  5 #include "counter_tb_ports.h"
  6 #include "counter_tb_exports.h"
  7 
  8 //Definitions to hols the data to be passed from calltf rtn
  9 typedef struct tagCounter32 {
 10   vpiHandle  clk;
 11   vpiHandle  d_out;
 12 
 13   vpiHandle  rst;
 14 } inst_rec;
 15 
 16 // CallBack Proto 
 17 int sc_counter_calltf(char *user_data);
 18 int sc_counter_interface(p_cb_data cb_data);
 19 
 20 int sc_counter_calltf(char *user_data) {
 21   vpiHandle  inst_h, arg_iter;
 22   s_vpi_value  value_s;
 23   s_vpi_time  time_s;
 24   s_cb_data  cb_data_s;
 25   inst_rec  *ip;
 26 
 27   ip = (inst_rec *)malloc(sizeof(inst_rec));
 28   
 29   // Get Arguments to System Task 
 30   inst_h = vpi_handle(vpiSysTfCall, 0);
 31   arg_iter = vpi_iterate(vpiArgument, inst_h);
 32 
 33   ip->clk     = vpi_scan(arg_iter);  // 1nd argument 
 34   ip->d_out   = vpi_scan(arg_iter);  // 2st argument 
 35   ip->rst     = vpi_scan(arg_iter);  // 3st argument 
 36   
 37   vpi_free_object(arg_iter);
 38   
 39   // Set-Up Value Change callback option 
 40   cb_data_s.user_data = (char *)ip;
 41   cb_data_s.reason    = cbValueChange;
 42   cb_data_s.cb_rtn    = sc_counter_interface;
 43   cb_data_s.time      = &time_s;
 44   cb_data_s.value     = &value_s;
 45 
 46   time_s.type         = vpiSuppressTime;
 47   value_s.format      = vpiIntVal;
 48 
 49   cb_data_s.obj  = ip->clk;
 50   vpi_register_cb(&cb_data_s);
 51 
 52   cb_data_s.obj  = ip->d_out;
 53   vpi_register_cb(&cb_data_s);
 54   
 55   init_sc();  // Initialize SystemC Model
 56 
 57   return(0);
 58 }
 59 
 60 //Value change simulation callback routine
 61 int sc_counter_interface(p_cb_data cb_data)
 62 {
 63   inst_rec  *ip;
 64   s_vpi_value  value_s;
 65   
 66   static unsigned long SimNow = 0;
 67 
 68   // IO ports systemC testbench
 69   static INVECTOR   invector;
 70   static OUTVECTOR  outvector;
 71   
 72   ip = (inst_rec *)cb_data->user_data;
 73   
 74   // Read current value from Verilog 
 75   value_s.format = vpiIntVal;
 76 
 77   vpi_get_value(ip->clk, &value_s);
 78   invector.clk = value_s.value.integer;
 79 
 80   vpi_get_value(ip->d_out, &value_s);
 81   invector.d_out = value_s.value.integer;
 82 
 83   exec_sc(&invector, &outvector, (tf_gettime()-SimNow));
 84   SimNow = tf_gettime();
 85 
 86   value_s.value.integer = outvector.rst;
 87   vpi_put_value(ip->rst, &value_s, 0, vpiNoDelay);
 88 
 89   if (outvector.done) {
 90     tf_dofinish();
 91   }
 92   return(0);
 93 }
You could download file counter_vpi.c here
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif VPI Compile Commands
   

space.gif

 # Point to you systemC Install Dir
 SYSTEMC_HOME = /appl/systemc
 INC_OPT      = -I. -I$(VCS_HOME)/include \
 	       -I$(SYSTEMC_HOME)/include
 COMP_OPT     = -c 
 LIB_OPT      = $(SYSTEMC_HOME)/lib-linux/libsystemc.a
 CPP_FILE     = counter.cpp counter_tb.cpp 
 VPI_C_FILE   = counter_vpi.c
 V_FILE       = counter.v
 
 VPI_O_FILE   = counter.o counter_vpi.o counter_tb.o
 VCS_OPT      = -CFLAGS -lstdc++ $(LIB_OPT)
 
 vpi:c cpp
 	vcs +vpi -P counter_vpi.tab $(VPI_O_FILE) counter.v $(VCS_OPT) -R
 
 cpp : $(CPP_FILE)
 	gcc $(INC_OPT) $(COMP_OPT) $(CPP_FILE)
 
 c : $(VPI_C_FILE)
 	gcc $(INC_OPT) $(COMP_OPT) $(VPI_C_FILE)
 
 clean:
 	rm -rf *.o simv csrc simv.daidir vcs.key *.vpd *.vcd 
   

space.gif

  ../images/main/bullet_star_pink.gif VPI Simulation Output
   

space.gif


  1 @0 s Started SystemC Schedular
  2 @0 s Asserting Reset 
  3 @2 nsCounter Monitor : tb 0 dut 0
  4 @4 nsCounter Monitor : tb 0 dut 0
  5 @6 nsCounter Monitor : tb 0 dut 0
  6 @8 nsCounter Monitor : tb 0 dut 0
  7 @10 nsCounter Monitor : tb 0 dut 0
  8 @12 nsCounter Monitor : tb 0 dut 0
  9 @14 nsCounter Monitor : tb 0 dut 0
 10 @16 nsCounter Monitor : tb 0 dut 0
 11 @18 nsCounter Monitor : tb 0 dut 0
 12 @20 ns De-asserting Reset 
 13 @20 nsCounter Monitor : tb 0 dut 0
 14 @22 nsCounter Monitor : tb 1 dut 1
 15 @24 nsCounter Monitor : tb 2 dut 2
 16 @26 nsCounter Monitor : tb 3 dut 3
 17 @28 nsCounter Monitor : tb 4 dut 4
 18 @30 nsCounter Monitor : tb 5 dut 5
 19 @32 nsCounter Monitor : tb 6 dut 6
 20 @34 nsCounter Monitor : tb 7 dut 7
 21 @36 nsCounter Monitor : tb 8 dut 8
 22 @38 nsCounter Monitor : tb 9 dut 9
 23 @40 nsCounter Monitor : tb 10 dut 10
 24 @42 nsCounter Monitor : tb 11 dut 11
 25 @44 nsCounter Monitor : tb 12 dut 12
 26 @46 nsCounter Monitor : tb 13 dut 13
 27 @48 nsCounter Monitor : tb 14 dut 14
 28 @50 nsCounter Monitor : tb 15 dut 15
 29 @52 nsCounter Monitor : tb 16 dut 16
 30 @54 nsCounter Monitor : tb 17 dut 17
 31 @56 nsCounter Monitor : tb 18 dut 18
 32 @58 nsCounter Monitor : tb 19 dut 19
 33 =======================================
 34  SIMULATION PASSED
 35 =======================================
 36 @60 nsCounter Monitor : tb 20 dut 20
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com