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 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 acapola
/*
2
Author: Sebastien Riou (acapola)
3
Creation date: 22:45:51 10/31/2010
4
 
5
$LastChangedDate: 2011-01-29 13:16:17 +0100 (Sat, 29 Jan 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 11 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/tb_HalfDuplexUartIf.v $
9
 
10
This file is under the BSD licence:
11
Copyright (c) 2011, Sebastien Riou
12
 
13
All rights reserved.
14
 
15
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
 
17
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
18
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
19
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
`default_nettype none
33 2 acapola
`timescale 1ns / 1ps
34
 
35
module tb_HalfDuplexUartIf;
36
parameter CLK_PERIOD = 10;//should be %2
37
parameter DIVIDER_WIDTH = 16;
38
        // Inputs
39
        reg nReset;
40
        reg clk;
41
        reg [DIVIDER_WIDTH-1:0] clkPerCycle;
42
        reg [7:0] dataIn;
43
        reg nWeDataIn;
44
        reg nCsDataOut;
45
        reg nCsStatusOut;
46
        wire serialIn;
47
 
48
        // Outputs
49
        wire [7:0] dataOut;
50
        wire [7:0] statusOut;
51
        wire serialOut;
52
        wire isTx;
53
 
54
        // Inputs
55
        reg [7:0] dataIn2;
56
        reg nWeDataIn2;
57
        reg nCsDataOut2;
58
        reg nCsStatusOut2;
59
        wire serialIn2;
60
 
61
        // Outputs
62
        wire [7:0] dataOut2;
63
        wire [7:0] statusOut2;
64
        wire serialOut2;
65
        wire isTx2;
66
 
67
        // Bidirs
68
        wire serialLine = isTx ? serialOut : isTx2 ? serialOut2 : 1'bz;
69
   pullup(serialLine);
70
 
71
        assign serialIn = serialLine;
72
        assign serialIn2 = serialLine;
73
 
74
        // Instantiate the Unit Under Test (UUT)
75
        HalfDuplexUartIf #(.DIVIDER_WIDTH(DIVIDER_WIDTH))
76
        uut (
77
                .nReset(nReset),
78
                .clk(clk),
79
                .clkPerCycle(clkPerCycle),
80
                .dataIn(dataIn),
81
                .nWeDataIn(nWeDataIn),
82
                .dataOut(dataOut),
83
                .nCsDataOut(nCsDataOut),
84
                .statusOut(statusOut),
85
                .nCsStatusOut(nCsStatusOut),
86
                .serialIn(serialIn),
87
                .serialOut(serialOut),
88
                .isTx(isTx)
89
        );
90
 
91
   HalfDuplexUartIf #(.DIVIDER_WIDTH(DIVIDER_WIDTH))
92
        uut2 (
93
                .nReset(nReset),
94
                .clk(clk),
95
                .clkPerCycle(clkPerCycle),
96
                .dataIn(dataIn2),
97
                .nWeDataIn(nWeDataIn2),
98
                .dataOut(dataOut2),
99
                .nCsDataOut(nCsDataOut2),
100
                .statusOut(statusOut2),
101
                .nCsStatusOut(nCsStatusOut2),
102
                .serialIn(serialIn2),
103
                .serialOut(serialOut2),
104
                .isTx(isTx2)
105
        );
106
 
107
integer tbErrorCnt;
108
wire bufferFull = statusOut[0];
109
wire bufferFull2 = statusOut2[0];
110
wire txPending = statusOut[6];
111
wire txPending2 = statusOut2[6];
112
 
113
/*//this is sensitive to glitch in combo logic so we cannot use wait(txRun == 0) or @negedge(txRun)...
114
wire bufferFull = statusOut[0];
115
wire rxRun = statusOut[5];
116
wire txRun = statusOut[6];
117
 
118
wire bufferFull2 = statusOut2[0];
119
wire rxRun2 = statusOut2[5];
120
wire txRun2 = statusOut2[6];
121
*/
122
//reg bufferFull ;//already registered
123
reg rxRun ;
124
reg txRun ;
125
 
126
//reg bufferFull2 ;
127
reg rxRun2 ;
128
reg txRun2 ;
129
always @(posedge clk) begin
130
   //bufferFull <= statusOut[0];
131
   rxRun <= statusOut[5];
132
   txRun <= statusOut[7];
133
   //bufferFull2 <= statusOut2[0];
134
   rxRun2 <= statusOut2[5];
135
   txRun2 <= statusOut2[7];
136
end
137
 
138
task sendByte;
139
  input [7:0] data;
140
  begin
