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 20

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

powered by: WebSVN 2.1.0

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