|
|
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "acc_user.h"
4 #include "vcs_acc_user.h"
5 #include "svdpi.h"
6
7
8 #include "counter_tb_ports.h"
9 #include "counter_tb_exports.h"
10
11 void sc_counter_init() {
12 init_sc(); // Initialize SystemC Model
13 }
14
15 int sc_counter_interface(int iclk, int idout) {
16 static unsigned long SimNow = 0;
17 int lrst;
18 // IO ports systemC testbench
19 static INVECTOR invector;
20 static OUTVECTOR outvector;
21 invector.clk = iclk;
22 invector.d_out = idout;
23 // Execute the SytemC Shell
24 exec_sc(&invector, &outvector, (tf_gettime()-SimNow));
25 SimNow = tf_gettime();
26 lrst = outvector.rst;
27 if (outvector.done) {
28 tf_dofinish();
29 }
30
31 return(lrst);
32 }
You could download file counter_dpi.c here
|
|
|
1 `timescale 1ns / 1ns
2 //---------------------------------------
3 // Verilog DUT
4 //---------------------------------------
5 module counter(
6 rst, // Reset input
7 clk, // Clock Input
8 d_out // Counter output
9 );
10 // Port Declation
11 input rst;
12 input clk;
13 output [31:0] d_out;
14 // Internal data type
15 reg [31:0] d_out;
16 // Code starts here
17 always @ (posedge clk)
18 if (rst) d_out = 0;
19 else d_out = d_out + 1;
20
21 endmodule
22 //---------------------------------------
23 // Testbench top level
24 //---------------------------------------
25 module tb();
26 reg rst;
27 reg clk;
28 integer iclk,irst,idout;
29 wire [31:0] d_out;
30 // Import the C functions
31 import "DPI" function void sc_counter_init();
32 import "DPI" function int sc_counter_interface
33 (input int iclk, idout);
34 // Assign Integer to reg
35 always @ (clk) iclk = clk;
36 always @ (irst) rst = irst;
37 always @ (d_out) idout = d_out;
38 // Call SystemC interface method, when ever
39 // Input changes
40 always @ (idout or iclk)
41 begin
42 irst = sc_counter_interface(iclk,idout);
43 end
44 // Init the simulation
45 initial begin
46 sc_counter_init();
47 clk = 0;
48 end
49 // Clock generator
50 always #1 clk = ~clk;
51 // DUT connection
52 counter dut (
53 // Inputs
54 rst,
55 clk,
56 // Outputs
57 d_out
58 );
59
60 endmodule
You could download file counter.sv here
|