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 12

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-01-29 17:13:49 +0100 (Sat, 29 Jan 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 12 $
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
wire [7:0] spy_lastByte;
93 7 acapola
wire [31:0] spy_bytesCnt;
94 6 acapola
 
95 3 acapola
        // Instantiate the Unit Under Test (UUT)
96
        Iso7816_3_Master uut (
97
                .nReset(nReset),
98
                .clk(clk),
99
                .clkPerCycle(clkPerCycle),
100
                .startActivation(startActivation),
101
                .startDeactivation(startDeactivation),
102
                .dataIn(dataIn),
103
                .nWeDataIn(nWeDataIn),
104 7 acapola
                .cyclesPerEtu(cyclesPerEtu),
105 3 acapola
                .dataOut(dataOut),
106
                .nCsDataOut(nCsDataOut),
107
                .statusOut(statusOut),
108
                .nCsStatusOut(nCsStatusOut),
109
                .isActivated(isActivated),
110
                .useIndirectConvention(useIndirectConvention),
111
                .tsError(tsError),
112
                .tsReceived(tsReceived),
113
                .atrIsEarly(atrIsEarly),
114
                .atrIsLate(atrIsLate),
115 10 acapola
                .isoSio(isoSioTerm),
116 3 acapola
                .isoClk(isoClk),
117
                .isoReset(isoReset),
118
                .isoVdd(isoVdd)
119
        );
120
 
121
        DummyCard card(
122
                .isoReset(isoReset),
123
                .isoClk(isoClk),
124
                .isoVdd(isoVdd),
125 10 acapola
                .isoSio(isoSioCard)
126 3 acapola
        );
127 10 acapola
 
128
        Iso7816_directionProbe probe(
129
                .isoSioTerm(isoSioTerm),
130
                .isoSioCard(isoSioCard),
131
                .termMon(probe_termMon),
132
                .cardMon(probe_cardMon)
133
        );
134 6 acapola
 
135
        Iso7816_3_t0_analyzer spy (
136
    .nReset(nReset),
137
    .clk(clk),
138
    .clkPerCycle(clkPerCycle[0]),
139
    .isoReset(isoReset),
140
    .isoClk(isoClk),
141
    .isoVdd(isoVdd),
142 10 acapola
    .isoSioTerm(probe_termMon),
143
    .isoSioCard(probe_cardMon),
144
         .useDirectionProbe(1'b1),
145 6 acapola
    .fiCode(spy_fiCode),
146
    .diCode(spy_diCode),
147
    .fi(spy_fi),
148
    .di(spy_di),
149
    .cyclesPerEtu(spy_cyclesPerEtu),
150
    .fMax(spy_fMax),
151
    .isActivated(spy_isActivated),
152
    .tsReceived(spy_tsReceived),
153
    .tsError(spy_tsError),
154
    .useIndirectConvention(spy_useIndirectConvention),
155
    .atrIsEarly(spy_atrIsEarly),
156
    .atrIsLate(spy_atrIsLate),
157
    .atrK(spy_atrK),
158
    .atrHasTck(spy_atrHasTck),
159
    .atrCompleted(spy_atrCompleted),
160
    .useT0(spy_useT0),
161
    .useT1(spy_useT1),
162
    .useT15(spy_useT15),
163
    .waitCardTx(spy_waitCardTx),
164
    .waitTermTx(spy_waitTermTx),
165
    .cardTx(spy_cardTx),
166
    .termTx(spy_termTx),
167
    .guardTime(spy_guardTime),
168
    .overrunError(spy_overrunError),
169
    .frameError(spy_frameError),
170 7 acapola
    .lastByte(spy_lastByte),
171
    .bytesCnt(spy_bytesCnt)
172 6 acapola
    );
173
 
174 4 acapola
 
175 3 acapola
        integer tbErrorCnt;
176 11 acapola
        reg tbTestSequenceDone;
177 3 acapola
        initial begin
178
                // Initialize Inputs
179 11 acapola
                tbErrorCnt=0;
180 4 acapola
                COM_errorCnt=0;
181 3 acapola
                nReset = 0;
182
                clk = 0;
183
                clkPerCycle = 0;
184
                startActivation = 0;
185
                startDeactivation = 0;
186
                dataIn = 0;
187 4 acapola
                nWeDataIn = 1'b1;
188 7 acapola
                cyclesPerEtu = 372-1;
189 4 acapola
                nCsDataOut = 1'b1;
190
                nCsStatusOut = 1'b1;
191 3 acapola
 
192
                // Wait 100 ns for global reset to finish
193
                #100;
194
      nReset = 1;
195
                // Add stimulus here
196
                #100
197
                startActivation = 1'b1;
198
                wait(isActivated);
199 4 acapola
                wait(tsReceived);
200
                if(atrIsEarly) begin
201
                        $display("ERROR: ATR is early");
202
                        tbErrorCnt=tbErrorCnt+1;
203
                end
204
                if(atrIsLate) begin
205
                        $display("ERROR: ATR is late");
206
                        tbErrorCnt=tbErrorCnt+1;
207
                end
208
                @(posedge clk);
209
                while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
210
                        while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
211
                                @(posedge clk);
212
                        end
213
                        @(posedge clk);
214
                end
215 11 acapola
                if(1'b1!==tbTestSequenceDone) begin
216
                        $display("ERROR: Two cycle pause in communication detected, stop simulation, time=",$time);
217
                        #(CLK_PERIOD*372*12);
218
                        $finish;
219
                end
220 3 acapola
        end
221 4 acapola
        //T=0 tpdu stimuli
222
        initial begin
223 11 acapola
                tbTestSequenceDone=1'b0;
224 9 acapola
                receiveAndCheckHexBytes("3B00");
225 12 acapola
                sendHexBytes("FF109778");
226
                receiveAndCheckHexBytes("FF109778");
227
                cyclesPerEtu=8-1;
228 9 acapola
                sendHexBytes("000C000001");
229
                receiveAndCheckHexBytes("0C");
230
                sendHexBytes("55");
231
                receiveAndCheckHexBytes("9000");
232 11 acapola
                tbTestSequenceDone=1'b1;
233
                $display("SUCCESS: test sequence completed.");
234
                #(CLK_PERIOD*372*12);
235
                $finish;
236 4 acapola
        end
237 3 acapola
        initial begin
238
                // timeout
239 7 acapola
                #10000000;
240 3 acapola
      tbErrorCnt=tbErrorCnt+1;
241
      $display("ERROR: timeout expired");
242
      #10;
243
                $finish;
244
        end
245
        always
246
                #(CLK_PERIOD/2) clk =  ! clk;
247
endmodule
248 11 acapola
`default_nettype wire
249 3 acapola
 

powered by: WebSVN 2.1.0

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