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 17

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-18 15:23:07 +0100 (Fri, 18 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 17 $
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 15 acapola
        wire [7:0] uart_dataOut;
50 3 acapola
        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 15 acapola
 
56
reg useIndirectConventionConfig;//can be changed by commands
57
reg useIndirectConvention;
58
 
59
wire stopBit2=1'b1;//0: 1 stop bit, 1: 2 stop bits 
60
wire msbFirst = useIndirectConvention;//if 1, bits order is: startBit, b7, b6, b5...b0, parity
61
wire oddParity = 1'b0;//if 1, parity bit is such that data+parity have an odd number of 1
62
wire sioHighValue = ~useIndirectConvention;//apply only to data bits
63
 
64
wire [7:0] uart_dataIn = sioHighValue ? dataIn : ~dataIn;
65
wire [7:0] dataOut = sioHighValue ? uart_dataOut : ~uart_dataOut;
66
 
67 4 acapola
        HalfDuplexUartIf uartIf (
68 3 acapola
                .nReset(isoReset),
69
                .clk(isoClk),
70
                .clkPerCycle(clkPerCycle),
71 15 acapola
                .dataIn(uart_dataIn),
72 3 acapola
                .nWeDataIn(nWeDataIn),
73 7 acapola
                .clocksPerBit(cyclesPerEtu),
74 15 acapola
                .stopBit2(stopBit2),
75
                .oddParity(oddParity),
76
      .msbFirst(msbFirst),
77
           .dataOut(uart_dataOut),
78 3 acapola
                .nCsDataOut(nCsDataOut),
79
                .statusOut(statusOut),
80
                .nCsStatusOut(nCsStatusOut),
81
                .serialIn(isoSio),
82
                .serialOut(serialOut),
83 4 acapola
                .comClk(cardIsoClk)
84 3 acapola
        );
85
 
86 4 acapola
reg sendAtr;
87
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
88
 
89
reg [7:0] buffer[256+5:0];
90
localparam CLA_I= 8*4;
91
localparam INS_I= 8*3;
92
localparam P1_I = 8*2;
93
localparam P2_I = 8*1;
94
localparam P3_I = 0;
95
reg [CLA_I+7:0] tpduHeader;
96
 
97
wire COM_statusOut=statusOut;
98
wire COM_clk=isoClk;
99
integer COM_errorCnt;
100
 
101 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
102
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
103
 
104 4 acapola
`include "ComDriverTasks.v"
105
 
106 3 acapola
assign isoSio = isTx ? serialOut : 1'bz;
107
 
108 4 acapola
 
109
/*T=0 card model
110
 
111
ATR:
112 13 acapola
        3B/3F 94 97 80 1F 42 BA BE BA BE
113 14 acapola
        3B 9E 96 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 0D
114 4 acapola
 
115 14 acapola
 
116 4 acapola
Implemented commands:
117
        write buffer:
118
                tpdu: 00 0C 00 00 LC data
119
                sw:   90 00
120
        read buffer:
121
                tpdu: 00 0A 00 00 LE
122
                response: data
123
                sw:   90 00
124 15 acapola
        toggle communication convention (take effect at next reset):
125
                tpdu 00 FC 00 00 00
126
                sw:     90 00
127 4 acapola
        any other:
128
                sw:   69 86
129
*/
130
task sendAckByte;
131
        sendByte(tpduHeader[INS_I+7:INS_I]);
132
endtask
133
 
134
task writeBufferCmd;
135
integer i;
136
begin
137
        sendAckByte;
138
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
139
                receiveByte(buffer[i]);
140
        end
141 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
142 4 acapola
end
143
endtask
144
 
145
task readBufferCmd;
146
integer i;
147
integer le;
148
begin
149
        sendAckByte;
150
        le=tpduHeader[P3_I+7:P3_I];
151
        if(0==le) le=256;
152
        for(i=0;i<le;i=i+1) begin
153
                sendByte(buffer[i]);
154
        end
155 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
156 4 acapola
end
157
endtask
158
 
159 15 acapola
task toggleConventionCmd;
160 4 acapola
integer i;
161 15 acapola
begin
162
        useIndirectConventionConfig=~useIndirectConventionConfig;
163
        sendHexBytes("9000");//sendWord(16'h9000);
164
end
165
endtask
166
 
167
//stuff which can be changed by command and affect ATR
168
always @(posedge isoVdd) begin
169 17 acapola
        useIndirectConventionConfig<=1'b0;
170 15 acapola
end
171
 
172
integer i;
173 3 acapola
always @(posedge isoClk, negedge isoReset) begin
174
        if(~isoReset) begin
175
                nWeDataIn<=1'b1;
176
                nCsDataOut<=1'b1;
177
                nCsStatusOut<=1'b1;
178
                tsCnt<=9'b0;
179
                sendAtr<=1'b1;
180 7 acapola
                cyclesPerEtu <= 13'd372-1'b1;
181 15 acapola
                useIndirectConvention<=useIndirectConventionConfig;
182 3 acapola
        end else if(tsCnt!=9'd400) begin
183
                tsCnt <= tsCnt + 1'b1;
184
        end else if(sendAtr) begin
185
                sendAtr<=1'b0;
186 13 acapola
                //sendHexBytes("3B00");
187 15 acapola
                if(useIndirectConvention)
188
                        sendHexBytes("3F");
189
                else
190
                        sendHexBytes("3B");
191 14 acapola
                //sendHexBytes("9497801F42BABEBABE");
192
                //sendHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 0D");
193
                sendHexBytes("9E 97 80 1F C7 80 31 E0 73 FE 21 1B 66 D0 00 28 24 01 00 ");
194 4 acapola
                waitEndOfTx;
195 3 acapola
        end else begin
196 11 acapola
                //get CLA
197
                receiveByte(tpduHeader[CLA_I+:8]);
198
 
199
                //get INS~P2 or PPS
200
                for(i=1;i<4;i=i+1)
201 4 acapola
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
202 11 acapola
 
203
                if(8'hFF==tpduHeader[CLA_I+:8]) begin
204
                        //support only PPS8 for the time being
205 12 acapola
                        if(32'hFF109778==tpduHeader[7+CLA_I:P2_I]) begin
206
                                sendHexBytes("FF109778");
207 11 acapola
                                waitEndOfTx;
208
                                cyclesPerEtu <= 13'd8-1'b1;
209
                        end
210
                end else begin
211
                        //tpdu: get P3
212
                        receiveByte(tpduHeader[P3_I+:8]);
213
                        //dispatch
214
                        case(tpduHeader[7+CLA_I:P2_I])
215
                                        32'h000C0000: writeBufferCmd;
216
                                        32'h000A0000: readBufferCmd;
217 15 acapola
                                        32'h00FC0000: toggleConventionCmd;
218
                                        default: sendHexBytes("6986");
219 11 acapola
                        endcase
220
                end
221 3 acapola
        end
222
end
223
 
224
endmodule
225 11 acapola
`default_nettype wire
226 3 acapola
 

powered by: WebSVN 2.1.0

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