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