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 6

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
        reg [12:0] cyclePerEtu;
36
        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
 
79 3 acapola
        // Instantiate the Unit Under Test (UUT)
80
        Iso7816_3_Master uut (
81
                .nReset(nReset),
82
                .clk(clk),
83
                .clkPerCycle(clkPerCycle),
84
                .startActivation(startActivation),
85
                .startDeactivation(startDeactivation),
86
                .dataIn(dataIn),
87
                .nWeDataIn(nWeDataIn),
88
                .cyclePerEtu(cyclePerEtu),
89
                .dataOut(dataOut),
90
                .nCsDataOut(nCsDataOut),
91
                .statusOut(statusOut),
92
                .nCsStatusOut(nCsStatusOut),
93
                .isActivated(isActivated),
94
                .useIndirectConvention(useIndirectConvention),
95
                .tsError(tsError),
96
                .tsReceived(tsReceived),
97
                .atrIsEarly(atrIsEarly),
98
                .atrIsLate(atrIsLate),
99
                .isoSio(isoSio),
100
                .isoClk(isoClk),
101
                .isoReset(isoReset),
102
                .isoVdd(isoVdd)
103
        );
104
 
105
        DummyCard card(
106
                .isoReset(isoReset),
107
                .isoClk(isoClk),
108
                .isoVdd(isoVdd),
109
                .isoSio(isoSio)
110
        );
111 6 acapola
 
112
        Iso7816_3_t0_analyzer spy (
113
    .nReset(nReset),
114
    .clk(clk),
115
    .clkPerCycle(clkPerCycle[0]),
116
    .isoReset(isoReset),
117
    .isoClk(isoClk),
118
    .isoVdd(isoVdd),
119
    .isoSio(isoSio),
120
    .fiCode(spy_fiCode),
121
    .diCode(spy_diCode),
122
    .fi(spy_fi),
123
    .di(spy_di),
124
    .cyclesPerEtu(spy_cyclesPerEtu),
125
    .fMax(spy_fMax),
126
    .isActivated(spy_isActivated),
127
    .tsReceived(spy_tsReceived),
128
    .tsError(spy_tsError),
129
    .useIndirectConvention(spy_useIndirectConvention),
130
    .atrIsEarly(spy_atrIsEarly),
131
    .atrIsLate(spy_atrIsLate),
132
    .atrK(spy_atrK),
133
    .atrHasTck(spy_atrHasTck),
134
    .atrCompleted(spy_atrCompleted),
135
    .useT0(spy_useT0),
136
    .useT1(spy_useT1),
137
    .useT15(spy_useT15),
138
    .waitCardTx(spy_waitCardTx),
139
    .waitTermTx(spy_waitTermTx),
140
    .cardTx(spy_cardTx),
141
    .termTx(spy_termTx),
142
    .guardTime(spy_guardTime),
143
    .overrunError(spy_overrunError),
144
    .frameError(spy_frameError),
145
    .lastByte(spy_lastByte)
146
    );
147
 
148 4 acapola
 
149 3 acapola
        integer tbErrorCnt;
150
        initial begin
151
                // Initialize Inputs
152 4 acapola
                COM_errorCnt=0;
153 3 acapola
                nReset = 0;
154
                clk = 0;
155
                clkPerCycle = 0;
156
                startActivation = 0;
157
                startDeactivation = 0;
158
                dataIn = 0;
159 4 acapola
                nWeDataIn = 1'b1;
160 3 acapola
                cyclePerEtu = 0;
161 4 acapola
                nCsDataOut = 1'b1;
162
                nCsStatusOut = 1'b1;
163 3 acapola
 
164
                // Wait 100 ns for global reset to finish
165
                #100;
166
      nReset = 1;
167
                // Add stimulus here
168
                #100
169
                startActivation = 1'b1;
170
                wait(isActivated);
171 4 acapola
                wait(tsReceived);
172
                if(atrIsEarly) begin
173
                        $display("ERROR: ATR is early");
174
                        tbErrorCnt=tbErrorCnt+1;
175
                end
176
                if(atrIsLate) begin
177
                        $display("ERROR: ATR is late");
178
                        tbErrorCnt=tbErrorCnt+1;
179
                end
180
                @(posedge clk);
181
                while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
182
                        while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
183
                                @(posedge clk);
184
                        end
185
                        @(posedge clk);
186
                end
187
                $display("Two cycle pause in communication detected, stop simulation");
188 3 acapola
                #200
189
                $finish;
190
        end
191 4 acapola
        //T=0 tpdu stimuli
192
        initial begin
193
                receiveAndCheckByte(8'h3B);
194
                receiveAndCheckByte(8'h00);
195
                //sendBytes("000C000001");//would be handy, TODO
196
                sendByte(8'h00);
197
                sendByte(8'h0C);
198
                sendByte(8'h00);
199
                sendByte(8'h00);
200
                sendByte(8'h01);
201
                receiveAndCheckByte(8'h0C);
202
                //sendBytes("55");
203
                sendByte(8'h55);
204
                receiveAndCheckByte(8'h90);
205
                receiveAndCheckByte(8'h00);
206
        end
207 3 acapola
        initial begin
208
                // timeout
209 4 acapola
                #100000;
210 3 acapola
      tbErrorCnt=tbErrorCnt+1;
211
      $display("ERROR: timeout expired");
212
      #10;
213
                $finish;
214
        end
215
        always
216
                #(CLK_PERIOD/2) clk =  ! clk;
217
endmodule
218
 

powered by: WebSVN 2.1.0

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