|
|
1 `timescale 1ns / 1ns
2 // Verilog DUT
3 module counter(
4 rst, // Reset input
5 clk, // Clock Input
6 d_out // Counter output
7 );
8 // Port Declation
9 input rst;
10 input clk;
11 output [31:0] d_out;
12 // Internal data type
13 reg [31:0] d_out;
14 // Code starts here
15 always @ (posedge clk)
16 if (rst) d_out <= 0;
17 else d_out <= d_out + 1;
18
19 endmodule
20 // Testbench top level
21 module tb();
22 reg rst;
23 reg clk;
24 wire [31:0] d_out;
25
26 initial begin
27 $sc_counter(clk, d_out, rst);// Testbench Connection
28 clk = 0;
29 end
30 // Clock generator
31 always #1 clk = ~clk;
32 // DUT connection
33 counter dut (
34 // Inputs
35 rst,
36 clk,
37 // Outputs
38 d_out
39 );
40
41 endmodule
You could download file counter.v here
|
|
|
1 #ifndef COUNTER_H
2 #define COUNTER_H
3
4 #include "systemc.h"
5
6 SC_MODULE (counter) {
7 sc_in<bool> clk; // clock input
8 sc_out<bool> rst; // reset ouput
9 sc_in<sc_uint<32> > d_out; // data input
10 sc_out<int> done; // Terminate sim
11
12 void cnt_model ();
13 void monitor ();
14 void test ();
15
16 sc_uint<32> cnt; // counter model
17 int error; // Error status
18
19 SC_CTOR(counter) {
20 SC_CTHREAD(monitor,clk.pos());
21 SC_CTHREAD(cnt_model,clk.pos());
22 SC_CTHREAD(test,clk.pos());
23 }
24 };
25
26 #endif
You could download file counter.h here
|