141
      wait(bufferFull==1'b0);
142
      dataIn=data;
143
      nWeDataIn=0;
144
      @(posedge clk);
145
      dataIn=8'hxx;
146
      nWeDataIn=1;
147
      @(posedge clk);
148
        end
149
endtask
150
 
151
task sendByte2;
152
  input [7:0] data;
153
  begin
154
      wait(bufferFull2==1'b0);
155
      dataIn2=data;
156
      nWeDataIn2=0;
157
      @(posedge clk);
158
      dataIn2=8'hxx;
159
      nWeDataIn2=1;
160
      @(posedge clk);
161
        end
162
endtask
163
 
164
task receiveByte;
165
  input [7:0] data;
166
  begin
167
      wait(txPending==1'b0);//wait start of last tx if any
168
      wait(txRun==1'b0);//wait end of previous transmission if any
169
      wait(bufferFull==1'b1);//wait reception of a byte
170
      @(posedge clk);
171
      nCsDataOut=0;
172
      @(posedge clk);
173
      nCsDataOut=1;
174
      if(data!=dataOut) begin
175
         tbErrorCnt=tbErrorCnt+1;
176
         $display("ERROR %d: uart1 received %x instead of %x",tbErrorCnt, dataOut, data);
177
      end
178
      @(posedge clk);
179
        end
180
endtask
181
 
182
task receiveByte2;
183
  input [7:0] data;
184
  begin
185
      wait(txPending2==1'b0);//wait start of last tx if any
186
      wait(txRun2==1'b0);//wait end of previous transmission if any
187
      wait(bufferFull2==1'b1);//wait reception of a byte
188
      @(posedge clk);
189
      nCsDataOut2=0;
190
      @(posedge clk);
191
      nCsDataOut2=1;
192
      if(data!=dataOut2) begin
193
         tbErrorCnt=tbErrorCnt+1;
194
         $display("ERROR %d: uart2 received %x instead of %x (time=%d)",tbErrorCnt, dataOut2, data,$time);
195
      end else
196
                        $display("INFO: uart2 received %x (time=%d)",dataOut2,$time);
197
      @(posedge clk);
198
        end
199
endtask
200
 
201
integer tbSequenceDone;
202
integer tbSequenceDone2;
203
        initial begin
204
                // Initialize Inputs
205
                nReset = 0;
206
                clk = 0;
207
                dataIn = 0;
208
                clkPerCycle = 0;
209
                nWeDataIn = 1;
210
                nCsDataOut = 1;
211
                nCsStatusOut = 1;
212
                nWeDataIn2 = 1;
213
                nCsDataOut2 = 1;
214
                nCsStatusOut2 = 1;
215
      tbErrorCnt=0;
216
      tbSequenceDone=0;
217
      tbSequenceDone2=0;
218
                // Wait 100 ns for global reset to finish
219
                #(CLK_PERIOD*10);
220
      #(CLK_PERIOD/2);
221
      nReset = 1;
222
      // Add stimulus here
223
      @(posedge clk);
224
      dataIn=8'h3B;
225
      nWeDataIn=0;
226
      @(posedge clk);
227
      dataIn=8'h00;
228
      nWeDataIn=1;
229
      @(posedge clk);
230
      if(bufferFull==1'b0) begin
231
         tbErrorCnt=tbErrorCnt+1;
232
         $display("ERROR %d: bufferFull==1'b0",tbErrorCnt);
233
      end
234
      @(posedge clk);
235
      @(posedge clk);
236
      if(bufferFull==1'b1) begin
237
         tbErrorCnt=tbErrorCnt+1;
238
         $display("ERROR %d: bufferFull==1'b1",tbErrorCnt);
239
      end
240
                //sendByte(8'h3B);
241
 
242
      sendByte(8'h97);
243
      sendByte(8'h12);
244
      sendByte(8'h34);
245
      receiveByte(8'h55);
246
      sendByte(8'h56);
247
      sendByte(8'h78);
248
      tbSequenceDone=1;
249
        end
250
 
251
   initial begin
252
      receiveByte2(8'h3B);
253
      receiveByte2(8'h97);
254
      receiveByte2(8'h12);
255
      receiveByte2(8'h34);
256
      sendByte2(8'h55);
257
      receiveByte2(8'h56);
258
      receiveByte2(8'h78);
259
      tbSequenceDone2=1;
260
   end
261
   initial begin
262
                wait(tbSequenceDone & tbSequenceDone2);
263
      if(tbErrorCnt)
264
         $display("INFO: Test FAILED (%d errors)", tbErrorCnt);
265
      else
266
         $display("INFO: Test PASSED");
267
      #10;
268
                $finish;
269
        end
270
        initial begin
271
                // timeout
272
                #10000;
273
      tbErrorCnt=tbErrorCnt+1;
274
      $display("ERROR: timeout expired");
275
      #10;
276
                $finish;
277
        end
278
 
279
        always
280
                #(CLK_PERIOD/2) clk =  ! clk;
281
 
282
 
283
 
284
endmodule
285 11 acapola
`default_nettype wire
286 2 acapola
 

powered by: WebSVN 2.1.0

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