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

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [test/] [tbIso7816_3_Master.v] - Blame information for rev 7

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

Line No. Rev Author Line
1 3 acapola
`timescale 1ns / 1ps
2 4 acapola
`default_nettype none
3 3 acapola
////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer:
6
//
7
// Create Date:   22:16:42 01/10/2011
8
// Design Name:   Iso7816_3_Master
9
// Module Name:   tbIso7816_3_Master.v
10
// Project Name:  Uart
11
// Target Device:  
12
// Tool versions:  
13
// Description: 
14
//
15
// Verilog Test Fixture created by ISE for module: Iso7816_3_Master
16
//
17
// Dependencies:
18
// 
19
// Revision:
20
// Revision 0.01 - File Created
21
// Additional Comments:
22
// 
23
////////////////////////////////////////////////////////////////////////////////
24
 
25
module tbIso7816_3_Master;
26
parameter CLK_PERIOD = 10;//should be %2
27
        // Inputs
28
        reg nReset;
29
        reg clk;
30
        reg [15:0] clkPerCycle;
31
        reg startActivation;
32
        reg startDeactivation;
33
        reg [7:0] dataIn;
34
        reg nWeDataIn;
35 7 acapola
        reg [12:0] cyclesPerEtu;
36 3 acapola
        reg nCsDataOut;
37
        reg nCsStatusOut;
38
 
39
        // Outputs
40
        wire [7:0] dataOut;
41
        wire [7:0] statusOut;
42
        wire isActivated;
43
        wire useIndirectConvention;
44
        wire tsError;
45
        wire tsReceived;
46
        wire atrIsEarly;
47
        wire atrIsLate;
48
        wire isoClk;
49
        wire isoReset;
50
        wire isoVdd;
51
 
52
        // Bidirs
53
        wire isoSio;
54
 
55 4 acapola
wire COM_statusOut=statusOut;
56
wire COM_clk=isoClk;
57
integer COM_errorCnt;
58
 
59
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
60
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
61
 
