#include #include #include "vpi_user.h" #include "counter_tb_ports.h" #include "counter_tb_exports.h" //Definitions to hols the data to be passed from calltf rtn typedef struct tagCounter32 { vpiHandle clk; vpiHandle d_out; vpiHandle rst; } inst_rec; // CallBack Proto int sc_counter_calltf(char *user_data); int sc_counter_interface(p_cb_data cb_data); int sc_counter_calltf(char *user_data) { vpiHandle inst_h, arg_iter; s_vpi_value value_s; s_vpi_time time_s; s_cb_data cb_data_s; inst_rec *ip; ip = (inst_rec *)malloc(sizeof(inst_rec)); // Get Arguments to System Task inst_h = vpi_handle(vpiSysTfCall, 0); arg_iter = vpi_iterate(vpiArgument, inst_h); ip->clk = vpi_scan(arg_iter); // 1nd argument ip->d_out = vpi_scan(arg_iter); // 2st argument ip->rst = vpi_scan(arg_iter); // 3st argument vpi_free_object(arg_iter); // Set-Up Value Change callback option cb_data_s.user_data = (char *)ip; cb_data_s.reason = cbValueChange; cb_data_s.cb_rtn = sc_counter_interface; cb_data_s.time = &time_s; cb_data_s.value = &value_s; time_s.type = vpiSuppressTime; value_s.format = vpiIntVal; cb_data_s.obj = ip->clk; vpi_register_cb(&cb_data_s); cb_data_s.obj = ip->d_out; vpi_register_cb(&cb_data_s); init_sc(); // Initialize SystemC Model return(0); } //Value change simulation callback routine int sc_counter_interface(p_cb_data cb_data) { inst_rec *ip; s_vpi_value value_s; static unsigned long SimNow = 0; // IO ports systemC testbench static INVECTOR invector; static OUTVECTOR outvector; ip = (inst_rec *)cb_data->user_data; // Read current value from Verilog value_s.format = vpiIntVal; vpi_get_value(ip->clk, &value_s); invector.clk = value_s.value.integer; vpi_get_value(ip->d_out, &value_s); invector.d_out = value_s.value.integer; exec_sc(&invector, &outvector, (tf_gettime()-SimNow)); SimNow = tf_gettime(); value_s.value.integer = outvector.rst; vpi_put_value(ip->rst, &value_s, 0, vpiNoDelay); if (outvector.done) { tf_dofinish(); } return(0); }