OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [test/] [DummyCard.v] - Blame information for rev 13

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:22:43 01/10/2011
4
 
5
$LastChangedDate: 2011-02-09 13:34:14 +0100 (Wed, 09 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 13 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/test/DummyCard.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 4 acapola
`default_nettype none
33 3 acapola
 
34
module DummyCard(
35 4 acapola
        input wire isoReset,
36
        input wire isoClk,
37
        input wire isoVdd,
38
        inout wire isoSio
39 3 acapola
        );
40
 
41
        // Inputs
42
        wire [0:0] clkPerCycle=0;
43
        reg [7:0] dataIn;
44
        reg nWeDataIn;
45
        reg nCsDataOut;
46
        reg nCsStatusOut;
47
 
48
        // Outputs
49
        wire [7:0] dataOut;
50
        wire [7:0] statusOut;
51
        wire serialOut;
52 7 acapola
        reg [12:0] cyclesPerEtu;
53 3 acapola
 
54 4 acapola
        wire cardIsoClk;//card use its own generated clock (like true UARTs)
55
        HalfDuplexUartIf uartIf (
56 3 acapola
                .nReset(isoReset),
57
                .clk(isoClk),
58
                .clkPerCycle(clkPerCycle),
59
                .dataIn(dataIn),
60
                .nWeDataIn(nWeDataIn),
61 7 acapola
                .clocksPerBit(cyclesPerEtu),
62 3 acapola
                .dataOut(dataOut),
63
                .nCsDataOut(nCsDataOut),
64
                .statusOut(statusOut),
65
                .nCsStatusOut(nCsStatusOut),
66
                .serialIn(isoSio),
67
                .serialOut(serialOut),
68 4 acapola
                .comClk(cardIsoClk)
69 3 acapola
        );
70
 
71 4 acapola
reg sendAtr;
72
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
73
 
74
reg [7:0] buffer[256+5:0];
75
localparam CLA_I= 8*4;
76
localparam INS_I= 8*3;
77
localparam P1_I = 8*2;
78
localparam P2_I = 8*1;
79
localparam P3_I = 0;
80
reg [CLA_I+7:0] tpduHeader;
81
 
82
wire COM_statusOut=statusOut;
83
wire COM_clk=isoClk;
84
integer COM_errorCnt;
85
 
86 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
87
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
88
 
89 4 acapola
`include "ComDriverTasks.v"
90
 
91 3 acapola
assign isoSio = isTx ? serialOut : 1'bz;
92
 
93 4 acapola
 
94
/*T=0 card model
95
 
96
ATR:
97 13 acapola
        3B/3F 94 97 80 1F 42 BA BE BA BE
98 4 acapola
 
99
Implemented commands:
100
        write buffer:
101
                tpdu: 00 0C 00 00 LC data
102
                sw:   90 00
103
        read buffer:
104
                tpdu: 00 0A 00 00 LE
105
                response: data
106
                sw:   90 00
107
        any other:
108
                sw:   69 86
109
*/
110
task sendAckByte;
111
        sendByte(tpduHeader[INS_I+7:INS_I]);
112
endtask
113
 
114
task writeBufferCmd;
115
integer i;
116
begin
117
        sendAckByte;
118
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
119
                receiveByte(buffer[i]);
120
        end
121 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
122 4 acapola
end
123
endtask
124
 
125
task readBufferCmd;
126
integer i;
127
integer le;
128
begin
129
        sendAckByte;
130
        le=tpduHeader[P3_I+7:P3_I];
131
        if(0==le) le=256;
132
        for(i=0;i<le;i=i+1) begin
133
                sendByte(buffer[i]);
134
        end
135 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
136 4 acapola
end
137
endtask
138
 
139
integer i;
140 3 acapola
always @(posedge isoClk, negedge isoReset) begin
141
        if(~isoReset) begin
142
                nWeDataIn<=1'b1;
143
                nCsDataOut<=1'b1;
144
                nCsStatusOut<=1'b1;
145
                tsCnt<=9'b0;
146
                sendAtr<=1'b1;
147 7 acapola
                cyclesPerEtu <= 13'd372-1'b1;
148 3 acapola
        end else if(tsCnt!=9'd400) begin
149
                tsCnt <= tsCnt + 1'b1;
150
        end else if(sendAtr) begin
151
                sendAtr<=1'b0;
152 13 acapola
                //sendHexBytes("3B00");
153
                sendHexBytes("3B");
154
                //sendHexBytes("3F");
155
                sendHexBytes("9497801F42BABEBABE");
156 4 acapola
                waitEndOfTx;
157 3 acapola
        end else begin
158 11 acapola
                //get CLA
159
                receiveByte(tpduHeader[CLA_I+:8]);
160
 
161
                //get INS~P2 or PPS
162
                for(i=1;i<4;i=i+1)
163 4 acapola
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
164 11 acapola
 
165
                if(8'hFF==tpduHeader[CLA_I+:8]) begin
166
                        //support only PPS8 for the time being
167 12 acapola
                        if(32'hFF109778==tpduHeader[7+CLA_I:P2_I]) begin
168
                                sendHexBytes("FF109778");
169 11 acapola
                                waitEndOfTx;
170
                                cyclesPerEtu <= 13'd8-1'b1;
171
                        end
172
                end else begin
173
                        //tpdu: get P3
174
                        receiveByte(tpduHeader[P3_I+:8]);
175
                        //dispatch
176
                        case(tpduHeader[7+CLA_I:P2_I])
177
                                        32'h000C0000: writeBufferCmd;
178
                                        32'h000A0000: readBufferCmd;
179
                                        default: sendHexBytes("6986");//sendWord(16'h6986);
180
                        endcase
181
                end
182 3 acapola
        end
183
end
184
 
185
endmodule
186 11 acapola
`default_nettype wire
187 3 acapola
 

powered by: WebSVN 2.1.0

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