62
`include "ComDriverTasks.v"
63
 
64 6 acapola
 
65
wire [3:0] spy_fiCode;
66
wire [3:0] spy_diCode;
67
wire [12:0] spy_fi;
68
wire [7:0] spy_di;
69
wire [12:0] spy_cyclesPerEtu;
70
wire [7:0] spy_fMax;
71
wire spy_isActivated,spy_tsReceived,spy_tsError;
72
wire spy_useIndirectConvention,spy_atrIsEarly,spy_atrIsLate;
73
wire [3:0] spy_atrK;
74
wire spy_atrHasTck,spy_atrCompleted;
75
wire spy_useT0,spy_useT1,spy_useT15,spy_waitCardTx,spy_waitTermTx,spy_cardTx,spy_termTx,spy_guardTime;
76
wire spy_overrunError,spy_frameError;
77
wire [7:0] spy_lastByte;
78 7 acapola
wire [31:0] spy_bytesCnt;
79 6 acapola
 
80 3 acapola
        // Instantiate the Unit Under Test (UUT)
81
        Iso7816_3_Master uut (
82
                .nReset(nReset),
83
                .clk(clk),
84
                .clkPerCycle(clkPerCycle),
85
                .startActivation(startActivation),
86
                .startDeactivation(startDeactivation),
87
                .dataIn(dataIn),
88
                .nWeDataIn(nWeDataIn),
89 7 acapola
                .cyclesPerEtu(cyclesPerEtu),
90 3 acapola
                .dataOut(dataOut),
91
                .nCsDataOut(nCsDataOut),
92
                .statusOut(statusOut),
93
                .nCsStatusOut(nCsStatusOut),
94
                .isActivated(isActivated),
95
                .useIndirectConvention(useIndirectConvention),
96
                .tsError(tsError),
97
                .tsReceived(tsReceived),
98
                .atrIsEarly(atrIsEarly),
99
                .atrIsLate(atrIsLate),
100
                .isoSio(isoSio),
101
                .isoClk(isoClk),
102
                .isoReset(isoReset),
103
                .isoVdd(isoVdd)
104
        );
105
 
106
        DummyCard card(
107
                .isoReset(isoReset),
108
                .isoClk(isoClk),
109
                .isoVdd(isoVdd),
110
                .isoSio(isoSio)
111
        );
112 6 acapola
 
113
        Iso7816_3_t0_analyzer spy (
114
    .nReset(nReset),
115
    .clk(clk),
116
    .clkPerCycle(clkPerCycle[0]),
117
    .isoReset(isoReset),
118
    .isoClk(isoClk),
119
    .isoVdd(isoVdd),
120
    .isoSio(isoSio),
121
    .fiCode(spy_fiCode),
122
    .diCode(spy_diCode),
123
    .fi(spy_fi),
124
    .di(spy_di),
125
    .cyclesPerEtu(spy_cyclesPerEtu),
126
    .fMax(spy_fMax),
127
    .isActivated(spy_isActivated),
128
    .tsReceived(spy_tsReceived),
129
    .tsError(spy_tsError),
130
    .useIndirectConvention(spy_useIndirectConvention),
131
    .atrIsEarly(spy_atrIsEarly),
132
    .atrIsLate(spy_atrIsLate),
133
    .atrK(spy_atrK),
134
    .atrHasTck(spy_atrHasTck),
135
    .atrCompleted(spy_atrCompleted),
136
    .useT0(spy_useT0),
137
    .useT1(spy_useT1),
138
    .useT15(spy_useT15),
139
    .waitCardTx(spy_waitCardTx),
140
    .waitTermTx(spy_waitTermTx),
141
    .cardTx(spy_cardTx),
142
    .termTx(spy_termTx),
143
    .guardTime(spy_guardTime),
144
    .overrunError(spy_overrunError),
145
    .frameError(spy_frameError),
146 7 acapola
    .lastByte(spy_lastByte),
147
    .bytesCnt(spy_bytesCnt)
148 6 acapola
    );
149
 
150 4 acapola
 
151 3 acapola
        integer tbErrorCnt;
152
        initial begin
153
                // Initialize Inputs
154 4 acapola
                COM_errorCnt=0;
155 3 acapola
                nReset = 0;
156
                clk = 0;
157
                clkPerCycle = 0;
158
                startActivation = 0;
159
                startDeactivation = 0;
160
                dataIn = 0;
161 4 acapola
                nWeDataIn = 1'b1;
162 7 acapola
                cyclesPerEtu = 372-1;
163 4 acapola
                nCsDataOut = 1'b1;
164
                nCsStatusOut = 1'b1;
165 3 acapola
 
166
                // Wait 100 ns for global reset to finish
167
                #100;
168
      nReset = 1;
169
                // Add stimulus here
170
                #100
171
                startActivation = 1'b1;
172
                wait(isActivated);
173 4 acapola
                wait(tsReceived);
174
                if(atrIsEarly) begin
175
                        $display("ERROR: ATR is early");
176
                        tbErrorCnt=tbErrorCnt+1;
177
                end
178
                if(atrIsLate) begin
179
                        $display("ERROR: ATR is late");
180
                        tbErrorCnt=tbErrorCnt+1;
181
                end
182
                @(posedge clk);
183
                while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
184
                        while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
185
                                @(posedge clk);
186
                        end
187
                        @(posedge clk);
188
                end
189
                $display("Two cycle pause in communication detected, stop simulation");
190 3 acapola
                #200
191
                $finish;
192
        end
193 4 acapola
        //T=0 tpdu stimuli
194
        initial begin
195
                receiveAndCheckByte(8'h3B);
196
                receiveAndCheckByte(8'h00);
197
                //sendBytes("000C000001");//would be handy, TODO
198
                sendByte(8'h00);
199
                sendByte(8'h0C);
200
                sendByte(8'h00);
201
                sendByte(8'h00);
202
                sendByte(8'h01);
203
                receiveAndCheckByte(8'h0C);
204
                //sendBytes("55");
205
                sendByte(8'h55);
206
                receiveAndCheckByte(8'h90);
207
                receiveAndCheckByte(8'h00);
208
        end
209 3 acapola
        initial begin
210
                // timeout
211 7 acapola
                #10000000;
212 3 acapola
      tbErrorCnt=tbErrorCnt+1;
213
      $display("ERROR: timeout expired");
214
      #10;
215
                $finish;
216
        end
217
        always
218
                #(CLK_PERIOD/2) clk =  ! clk;
219
endmodule
220
 

powered by: WebSVN 2.1.0

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