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 10

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:22:43 01/10/2011
8
// Design Name:   HalfDuplexUartIf
9
// Module Name:   dummyCard.v
10
// Project Name:  Uart
11
// Target Device:  
12
// Tool versions:  
13
// Description: 
14
//
15
// Verilog Test Fixture created by ISE for module: HalfDuplexUartIf
16
//
17
// Dependencies:
18
// 
19
// Revision:
20
// Revision 0.01 - File Created
21
// Additional Comments:
22
// 
23
////////////////////////////////////////////////////////////////////////////////
24
 
25
module DummyCard(
26 4 acapola
        input wire isoReset,
27
        input wire isoClk,
28
        input wire isoVdd,
29
        inout wire isoSio
30 3 acapola
        );
31
 
32
        // Inputs
33
        wire [0:0] clkPerCycle=0;
34
        reg [7:0] dataIn;
35
        reg nWeDataIn;
36
        reg nCsDataOut;
37
        reg nCsStatusOut;
38
 
39
        // Outputs
40
        wire [7:0] dataOut;
41
        wire [7:0] statusOut;
42
        wire serialOut;
43 7 acapola
        reg [12:0] cyclesPerEtu;
44 3 acapola
 
45 4 acapola
        wire cardIsoClk;//card use its own generated clock (like true UARTs)
46
        HalfDuplexUartIf uartIf (
47 3 acapola
                .nReset(isoReset),
48
                .clk(isoClk),
49
                .clkPerCycle(clkPerCycle),
50
                .dataIn(dataIn),
51
                .nWeDataIn(nWeDataIn),
52 7 acapola
                .clocksPerBit(cyclesPerEtu),
53 3 acapola
                .dataOut(dataOut),
54
                .nCsDataOut(nCsDataOut),
55
                .statusOut(statusOut),
56
                .nCsStatusOut(nCsStatusOut),
57
                .serialIn(isoSio),
58
                .serialOut(serialOut),
59 4 acapola
                .comClk(cardIsoClk)
60 3 acapola
        );
61
 
62 4 acapola
reg sendAtr;
63
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
64
 
65
reg [7:0] buffer[256+5:0];
66
localparam CLA_I= 8*4;
67
localparam INS_I= 8*3;
68
localparam P1_I = 8*2;
69
localparam P2_I = 8*1;
70
localparam P3_I = 0;
71
reg [CLA_I+7:0] tpduHeader;
72
 
73
wire COM_statusOut=statusOut;
74
wire COM_clk=isoClk;
75
integer COM_errorCnt;
76
 
77 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
78
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
79
 
80 4 acapola
`include "ComDriverTasks.v"
81
 
82 3 acapola
assign isoSio = isTx ? serialOut : 1'bz;
83
 
84 4 acapola
 
85
/*T=0 card model
86
 
87
ATR:
88
        3B 00
89
 
90
Implemented commands:
91
        write buffer:
92
                tpdu: 00 0C 00 00 LC data
93
                sw:   90 00
94
        read buffer:
95
                tpdu: 00 0A 00 00 LE
96
                response: data
97
                sw:   90 00
98
        any other:
99
                sw:   69 86
100
*/
101
task sendAckByte;
102
        sendByte(tpduHeader[INS_I+7:INS_I]);
103
endtask
104
 
105
task writeBufferCmd;
106
integer i;
107
begin
108
        sendAckByte;
109
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
110
                receiveByte(buffer[i]);
111
        end
112 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
113 4 acapola
end
114
endtask
115
 
116
task readBufferCmd;
117
integer i;
118
integer le;
119
begin
120
        sendAckByte;
121
        le=tpduHeader[P3_I+7:P3_I];
122
        if(0==le) le=256;
123
        for(i=0;i<le;i=i+1) begin
124
                sendByte(buffer[i]);
125
        end
126 9 acapola
        sendHexBytes("9000");//sendWord(16'h9000);
127 4 acapola
end
128
endtask
129
 
130
integer i;
131 3 acapola
always @(posedge isoClk, negedge isoReset) begin
132
        if(~isoReset) begin
133
                nWeDataIn<=1'b1;
134
                nCsDataOut<=1'b1;
135
                nCsStatusOut<=1'b1;
136
                tsCnt<=9'b0;
137
                sendAtr<=1'b1;
138 7 acapola
                cyclesPerEtu <= 13'd372-1'b1;
139 3 acapola
        end else if(tsCnt!=9'd400) begin
140
                tsCnt <= tsCnt + 1'b1;
141
        end else if(sendAtr) begin
142
                sendAtr<=1'b0;
143 9 acapola
                sendHexBytes("3B00");
144 4 acapola
                waitEndOfTx;
145 3 acapola
        end else begin
146 4 acapola
                //get tpdu
147
                for(i=0;i<5;i=i+1)
148
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
149
                //dispatch
150
                case(tpduHeader[7+CLA_I:P2_I])
151
                                32'h000C0000: writeBufferCmd;
152
                                32'h000A0000: readBufferCmd;
153 9 acapola
                                default: sendHexBytes("6986");//sendWord(16'h6986);
154 4 acapola
                endcase
155 3 acapola
        end
156
end
157
 
158
endmodule
159
 

powered by: WebSVN 2.1.0

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