aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/lib/wishbone/simple_uart_tb.v
blob: 8b1427f99a7f6c439f00caf34b9544fcaf71917a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module simple_uart_tb();
   
   localparam SUART_CLKDIV = 0;
   localparam SUART_TXLEVEL = 1;
   localparam SUART_RXLEVEL = 2;
   localparam SUART_TXCHAR = 3;
   localparam SUART_RXCHAR = 4;
   
   reg           clk;
   reg 		 rst;

   reg 		 we_i;
   reg 		 stb_i;
   reg 		 cyc_i;
   wire 	 ack_o;
   reg [2:0] 	 adr_i;
   reg [31:0] 	 dat_i;
   wire [31:0] 	 dat_o;
   wire 	 rx_int_o;
   wire 	 tx_int_o;
   wire 	 tx_o;
   reg 		 rx_i;
   wire 	 baud_o;

   reg [31:0] 	 read_data;
   

   initial 
     clk = 0;

   // 200MHz clock
   always
     #2.5 clk = ~clk;

   initial begin
      rst <= 0;
      we_i <= 0;
      stb_i <= 0;
      cyc_i <= 0;
      adr_i <= 0;
      dat_i <= 0;
      rx_i <= 0;
   end
   
   
   task write_wb;
      input [31:0] data_in;
      input [2:0]  addr_in;

      begin
	 @(negedge clk);	 
	 dat_i <= data_in;
	 adr_i <= addr_in;
	 we_i <= 1;
	 stb_i <= 1;
	 cyc_i <= 1;
	 @(negedge clk);
	 while (ack_o == 0) begin
	    @(negedge clk);
	 end
	 dat_i <= 0;
	 adr_i <= 0;
	 we_i <= 0;
	 stb_i <= 0;
	 cyc_i <= 0;
      end
   endtask // write_wb

   
   task read_wb;
      output [31:0] data_out;
      input [2:0]  addr_in;

      begin
	 @(negedge clk);	 
	 adr_i <= addr_in;
	 we_i <= 0;
	 stb_i <= 1;
	 cyc_i <= 1;
	 @(negedge clk);
	 while (ack_o == 0) begin
	    @(negedge clk);
	 end
	 data_out <= dat_o;
	 adr_i <= 0;
	 stb_i <= 0;
	 cyc_i <= 0;
      end
   endtask // write_wb

   initial begin
      @(negedge clk);    
      rst <= 1;
      repeat(10) @(negedge clk);
      rst <= 0;
      repeat(10) @(negedge clk);
      write_wb(4'h0620,SUART_CLKDIV);
      repeat(10) @(negedge clk);
      read_wb(read_data,SUART_TXLEVEL);
      repeat(10) @(negedge clk);
   end // initial begin
   
   
   
   simple_uart
     #(.CLKDIV_DEFAULT(16'd0))
   simple_uart_i
     (
      .clk_i(clk),
      .rst_i(rst),
      .we_i(we_i),
      .stb_i(stb_i),
      .cyc_i(cyc_i),
      .ack_o(ack_o),
      .adr_i(adr_i),
      .dat_i(dat_i),
      .dat_o(dat_o),
      .rx_int_o(rx_int_o),
      .tx_int_o(tx_int_o), 
      .tx_o(tx_o), 
      .rx_i(rx_i),
      .baud_o(baud_o)
      );

   

endmodule // simple_uart_tb