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 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: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
 
44
 
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
                .dataOut(dataOut),
53
                .nCsDataOut(nCsDataOut),
54
                .statusOut(statusOut),
55
                .nCsStatusOut(nCsStatusOut),
56
                .serialIn(isoSio),
57
                .serialOut(serialOut),
58 4 acapola
                .comClk(cardIsoClk)
59 3 acapola
        );
60
 
61 4 acapola
reg sendAtr;
62
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
63
 
64
reg [7:0] buffer[256+5:0];
65
localparam CLA_I= 8*4;
66
localparam INS_I= 8*3;
67
localparam P1_I = 8*2;
68
localparam P2_I = 8*1;
69
localparam P3_I = 0;
70
reg [CLA_I+7:0] tpduHeader;
71
 
72
wire COM_statusOut=statusOut;
73
wire COM_clk=isoClk;
74
integer COM_errorCnt;
75
 
76 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
77
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
78
 
79 4 acapola
`include "ComDriverTasks.v"
80
 
81 3 acapola
assign isoSio = isTx ? serialOut : 1'bz;
82
 
83 4 acapola
 
84
/*T=0 card model
85
 
86
ATR:
87
        3B 00
88
 
89
Implemented commands:
90
        write buffer:
91
                tpdu: 00 0C 00 00 LC data
92
                sw:   90 00
93
        read buffer:
94
                tpdu: 00 0A 00 00 LE
95
                response: data
96
                sw:   90 00
97
        any other:
98
                sw:   69 86
99
*/
100
task sendAckByte;
101
        sendByte(tpduHeader[INS_I+7:INS_I]);
102
endtask
103
 
104
task writeBufferCmd;
105
integer i;
106
begin
107
        sendAckByte;
108
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
109
                receiveByte(buffer[i]);
110
        end
111
        sendWord(16'h9000);
112
end
113
endtask
114
 
115
task readBufferCmd;
116
integer i;
117
integer le;
118
begin
119
        sendAckByte;
120
        le=tpduHeader[P3_I+7:P3_I];
121
        if(0==le) le=256;
122
        for(i=0;i<le;i=i+1) begin
123
                sendByte(buffer[i]);
124
        end
125
        sendWord(16'h9000);
126
end
127
endtask
128
 
129
integer i;
130 3 acapola
always @(posedge isoClk, negedge isoReset) begin
131
        if(~isoReset) begin
132
                nWeDataIn<=1'b1;
133
                nCsDataOut<=1'b1;
134
                nCsStatusOut<=1'b1;
135
                tsCnt<=9'b0;
136
                sendAtr<=1'b1;
137
        end else if(tsCnt!=9'd400) begin
138
                tsCnt <= tsCnt + 1'b1;
139
        end else if(sendAtr) begin
140
                sendAtr<=1'b0;
141 4 acapola
                sendByte(8'h3B);
142
                sendByte(8'h00);
143
                waitEndOfTx;
144 3 acapola
        end else begin
145 4 acapola
                //get tpdu
146
                for(i=0;i<5;i=i+1)
147
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
148
                //dispatch
149
                case(tpduHeader[7+CLA_I:P2_I])
150
                                32'h000C0000: writeBufferCmd;
151
                                32'h000A0000: readBufferCmd;
152
                                default: sendWord(16'h6986);
153
                endcase
154 3 acapola
        end
155
end
156
 
157
endmodule
158
 

powered by: WebSVN 2.1.0

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