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 10

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 10 acapola
// Engineer: Sebastien Riou
6 3 acapola
//
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 10 acapola
 
52
        //probe outputs
53
        wire probe_termMon;
54
        wire probe_cardMon;
55 3 acapola
 
56
        // Bidirs
57 10 acapola
        wire isoSioTerm;
58
        wire isoSioCard;
59 3 acapola
 
60 4 acapola
wire COM_statusOut=statusOut;
61
wire COM_clk=isoClk;
62
integer COM_errorCnt;
63
 
64
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
65
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
66
 
67
`include "ComDriverTasks.v"
68
 
69 6 acapola
 
70
wire [3:0] spy_fiCode;
71
wire [3:0] spy_diCode;
72
wire [12:0] spy_fi;
73
wire [7:0] spy_di;
74
wire [12:0] spy_cyclesPerEtu;
75
wire [7:0] spy_fMax;
76
wire spy_isActivated,spy_tsReceived,spy_tsError;
77
wire spy_useIndirectConvention,spy_atrIsEarly,spy_atrIsLate;
78
wire [3:0] spy_atrK;
79
wire spy_atrHasTck,spy_atrCompleted;
80
wire spy_useT0,spy_useT1,spy_useT15,spy_waitCardTx,spy_waitTermTx,spy_cardTx,spy_termTx,spy_guardTime;
81
wire spy_overrunError,spy_frameError;
82
wire [7:0] spy_lastByte;
83 7 acapola
wire [31:0] spy_bytesCnt;
84 6 acapola
 
85 3 acapola
        // Instantiate the Unit Under Test (UUT)
86
        Iso7816_3_Master uut (
87
                .nReset(nReset),
88
                .clk(clk),
89
                .clkPerCycle(clkPerCycle),
90
                .startActivation(startActivation),
91
                .startDeactivation(startDeactivation),
92
                .dataIn(dataIn),
93
                .nWeDataIn(nWeDataIn),
94 7 acapola
                .cyclesPerEtu(cyclesPerEtu),
95 3 acapola
                .dataOut(dataOut),
96
                .nCsDataOut(nCsDataOut),
97
                .statusOut(statusOut),
98
                .nCsStatusOut(nCsStatusOut),
99
                .isActivated(isActivated),
100
                .useIndirectConvention(useIndirectConvention),
101
                .tsError(tsError),
102
                .tsReceived(tsReceived),
103
                .atrIsEarly(atrIsEarly),
104
                .atrIsLate(atrIsLate),
105 10 acapola
                .isoSio(isoSioTerm),
106 3 acapola
                .isoClk(isoClk),
107
                .isoReset(isoReset),
108
                .isoVdd(isoVdd)
109
        );
110
 
111
        DummyCard card(
112
                .isoReset(isoReset),
113
                .isoClk(isoClk),
114
                .isoVdd(isoVdd),
115 10 acapola
                .isoSio(isoSioCard)
116 3 acapola
        );
117 10 acapola
 
118
        Iso7816_directionProbe probe(
119
                .isoSioTerm(isoSioTerm),
120
                .isoSioCard(isoSioCard),
121
                .termMon(probe_termMon),
122
                .cardMon(probe_cardMon)
123
        );
124 6 acapola
 
125
        Iso7816_3_t0_analyzer spy (
126
    .nReset(nReset),
127
    .clk(clk),
128
    .clkPerCycle(clkPerCycle[0]),
129
    .isoReset(isoReset),
130
    .isoClk(isoClk),
131
    .isoVdd(isoVdd),
132 10 acapola
    .isoSioTerm(probe_termMon),
133
    .isoSioCard(probe_cardMon),
134
         .useDirectionProbe(1'b1),
135 6 acapola
    .fiCode(spy_fiCode),
136
    .diCode(spy_diCode),
137
    .fi(spy_fi),
138
    .di(spy_di),
139
    .cyclesPerEtu(spy_cyclesPerEtu),
140
    .fMax(spy_fMax),
141
    .isActivated(spy_isActivated),
142
    .tsReceived(spy_tsReceived),
143
    .tsError(spy_tsError),
144
    .useIndirectConvention(spy_useIndirectConvention),
145
    .atrIsEarly(spy_atrIsEarly),
146
    .atrIsLate(spy_atrIsLate),
147
    .atrK(spy_atrK),
148
    .atrHasTck(spy_atrHasTck),
149
    .atrCompleted(spy_atrCompleted),
150
    .useT0(spy_useT0),
151
    .useT1(spy_useT1),
152
    .useT15(spy_useT15),
153
    .waitCardTx(spy_waitCardTx),
154
    .waitTermTx(spy_waitTermTx),
155
    .cardTx(spy_cardTx),
156
    .termTx(spy_termTx),
157
    .guardTime(spy_guardTime),
158
    .overrunError(spy_overrunError),
159
    .frameError(spy_frameError),
160 7 acapola
    .lastByte(spy_lastByte),
161
    .bytesCnt(spy_bytesCnt)
162 6 acapola
    );
163
 
164 4 acapola
 
165 3 acapola
        integer tbErrorCnt;
166
        initial begin
167
                // Initialize Inputs
168 4 acapola
                COM_errorCnt=0;
169 3 acapola
                nReset = 0;
170
                clk = 0;
171
                clkPerCycle = 0;
172
                startActivation = 0;
173
                startDeactivation = 0;
174
                dataIn = 0;
175 4 acapola
                nWeDataIn = 1'b1;
176 7 acapola
                cyclesPerEtu = 372-1;
177 4 acapola
                nCsDataOut = 1'b1;
178
                nCsStatusOut = 1'b1;
179 3 acapola
 
180
                // Wait 100 ns for global reset to finish
181
                #100;
182
      nReset = 1;
183
                // Add stimulus here
184
                #100
185
                startActivation = 1'b1;
186
                wait(isActivated);
187 4 acapola
                wait(tsReceived);
188
                if(atrIsEarly) begin
189
                        $display("ERROR: ATR is early");
190
                        tbErrorCnt=tbErrorCnt+1;
191
                end
192
                if(atrIsLate) begin
193
                        $display("ERROR: ATR is late");
194
                        tbErrorCnt=tbErrorCnt+1;
195
                end
196
                @(posedge clk);
197
                while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
198
                        while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
199
                                @(posedge clk);
200
                        end
201
                        @(posedge clk);
202
                end
203 8 acapola
                $display("Two cycle pause in communication detected, stop simulation, time=",$time);
204
                #(CLK_PERIOD*372*12);
205 3 acapola
                $finish;
206
        end
207 4 acapola
        //T=0 tpdu stimuli
208
        initial begin
209 9 acapola
                //receiveAndCheckByte(8'h3B);
210
                //receiveAndCheckByte(8'h00);
211
                receiveAndCheckHexBytes("3B00");
212
                sendHexBytes("000C000001");
213
                //receiveAndCheckByte(8'h0C);
214
                receiveAndCheckHexBytes("0C");
215
                sendHexBytes("55");
216
                //receiveAndCheckByte(8'h90);
217
                //receiveAndCheckByte(8'h00);
218
                receiveAndCheckHexBytes("9000");
219 4 acapola
        end
220 3 acapola
        initial begin
221
                // timeout
222 7 acapola
                #10000000;
223 3 acapola
      tbErrorCnt=tbErrorCnt+1;
224
      $display("ERROR: timeout expired");
225
      #10;
226
                $finish;
227
        end
228
        always
229
                #(CLK_PERIOD/2) clk =  ! clk;
230
endmodule
231
 

powered by: WebSVN 2.1.0

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