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 14

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-10 16:40:57 +0100 (Thu, 10 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 14 $
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 14 acapola
        3B 9E 96 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 0D
99 4 acapola
 
100 14 acapola
 
101 4 acapola
Implemented commands:
102
        write buffer:
103
                tpdu: 00 0C 00 00 LC data
104
                sw:   90 00
105
        read buffer:
106
                tpdu: 00 0A 00 00 LE
107
                response: data
108
                sw:   90 00
109
        any other:
110
                sw:   69 86
111
*/
112
task sendAckByte;
113
        sendByte(tpduHeader[INS_I+7:INS_I]);
114
endtask
115
 
116
task writeBufferCmd;
117
integer i;
118
begin
119
        sendAckByte;
120
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
121
                receiveByte(buffer[i]);
122
        end
123 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
124 4 acapola
end
125
endtask
126
 
127
task readBufferCmd;
128
integer i;
129
integer le;
130
begin
131
        sendAckByte;
132
        le=tpduHeader[P3_I+7:P3_I];
133
        if(0==le) le=256;
134
        for(i=0;i<le;i=i+1) begin
135
                sendByte(buffer[i]);
136
        end
137 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
138 4 acapola
end
139
endtask
140
 
141
integer i;
142 3 acapola
always @(posedge isoClk, negedge isoReset) begin
143
        if(~isoReset) begin
144
                nWeDataIn<=1'b1;
145
                nCsDataOut<=1'b1;
146
                nCsStatusOut<=1'b1;
147
                tsCnt<=9'b0;
148
                sendAtr<=1'b1;
149 7 acapola
                cyclesPerEtu <= 13'd372-1'b1;
150 3 acapola
        end else if(tsCnt!=9'd400) begin
151
                tsCnt <= tsCnt + 1'b1;
152
        end else if(sendAtr) begin
153
                sendAtr<=1'b0;
154 13 acapola
                //sendHexBytes("3B00");
155
                sendHexBytes("3B");
156
                //sendHexBytes("3F");
157 14 acapola
                //sendHexBytes("9497801F42BABEBABE");
158
                //sendHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 0D");
159
                sendHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 ");
160 4 acapola
                waitEndOfTx;
161 3 acapola
        end else begin
162 11 acapola
                //get CLA
163
                receiveByte(tpduHeader[CLA_I+:8]);
164
 
165
                //get INS~P2 or PPS
166
                for(i=1;i<4;i=i+1)
167 4 acapola
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
168 11 acapola
 
169
                if(8'hFF==tpduHeader[CLA_I+:8]) begin
170
                        //support only PPS8 for the time being
171 12 acapola
                        if(32'hFF109778==tpduHeader[7+CLA_I:P2_I]) begin
172
                                sendHexBytes("FF109778");
173 11 acapola
                                waitEndOfTx;
174
                                cyclesPerEtu <= 13'd8-1'b1;
175
                        end
176
                end else begin
177
                        //tpdu: get P3
178
                        receiveByte(tpduHeader[P3_I+:8]);
179
                        //dispatch
180
                        case(tpduHeader[7+CLA_I:P2_I])
181
                                        32'h000C0000: writeBufferCmd;
182
                                        32'h000A0000: readBufferCmd;
183
                                        default: sendHexBytes("6986");//sendWord(16'h6986);
184
                        endcase
185
                end
186 3 acapola
        end
187
end
188
 
189
endmodule
190 11 acapola
`default_nettype wire
191 3 acapola
 

powered by: WebSVN 2.1.0

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