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] - Diff between revs 4 and 7

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 7
`timescale 1ns / 1ps
`timescale 1ns / 1ps
`default_nettype none
`default_nettype none
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Company: 
// Company: 
// Engineer:
// Engineer:
//
//
// Create Date:   22:22:43 01/10/2011
// Create Date:   22:22:43 01/10/2011
// Design Name:   HalfDuplexUartIf
// Design Name:   HalfDuplexUartIf
// Module Name:   dummyCard.v
// Module Name:   dummyCard.v
// Project Name:  Uart
// Project Name:  Uart
// Target Device:  
// Target Device:  
// Tool versions:  
// Tool versions:  
// Description: 
// Description: 
//
//
// Verilog Test Fixture created by ISE for module: HalfDuplexUartIf
// Verilog Test Fixture created by ISE for module: HalfDuplexUartIf
//
//
// Dependencies:
// Dependencies:
// 
// 
// Revision:
// Revision:
// Revision 0.01 - File Created
// Revision 0.01 - File Created
// Additional Comments:
// Additional Comments:
// 
// 
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
 
 
module DummyCard(
module DummyCard(
        input wire isoReset,
        input wire isoReset,
        input wire isoClk,
        input wire isoClk,
        input wire isoVdd,
        input wire isoVdd,
        inout wire isoSio
        inout wire isoSio
        );
        );
 
 
        // Inputs
        // Inputs
        wire [0:0] clkPerCycle=0;
        wire [0:0] clkPerCycle=0;
        reg [7:0] dataIn;
        reg [7:0] dataIn;
        reg nWeDataIn;
        reg nWeDataIn;
        reg nCsDataOut;
        reg nCsDataOut;
        reg nCsStatusOut;
        reg nCsStatusOut;
 
 
        // Outputs
        // Outputs
        wire [7:0] dataOut;
        wire [7:0] dataOut;
        wire [7:0] statusOut;
        wire [7:0] statusOut;
        wire serialOut;
        wire serialOut;
 
        reg [12:0] cyclesPerEtu;
 
 
        wire cardIsoClk;//card use its own generated clock (like true UARTs)
        wire cardIsoClk;//card use its own generated clock (like true UARTs)
        HalfDuplexUartIf uartIf (
        HalfDuplexUartIf uartIf (
                .nReset(isoReset),
                .nReset(isoReset),
                .clk(isoClk),
                .clk(isoClk),
                .clkPerCycle(clkPerCycle),
                .clkPerCycle(clkPerCycle),
                .dataIn(dataIn),
                .dataIn(dataIn),
                .nWeDataIn(nWeDataIn),
                .nWeDataIn(nWeDataIn),
 
                .clocksPerBit(cyclesPerEtu),
                .dataOut(dataOut),
                .dataOut(dataOut),
                .nCsDataOut(nCsDataOut),
                .nCsDataOut(nCsDataOut),
                .statusOut(statusOut),
                .statusOut(statusOut),
                .nCsStatusOut(nCsStatusOut),
                .nCsStatusOut(nCsStatusOut),
                .serialIn(isoSio),
                .serialIn(isoSio),
                .serialOut(serialOut),
                .serialOut(serialOut),
                .comClk(cardIsoClk)
                .comClk(cardIsoClk)
        );
        );
 
 
