OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [test/] [tb_HalfDuplexUartIf.v] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acapola
`timescale 1ns / 1ps
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer:
6
//
7
// Create Date:   22:45:51 10/31/2010
8
// Design Name:   HalfDuplexUartIf
9 3 acapola
// Module Name:   tb_HalfDuplexUartIf.v
10 2 acapola
// Project Name:  Uart
11
// Target Device:  
12
// Tool versions:  
13
// Description: 
14
//
15
// Verilog Test Fixture created by ISE for module: HalfDuplexUartIf
16
//
17
// Dependencies:
18
// 
19
// Revision:
20
// Revision 0.01 - File Created
21
// Additional Comments:
22
// 
23
////////////////////////////////////////////////////////////////////////////////
24
 
25
module tb_HalfDuplexUartIf;
26
parameter CLK_PERIOD = 10;//should be %2
27
parameter DIVIDER_WIDTH = 16;
28
        // Inputs
29
        reg nReset;
30
        reg clk;
31
        reg [DIVIDER_WIDTH-1:0] clkPerCycle;
32
        reg [7:0] dataIn;
33
        reg nWeDataIn;
34
        reg nCsDataOut;
35
        reg nCsStatusOut;
36
        wire serialIn;
37
 
38
        // Outputs
39
        wire [7:0] dataOut;
40
        wire [7:0] statusOut;
41
        wire serialOut;
42
        wire isTx;
43
 
44
        // Inputs
45
        reg [7:0] dataIn2;
46
        reg nWeDataIn2;
47
        reg nCsDataOut2;
48
        reg nCsStatusOut2;
49
        wire serialIn2;
50
 
51
        // Outputs
52
        wire [7:0] dataOut2;
53
        wire [7:0] statusOut2;
54
        wire serialOut2;
55
        wire isTx2;
56
 
57
        // Bidirs
58
        wire serialLine = isTx ? serialOut : isTx2 ? serialOut2 : 1'bz;
59
   pullup(serialLine);
60
 
61
        assign serialIn = serialLine;
62
        assign serialIn2 = serialLine;
63
 
64
        // Instantiate the Unit Under Test (UUT)
65
        HalfDuplexUartIf #(.DIVIDER_WIDTH(DIVIDER_WIDTH))
66
        uut (
67
                .nReset(nReset),
68
                .clk(clk),
69
                .clkPerCycle(clkPerCycle),
70
                .dataIn(dataIn),
71
                .nWeDataIn(nWeDataIn),
72
                .dataOut(dataOut),
73
                .nCsDataOut(nCsDataOut),
74
                .statusOut(statusOut),
75
                .nCsStatusOut(nCsStatusOut),
76
                .serialIn(serialIn),
77
                .serialOut(serialOut),
78
                .isTx(isTx)
79
        );
80
 
81
   HalfDuplexUartIf #(.DIVIDER_WIDTH(DIVIDER_WIDTH))
82
        uut2 (
83
                .nReset(nReset),
84
                .clk(clk),
85
                .clkPerCycle(clkPerCycle),
86
                .dataIn(dataIn2),
87
                .nWeDataIn(nWeDataIn2),
88
                .dataOut(dataOut2),
89
                .nCsDataOut(nCsDataOut2),
90
                .statusOut(statusOut2),
91
                .nCsStatusOut(nCsStatusOut2),
92
                .serialIn(serialIn2),
93
                .serialOut(serialOut2),
94
                .isTx(isTx2)
95
        );
96
 
97
integer tbErrorCnt;
98
wire bufferFull = statusOut[0];
99
wire bufferFull2 = statusOut2[0];
100
wire txPending = statusOut[6];
101
wire txPending2 = statusOut2[6];
102
 
103
/*//this is sensitive to glitch in combo logic so we cannot use wait(txRun == 0) or @negedge(txRun)...
104
wire bufferFull = statusOut[0];
105
wire rxRun = statusOut[5];
106
wire txRun = statusOut[6];
107
 
108
wire bufferFull2 = statusOut2[0];
109
wire rxRun2 = statusOut2[5];
110
wire txRun2 = statusOut2[6];
111
*/
112
//reg bufferFull ;//already registered
113
reg rxRun ;
114
reg txRun ;
115
 
116
//reg bufferFull2 ;
117
reg rxRun2 ;
118
reg txRun2 ;
119
always @(posedge clk) begin
120
   //bufferFull <= statusOut[0];
121
   rxRun <= statusOut[5];
122
   txRun <= statusOut[7];
123
   //bufferFull2 <= statusOut2[0];
124
   rxRun2 <= statusOut2[5];
125
   txRun2 <= statusOut2[7];
126
end
127
 
128
task sendByte;
129
  input [7:0] data;
130
  begin
131
      wait(bufferFull==1'b0);
132
      dataIn=data;
133
      nWeDataIn=0;
134
      @(posedge clk);
135
      dataIn=8'hxx;
136
      nWeDataIn=1;
137
      @(posedge clk);
138
        end
139
endtask
140
 
141
task sendByte2;
142
  input [7:0] data;
143
  begin
144
      wait(bufferFull2==1'b0);
145
      dataIn2=data;
146
      nWeDataIn2=0;
147
      @(posedge clk);
148
      dataIn2=8'hxx;
149
      nWeDataIn2=1;
150
      @(posedge clk);
151
        end
152
endtask
153
 
154
task receiveByte;
155
  input [7:0] data;
156
  begin
157
      wait(txPending==1'b0);//wait start of last tx if any
158
      wait(txRun==1'b0);//wait end of previous transmission if any
159
      wait(bufferFull==1'b1);//wait reception of a byte
160
      @(posedge clk);
161
      nCsDataOut=0;
162
      @(posedge clk);
163
      nCsDataOut=1;
164
      if(data!=dataOut) begin
165
         tbErrorCnt=tbErrorCnt+1;
166
         $display("ERROR %d: uart1 received %x instead of %x",tbErrorCnt, dataOut, data);
167
      end
168
      @(posedge clk);
169
        end
170
endtask
171
 
172
task receiveByte2;
173
  input [7:0] data;
174
  begin
175
      wait(txPending2==1'b0);//wait start of last tx if any
176
      wait(txRun2==1'b0);//wait end of previous transmission if any
177
      wait(bufferFull2==1'b1);//wait reception of a byte
178
      @(posedge clk);
179
      nCsDataOut2=0;
180
      @(posedge clk);
181
      nCsDataOut2=1;
182
      if(data!=dataOut2) begin
183
         tbErrorCnt=tbErrorCnt+1;
184
         $display("ERROR %d: uart2 received %x instead of %x (time=%d)",tbErrorCnt, dataOut2, data,$time);
185
      end else
186
                        $display("INFO: uart2 received %x (time=%d)",dataOut2,$time);
187
      @(posedge clk);
188
        end
189
endtask
190
 
191
integer tbSequenceDone;
192
integer tbSequenceDone2;
193
        initial begin
194
                // Initialize Inputs
195
                nReset = 0;
196
                clk = 0;
197
                dataIn = 0;
198
                clkPerCycle = 0;
199
                nWeDataIn = 1;
200
                nCsDataOut = 1;
201
                nCsStatusOut = 1;
202
                nWeDataIn2 = 1;
203
                nCsDataOut2 = 1;
204
                nCsStatusOut2 = 1;
205
      tbErrorCnt=0;
206
      tbSequenceDone=0;
207
      tbSequenceDone2=0;
208
                // Wait 100 ns for global reset to finish
209
                #(CLK_PERIOD*10);
210
      #(CLK_PERIOD/2);
211
      nReset = 1;
212
      // Add stimulus here
213
      @(posedge clk);
214
      dataIn=8'h3B;
215
      nWeDataIn=0;
216
      @(posedge clk);
217
      dataIn=8'h00;
218
      nWeDataIn=1;
219
      @(posedge clk);
220
      if(bufferFull==1'b0) begin
221
         tbErrorCnt=tbErrorCnt+1;
222
         $display("ERROR %d: bufferFull==1'b0",tbErrorCnt);
223
      end
224
      @(posedge clk);
225
      @(posedge clk);
226
      if(bufferFull==1'b1) begin
227
         tbErrorCnt=tbErrorCnt+1;
228
         $display("ERROR %d: bufferFull==1'b1",tbErrorCnt);
229
      end
230
                //sendByte(8'h3B);
231
 
232
      sendByte(8'h97);
233
      sendByte(8'h12);
234
      sendByte(8'h34);
235
      receiveByte(8'h55);
236
      sendByte(8'h56);
237
      sendByte(8'h78);
238
      tbSequenceDone=1;
239
        end
240
 
241
   initial begin
242
      receiveByte2(8'h3B);
243
      receiveByte2(8'h97);
244
      receiveByte2(8'h12);
245
      receiveByte2(8'h34);
246
      sendByte2(8'h55);
247
      receiveByte2(8'h56);
248
      receiveByte2(8'h78);
249
      tbSequenceDone2=1;
250
   end
251
   initial begin
252
                wait(tbSequenceDone & tbSequenceDone2);
253
      if(tbErrorCnt)
254
         $display("INFO: Test FAILED (%d errors)", tbErrorCnt);
255
      else
256
         $display("INFO: Test PASSED");
257
      #10;
258
                $finish;
259
        end
260
        initial begin
261
                // timeout
262
                #10000;
263
      tbErrorCnt=tbErrorCnt+1;
264
      $display("ERROR: timeout expired");
265
      #10;
266
                $finish;
267
        end
268
 
269
        always
270
                #(CLK_PERIOD/2) clk =  ! clk;
271
 
272
 
273
 
274
endmodule
275
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.