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 18

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

powered by: WebSVN 2.1.0

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