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 15

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

Line No. Rev Author Line
1 11 acapola
/*
2
Author: Sebastien Riou (acapola)
3
Creation date: 22:16:42 01/10/2011
4
 
5
$LastChangedDate: 2011-02-13 16:20:10 +0100 (Sun, 13 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 15 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/tbIso7816_3_Master.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 3 acapola
`timescale 1ns / 1ps
34
 
35
module tbIso7816_3_Master;
36
parameter CLK_PERIOD = 10;//should be %2
37
        // Inputs
38
        reg nReset;
39
        reg clk;
40
        reg [15:0] clkPerCycle;
41
        reg startActivation;
42
        reg startDeactivation;
43
        reg [7:0] dataIn;
44
        reg nWeDataIn;
45 7 acapola
        reg [12:0] cyclesPerEtu;
46 3 acapola
        reg nCsDataOut;
47
        reg nCsStatusOut;
48
 
49
        // Outputs
50
        wire [7:0] dataOut;
51
        wire [7:0] statusOut;
52
        wire isActivated;
53
        wire useIndirectConvention;
54
        wire tsError;
55
        wire tsReceived;
56
        wire atrIsEarly;
57
        wire atrIsLate;
58
        wire isoClk;
59
        wire isoReset;
60
        wire isoVdd;
61 10 acapola
 
62
        //probe outputs
63
        wire probe_termMon;
64
        wire probe_cardMon;
65 3 acapola
 
66
        // Bidirs
67 10 acapola
        wire isoSioTerm;
68
        wire isoSioCard;
69 3 acapola
 
70 4 acapola
wire COM_statusOut=statusOut;
71
wire COM_clk=isoClk;
72
integer COM_errorCnt;
73
 
74
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
75
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
76
 
77
`include "ComDriverTasks.v"
78
 
79 6 acapola
 
80
wire [3:0] spy_fiCode;
81
wire [3:0] spy_diCode;
82
wire [12:0] spy_fi;
83
wire [7:0] spy_di;
84
wire [12:0] spy_cyclesPerEtu;
85
wire [7:0] spy_fMax;
86
wire spy_isActivated,spy_tsReceived,spy_tsError;
87
wire spy_useIndirectConvention,spy_atrIsEarly,spy_atrIsLate;
88
wire [3:0] spy_atrK;
89
wire spy_atrHasTck,spy_atrCompleted;
90
wire spy_useT0,spy_useT1,spy_useT15,spy_waitCardTx,spy_waitTermTx,spy_cardTx,spy_termTx,spy_guardTime;
91
wire spy_overrunError,spy_frameError;
92 15 acapola
wire spy_comOnGoing;
93 6 acapola
wire [7:0] spy_lastByte;
94 7 acapola
wire [31:0] spy_bytesCnt;
95 6 acapola
 
96 3 acapola
        // Instantiate the Unit Under Test (UUT)
97
        Iso7816_3_Master uut (
98
                .nReset(nReset),
99
                .clk(clk),
100
                .clkPerCycle(clkPerCycle),
101
                .startActivation(startActivation),
102
                .startDeactivation(startDeactivation),
103
                .dataIn(dataIn),
104
                .nWeDataIn(nWeDataIn),
105 7 acapola
                .cyclesPerEtu(cyclesPerEtu),
106 3 acapola
                .dataOut(dataOut),
107
                .nCsDataOut(nCsDataOut),
108
                .statusOut(statusOut),
109
                .nCsStatusOut(nCsStatusOut),
110
                .isActivated(isActivated),
111
                .useIndirectConvention(useIndirectConvention),
112
                .tsError(tsError),
113
                .tsReceived(tsReceived),
114
                .atrIsEarly(atrIsEarly),
115
                .atrIsLate(atrIsLate),
116 10 acapola
                .isoSio(isoSioTerm),
117 3 acapola
                .isoClk(isoClk),
118
                .isoReset(isoReset),
119
                .isoVdd(isoVdd)
120
        );
121
 
122
        DummyCard card(
123
                .isoReset(isoReset),
124
                .isoClk(isoClk),
125
                .isoVdd(isoVdd),
126 10 acapola
                .isoSio(isoSioCard)
127 3 acapola
        );
128 10 acapola
 
129
        Iso7816_directionProbe probe(
130
                .isoSioTerm(isoSioTerm),
131
                .isoSioCard(isoSioCard),
132
                .termMon(probe_termMon),
133
                .cardMon(probe_cardMon)
134
        );
135 6 acapola
 
136
        Iso7816_3_t0_analyzer spy (
137
    .nReset(nReset),
138
    .clk(clk),
139
    .clkPerCycle(clkPerCycle[0]),
140
    .isoReset(isoReset),
141
    .isoClk(isoClk),
142
    .isoVdd(isoVdd),
143 10 acapola
    .isoSioTerm(probe_termMon),
144
    .isoSioCard(probe_cardMon),
145
         .useDirectionProbe(1'b1),
146 6 acapola
    .fiCode(spy_fiCode),
147
    .diCode(spy_diCode),
148
    .fi(spy_fi),
149
    .di(spy_di),
150
    .cyclesPerEtu(spy_cyclesPerEtu),
151
    .fMax(spy_fMax),
152
    .isActivated(spy_isActivated),
153
    .tsReceived(spy_tsReceived),
154
    .tsError(spy_tsError),
155
    .useIndirectConvention(spy_useIndirectConvention),
156
    .atrIsEarly(spy_atrIsEarly),
157
    .atrIsLate(spy_atrIsLate),
158
    .atrK(spy_atrK),
159
    .atrHasTck(spy_atrHasTck),
160
    .atrCompleted(spy_atrCompleted),
161
    .useT0(spy_useT0),
162
    .useT1(spy_useT1),
163
    .useT15(spy_useT15),
164
    .waitCardTx(spy_waitCardTx),
165
    .waitTermTx(spy_waitTermTx),
166
    .cardTx(spy_cardTx),
167
    .termTx(spy_termTx),
168
    .guardTime(spy_guardTime),
169
    .overrunError(spy_overrunError),
170
    .frameError(spy_frameError),
171 15 acapola
    .comOnGoing(spy_comOnGoing),
172
         .lastByte(spy_lastByte),
173 7 acapola
    .bytesCnt(spy_bytesCnt)
174 6 acapola
    );
175
 
176 4 acapola
 
177 3 acapola
        integer tbErrorCnt;
178 11 acapola
        reg tbTestSequenceDone;
179 3 acapola
        initial begin
180
                // Initialize Inputs
181 11 acapola
                tbErrorCnt=0;
182 4 acapola
                COM_errorCnt=0;
183 3 acapola
                nReset = 0;
184
                clk = 0;
185
                clkPerCycle = 0;
186
                startActivation = 0;
187
                startDeactivation = 0;
188
                dataIn = 0;
189 4 acapola
                nWeDataIn = 1'b1;
190 7 acapola
                cyclesPerEtu = 372-1;
191 4 acapola
                nCsDataOut = 1'b1;
192
                nCsStatusOut = 1'b1;
193 3 acapola
 
194
                // Wait 100 ns for global reset to finish
195
                #100;
196
      nReset = 1;
197
                // Add stimulus here
198
                #100
199
                startActivation = 1'b1;
200
                wait(isActivated);
201 4 acapola
                wait(tsReceived);
202 13 acapola
                if(tsError) begin
203
                        $display("ERROR: ATR's TS is invalid");
204
                        tbErrorCnt=tbErrorCnt+1;
205
                end
206 4 acapola
                if(atrIsEarly) begin
207
                        $display("ERROR: ATR is early");
208
                        tbErrorCnt=tbErrorCnt+1;
209
                end
210
                if(atrIsLate) begin
211
                        $display("ERROR: ATR is late");
212
                        tbErrorCnt=tbErrorCnt+1;
213
                end
214
                @(posedge clk);
215 15 acapola
                while((1'b0===spy_atrCompleted)||(txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
216
                        while((1'b0===spy_atrCompleted)||(txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
217 4 acapola
                                @(posedge clk);
218
                        end
219
                        @(posedge clk);
220
                end
221 11 acapola
                if(1'b1!==tbTestSequenceDone) begin
222
                        $display("ERROR: Two cycle pause in communication detected, stop simulation, time=",$time);
223
                        #(CLK_PERIOD*372*12);
224
                        $finish;
225
                end
226 3 acapola
        end
227 4 acapola
        //T=0 tpdu stimuli
228 15 acapola
        //reg [7:0] byteFromCard;
229
        reg [8*256:0] bytesFromCard;
230 4 acapola
        initial begin
231 11 acapola
                tbTestSequenceDone=1'b0;
232 13 acapola
                //receiveAndCheckHexBytes("3B00");
233 15 acapola
                receiveByte(bytesFromCard[7:0]);//3B or 3F, so we don't check (Master and Spy do)
234 14 acapola
                //receiveAndCheckHexBytes("9497801F42BABEBABE");
235
                //TODO: handle TCK-->receiveAndCheckHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 0D");
236
                receiveAndCheckHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00");
237 12 acapola
                sendHexBytes("FF109778");
238
                receiveAndCheckHexBytes("FF109778");
239
                cyclesPerEtu=8-1;
240 15 acapola
                //sendHexBytes("000C000001");
241
                //receiveAndCheckHexBytes("0C");
242
                //sendHexBytes("55");
243
                sendT0TpduLc("000C000004 CAFEBABE");//write buffer
244 9 acapola
                receiveAndCheckHexBytes("9000");
245 15 acapola
 
246
                sendT0TpduLc("00FC000000");//change convention for next ATR
247
                receiveAndCheckHexBytes("9000");
248
 
249
                sendT0TpduLeCheck("000A000004","CAFEBABE");//read buffer
250
                receiveAndCheckHexBytes("9000");
251
 
252
/*              //Reset not supported by the dummy card yet because we use "wait()" in Com tasks...
253
                wait(spy_comOnGoing===1'b0);
254
                wait(spy_guardTime===1'b0);
255
 
256
                startActivation = 1'b0;
257
                startDeactivation = 1'b1;
258
                cyclesPerEtu = 372-1;
259
                wait(1'b0===spy_isActivated);
260
                startDeactivation = 0;
261
                startActivation = 1'b1;
262
 
263
                receiveAndCheckHexBytes("3B 9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00");
264
                sendT0TpduLeCheck("000A000004","CAFEBABE");//read buffer
265
                receiveAndCheckHexBytes("9000");
266
*/
267 11 acapola
                tbTestSequenceDone=1'b1;
268
                #(CLK_PERIOD*372*12);
269 14 acapola
                if(0===tbErrorCnt) $display("SUCCESS: test sequence completed.");
270 11 acapola
                $finish;
271 4 acapola
        end
272 3 acapola
        initial begin
273
                // timeout
274 7 acapola
                #10000000;
275 3 acapola
      tbErrorCnt=tbErrorCnt+1;
276
      $display("ERROR: timeout expired");
277
      #10;
278
                $finish;
279
        end
280
        always
281
                #(CLK_PERIOD/2) clk =  ! clk;
282
endmodule
283 11 acapola
`default_nettype wire
284 3 acapola
 

powered by: WebSVN 2.1.0

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