OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [sources/] [Iso7816_3_Master.v] - Diff between revs 4 and 5

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

Rev 4 Rev 5
`timescale 1ns / 1ps
`timescale 1ns / 1ps
`default_nettype none
`default_nettype none
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Company: 
// Engineer: 
// Engineer: 
// 
// 
// Create Date:    17:16:40 01/09/2011 
// Create Date:    17:16:40 01/09/2011 
// Design Name: 
// Design Name: 
// Module Name:    Iso7816_3_Master 
// Module Name:    Iso7816_3_Master 
// Project Name: 
// Project Name: 
// Target Devices: 
// Target Devices: 
// Tool versions: 
// Tool versions: 
// Description: 
// Description: 
//
//
// Dependencies: 
// Dependencies: 
//
//
// Revision: 
// Revision: 
// Revision 0.01 - File Created
// Revision 0.01 - File Created
// Additional Comments: 
// Additional Comments: 
//
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
module Iso7816_3_Master(
module Iso7816_3_Master(
    input wire nReset,
    input wire nReset,
    input wire clk,
    input wire clk,
         input wire [15:0] clkPerCycle,//not supported yet
         input wire [15:0] clkPerCycle,//not supported yet
         input wire startActivation,//Starts activation sequence
         input wire startActivation,//Starts activation sequence
         input wire startDeactivation,//Starts deactivation sequence
         input wire startDeactivation,//Starts deactivation sequence
    input wire [7:0] dataIn,
    input wire [7:0] dataIn,
    input wire nWeDataIn,
    input wire nWeDataIn,
         input wire [12:0] cyclePerEtu,
         input wire [12:0] cyclePerEtu,
    output wire [7:0] dataOut,
    output wire [7:0] dataOut,
    input wire nCsDataOut,
    input wire nCsDataOut,
    output wire [7:0] statusOut,
    output wire [7:0] statusOut,
    input wire nCsStatusOut,
    input wire nCsStatusOut,
         output reg isActivated,//set to high by activation sequence, set to low by deactivation sequence
         output reg isActivated,//set to high by activation sequence, set to low by deactivation sequence
         output wire useIndirectConvention,
         output wire useIndirectConvention,
         output wire tsError,//high if TS character is wrong
         output wire tsError,//high if TS character is wrong
         output wire tsReceived,
         output wire tsReceived,
         output wire atrIsEarly,//high if TS received before 400 cycles after reset release
         output wire atrIsEarly,//high if TS received before 400 cycles after reset release
         output wire atrIsLate,//high if TS is still not received after 40000 cycles after reset release
         output wire atrIsLate,//high if TS is still not received after 40000 cycles after reset release
         //ISO7816 signals
         //ISO7816 signals
    inout wire isoSio,
    inout wire isoSio,
         output wire isoClk,
         output wire isoClk,
         output reg isoReset,
         output reg isoReset,
         output reg isoVdd
         output reg isoVdd
    );
    );
 
 
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;
 
 
wire serialOut;
wire serialOut;
assign isoSio = isTx ? serialOut : 1'bz;
assign isoSio = isTx ? serialOut : 1'bz;
pullup(isoSio);
pullup(isoSio);
wire comClk;
wire comClk;
 
 
        HalfDuplexUartIf uart (
        HalfDuplexUartIf uart (
                .nReset(nReset),
                .nReset(nReset),
                .clk(clk),
                .clk(clk),
                .clkPerCycle(1'b0),
                .clkPerCycle(1'b0),
                .dataIn(dataIn),
                .dataIn(dataIn),
                .nWeDataIn(nWeDataIn),
                .nWeDataIn(nWeDataIn),
                .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(comClk)
                .comClk(comClk)
        );
        );
 
 
        reg isoClkEn;
        reg isoClkEn;
        assign isoClk = isoClkEn ? comClk : 1'b0;
        assign isoClk = isoClkEn ? comClk : 1'b0;
 
 
        reg [16:0] resetCnt;
reg [16:0] resetCnt;
        reg waitTs;
reg waitTs;
        assign tsReceived = ~waitTs;
assign tsReceived = ~waitTs;
        reg [7:0] ts;
reg [7:0] ts;
        assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
        assign atrIsLate = resetCnt>(16'h100+16'd40000);
assign atrIsLate = resetCnt>(16'h100+16'd40000);
        assign useIndirectConvention = ~waitTs & (ts==8'h3F);
assign useIndirectConvention = ~waitTs & (ts==8'h3F);
        assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
        always @(posedge comClk, negedge nReset) begin
always @(posedge comClk, negedge nReset) begin
                if(~nReset) begin
        if(~nReset) begin
                        isoClkEn <= 1'b0;
                isoClkEn <= 1'b0;
                        resetCnt<=16'b0;
                resetCnt<=16'b0;
                        waitTs<=1'b1;
                waitTs<=1'b1;
                        isoReset <= 1'b0;
                isoReset <= 1'b0;
                        isoVdd <= 1'b0;
                isoVdd <= 1'b0;
                        isActivated <= 1'b0;
                isActivated <= 1'b0;
                end else if(isActivated) begin
        end else if(isActivated) begin
                        if(waitTs) begin
                if(waitTs) begin
                                if(statusOut[0]) begin
                        if(statusOut[0]) begin
                                        waitTs<=1'b0;
                                waitTs<=1'b0;
                                        ts<=dataOut;
                                ts<=dataOut;
                                end
                        end
                                resetCnt<=resetCnt+1;
                        resetCnt<=resetCnt+1;
                        end
                end
                        if(startDeactivation) begin
                if(startDeactivation) begin
                                isoVdd <= 1'b0;
                        isoVdd <= 1'b0;
                                isoClkEn <= 1'b0;
                        isoClkEn <= 1'b0;
                                isoReset <= 1'b0;
                        isoReset <= 1'b0;
                                resetCnt<=16'b0;
                        resetCnt<=16'b0;
                                isActivated <= 1'b0;
                        isActivated <= 1'b0;
                        end
                end
                end else begin
        end else begin
                        if(startActivation) begin
                if(startActivation) begin
                                waitTs <= 1'b1;
                        waitTs <= 1'b1;
                                isoVdd <= 1'b1;
                        isoVdd <= 1'b1;
                                isoClkEn <= 1'b1;
                        isoClkEn <= 1'b1;
                                if(16'h100 == resetCnt) begin
                        if(16'h100 == resetCnt) begin
                                        isActivated <=1'b1;
                                isActivated <=1'b1;
                                        isoReset <=1'b1;
                                isoReset <=1'b1;
                                end else
                        end else
                                        resetCnt<=resetCnt + 1;
                                resetCnt<=resetCnt + 1;
                        end else begin
                end else begin
                                resetCnt<=16'b0;
                        resetCnt<=16'b0;
                        end
                end
                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.