reg sendAtr;
reg sendAtr;
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
reg [8:0] tsCnt;//counter to start ATR 400 cycles after reset release
 
 
reg [7:0] buffer[256+5:0];
reg [7:0] buffer[256+5:0];
localparam CLA_I= 8*4;
localparam CLA_I= 8*4;
localparam INS_I= 8*3;
localparam INS_I= 8*3;
localparam P1_I = 8*2;
localparam P1_I = 8*2;
localparam P2_I = 8*1;
localparam P2_I = 8*1;
localparam P3_I = 0;
localparam P3_I = 0;
reg [CLA_I+7:0] tpduHeader;
reg [CLA_I+7:0] tpduHeader;
 
 
wire COM_statusOut=statusOut;
wire COM_statusOut=statusOut;
wire COM_clk=isoClk;
wire COM_clk=isoClk;
integer COM_errorCnt;
integer COM_errorCnt;
 
 
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
 
 
`include "ComDriverTasks.v"
`include "ComDriverTasks.v"
 
 
assign isoSio = isTx ? serialOut : 1'bz;
assign isoSio = isTx ? serialOut : 1'bz;
 
 
 
 
/*T=0 card model
/*T=0 card model
 
 
ATR:
ATR:
        3B 00
        3B 00
 
 
Implemented commands:
Implemented commands:
        write buffer:
        write buffer:
                tpdu: 00 0C 00 00 LC data
                tpdu: 00 0C 00 00 LC data
                sw:   90 00
                sw:   90 00
        read buffer:
        read buffer:
                tpdu: 00 0A 00 00 LE
                tpdu: 00 0A 00 00 LE
                response: data
                response: data
                sw:   90 00
                sw:   90 00
        any other:
        any other:
                sw:   69 86
                sw:   69 86
*/
*/
task sendAckByte;
task sendAckByte;
        sendByte(tpduHeader[INS_I+7:INS_I]);
        sendByte(tpduHeader[INS_I+7:INS_I]);
endtask
endtask
 
 
task writeBufferCmd;
task writeBufferCmd;
integer i;
integer i;
begin
begin
        sendAckByte;
        sendAckByte;
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
        for(i=0;i<tpduHeader[P3_I+7:P3_I];i=i+1) begin
                receiveByte(buffer[i]);
                receiveByte(buffer[i]);
        end
        end
        sendWord(16'h9000);
        sendWord(16'h9000);
end
end
endtask
endtask
 
 
task readBufferCmd;
task readBufferCmd;
integer i;
integer i;
integer le;
integer le;
begin
begin
        sendAckByte;
        sendAckByte;
        le=tpduHeader[P3_I+7:P3_I];
        le=tpduHeader[P3_I+7:P3_I];
        if(0==le) le=256;
        if(0==le) le=256;
        for(i=0;i<le;i=i+1) begin
        for(i=0;i<le;i=i+1) begin
                sendByte(buffer[i]);
                sendByte(buffer[i]);
        end
        end
        sendWord(16'h9000);
        sendWord(16'h9000);
end
end
endtask
endtask
 
 
integer i;
integer i;
always @(posedge isoClk, negedge isoReset) begin
always @(posedge isoClk, negedge isoReset) begin
        if(~isoReset) begin
        if(~isoReset) begin
                nWeDataIn<=1'b1;
                nWeDataIn<=1'b1;
                nCsDataOut<=1'b1;
                nCsDataOut<=1'b1;
                nCsStatusOut<=1'b1;
                nCsStatusOut<=1'b1;
                tsCnt<=9'b0;
                tsCnt<=9'b0;
                sendAtr<=1'b1;
                sendAtr<=1'b1;
 
                cyclesPerEtu <= 13'd372-1'b1;
        end else if(tsCnt!=9'd400) begin
        end else if(tsCnt!=9'd400) begin
                tsCnt <= tsCnt + 1'b1;
                tsCnt <= tsCnt + 1'b1;
        end else if(sendAtr) begin
        end else if(sendAtr) begin
                sendAtr<=1'b0;
                sendAtr<=1'b0;
                sendByte(8'h3B);
                sendByte(8'h3B);
                sendByte(8'h00);
                sendByte(8'h00);
                waitEndOfTx;
                waitEndOfTx;
        end else begin
        end else begin
                //get tpdu
                //get tpdu
                for(i=0;i<5;i=i+1)
                for(i=0;i<5;i=i+1)
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
                        receiveByte(tpduHeader[(CLA_I-(i*8))+:8]);
                //dispatch
                //dispatch
                case(tpduHeader[7+CLA_I:P2_I])
                case(tpduHeader[7+CLA_I:P2_I])
                                32'h000C0000: writeBufferCmd;
                                32'h000C0000: writeBufferCmd;
                                32'h000A0000: readBufferCmd;
                                32'h000A0000: readBufferCmd;
                                default: sendWord(16'h6986);
                                default: sendWord(16'h6986);
                endcase
                endcase
        end
        end
end
end
 
 
endmodule
endmodule
 
 
 
 

powered by: WebSVN 2.1.0

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