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 4

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
// Engineer:
6
//
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
        reg [12:0] cyclePerEtu;
36
        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
 
52
        // Bidirs
53
        wire isoSio;
54
 
55 4 acapola
wire COM_statusOut=statusOut;
56
wire COM_clk=isoClk;
57
integer COM_errorCnt;
58
 
59
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
60
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
61
 
62
`include "ComDriverTasks.v"
63
 
64 3 acapola
        // Instantiate the Unit Under Test (UUT)
65
        Iso7816_3_Master uut (
66
                .nReset(nReset),
67
                .clk(clk),
68
                .clkPerCycle(clkPerCycle),
69
                .startActivation(startActivation),
70
                .startDeactivation(startDeactivation),
71
                .dataIn(dataIn),
72
                .nWeDataIn(nWeDataIn),
73
                .cyclePerEtu(cyclePerEtu),
74
                .dataOut(dataOut),
75
                .nCsDataOut(nCsDataOut),
76
                .statusOut(statusOut),
77
                .nCsStatusOut(nCsStatusOut),
78
                .isActivated(isActivated),
79
                .useIndirectConvention(useIndirectConvention),
80
                .tsError(tsError),
81
                .tsReceived(tsReceived),
82
                .atrIsEarly(atrIsEarly),
83
                .atrIsLate(atrIsLate),
84
                .isoSio(isoSio),
85
                .isoClk(isoClk),
86
                .isoReset(isoReset),
87
                .isoVdd(isoVdd)
88
        );
89
 
90
        DummyCard card(
91
                .isoReset(isoReset),
92
                .isoClk(isoClk),
93
                .isoVdd(isoVdd),
94
                .isoSio(isoSio)
95
        );
96 4 acapola
 
97 3 acapola
        integer tbErrorCnt;
98
        initial begin
99
                // Initialize Inputs
100 4 acapola
                COM_errorCnt=0;
101 3 acapola
                nReset = 0;
102
                clk = 0;
103
                clkPerCycle = 0;
104
                startActivation = 0;
105
                startDeactivation = 0;
106
                dataIn = 0;
107 4 acapola
                nWeDataIn = 1'b1;
108 3 acapola
                cyclePerEtu = 0;
109 4 acapola
                nCsDataOut = 1'b1;
110
                nCsStatusOut = 1'b1;
111 3 acapola
 
112
                // Wait 100 ns for global reset to finish
113
                #100;
114
      nReset = 1;
115
                // Add stimulus here
116
                #100
117
                startActivation = 1'b1;
118
                wait(isActivated);
119 4 acapola
                wait(tsReceived);
120
                if(atrIsEarly) begin
121
                        $display("ERROR: ATR is early");
122
                        tbErrorCnt=tbErrorCnt+1;
123
                end
124
                if(atrIsLate) begin
125
                        $display("ERROR: ATR is late");
126
                        tbErrorCnt=tbErrorCnt+1;
127
                end
128
                @(posedge clk);
129
                while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
130
                        while((txRun===1'b1)||(rxRun===1'b1)||(rxStartBit===1'b1)) begin
131
                                @(posedge clk);
132
                        end
133
                        @(posedge clk);
134
                end
135
                $display("Two cycle pause in communication detected, stop simulation");
136 3 acapola
                #200
137
                $finish;
138
        end
139 4 acapola
        //T=0 tpdu stimuli
140
        initial begin
141
                receiveAndCheckByte(8'h3B);
142
                receiveAndCheckByte(8'h00);
143
                //sendBytes("000C000001");//would be handy, TODO
144
                sendByte(8'h00);
145
                sendByte(8'h0C);
146
                sendByte(8'h00);
147
                sendByte(8'h00);
148
                sendByte(8'h01);
149
                receiveAndCheckByte(8'h0C);
150
                //sendBytes("55");
151
                sendByte(8'h55);
152
                receiveAndCheckByte(8'h90);
153
                receiveAndCheckByte(8'h00);
154
        end
155 3 acapola
        initial begin
156
                // timeout
157 4 acapola
                #100000;
158 3 acapola
      tbErrorCnt=tbErrorCnt+1;
159
      $display("ERROR: timeout expired");
160
      #10;
161
                $finish;
162
        end
163
        always
164
                #(CLK_PERIOD/2) clk =  ! clk;
165
endmodule
166
 

powered by: WebSVN 2.1.0

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