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] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 acapola
`timescale 1ns / 1ps
2 4 acapola
`default_nettype none
3 2 acapola
//////////////////////////////////////////////////////////////////////////////////
4
// Company: 
5
// Engineer: 
6
// 
7
// Create Date:    17:16:40 01/09/2011 
8
// Design Name: 
9
// Module Name:    Iso7816_3_Master 
10
// Project Name: 
11
// Target Devices: 
12
// Tool versions: 
13
// Description: 
14
//
15
// Dependencies: 
16
//
17
// Revision: 
18
// Revision 0.01 - File Created
19
// Additional Comments: 
20
//
21
//////////////////////////////////////////////////////////////////////////////////
22
module Iso7816_3_Master(
23 4 acapola
    input wire nReset,
24
    input wire clk,
25
         input wire [15:0] clkPerCycle,//not supported yet
26
         input wire startActivation,//Starts activation sequence
27
         input wire startDeactivation,//Starts deactivation sequence
28
    input wire [7:0] dataIn,
29
    input wire nWeDataIn,
30
         input wire [12:0] cyclePerEtu,
31
    output wire [7:0] dataOut,
32
    input wire nCsDataOut,
33
    output wire [7:0] statusOut,
34
    input wire nCsStatusOut,
35 2 acapola
         output reg isActivated,//set to high by activation sequence, set to low by deactivation sequence
36 4 acapola
         output wire useIndirectConvention,
37
         output wire tsError,//high if TS character is wrong
38
         output wire tsReceived,
39
         output wire atrIsEarly,//high if TS received before 400 cycles after reset release
40
         output wire atrIsLate,//high if TS is still not received after 40000 cycles after reset release
41 2 acapola
         //ISO7816 signals
42 4 acapola
    inout wire isoSio,
43
         output wire isoClk,
44 3 acapola
         output reg isoReset,
45
         output reg isoVdd
46 2 acapola
    );
47
 
48 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
49
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
50
 
51 4 acapola
wire serialOut;
52
assign isoSio = isTx ? serialOut : 1'bz;
53
pullup(isoSio);
54 3 acapola
wire comClk;
55 2 acapola
 
56
        HalfDuplexUartIf uart (
57
                .nReset(nReset),
58
                .clk(clk),
59
                .clkPerCycle(1'b0),
60
                .dataIn(dataIn),
61
                .nWeDataIn(nWeDataIn),
62
                .dataOut(dataOut),
63
                .nCsDataOut(nCsDataOut),
64
                .statusOut(statusOut),
65
                .nCsStatusOut(nCsStatusOut),
66
                .serialIn(isoSio),
67
                .serialOut(serialOut),
68
                .comClk(comClk)
69
        );
70
 
71
        reg isoClkEn;
72
        assign isoClk = isoClkEn ? comClk : 1'b0;
73
 
74 5 acapola
reg [16:0] resetCnt;
75
reg waitTs;
76
assign tsReceived = ~waitTs;
77
reg [7:0] ts;
78
assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
79
assign atrIsLate = resetCnt>(16'h100+16'd40000);
80
assign useIndirectConvention = ~waitTs & (ts==8'h3F);
81
assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
82
always @(posedge comClk, negedge nReset) begin
83
        if(~nReset) begin
84
                isoClkEn <= 1'b0;
85
                resetCnt<=16'b0;
86
                waitTs<=1'b1;
87
                isoReset <= 1'b0;
88
                isoVdd <= 1'b0;
89
                isActivated <= 1'b0;
90
        end else if(isActivated) begin
91
                if(waitTs) begin
92
                        if(statusOut[0]) begin
93
                                waitTs<=1'b0;
94
                                ts<=dataOut;
95
                        end
96
                        resetCnt<=resetCnt+1;
97
                end
98
                if(startDeactivation) begin
99
                        isoVdd <= 1'b0;
100 2 acapola
                        isoClkEn <= 1'b0;
101 5 acapola
                        isoReset <= 1'b0;
102 2 acapola
                        resetCnt<=16'b0;
103
                        isActivated <= 1'b0;
104 5 acapola
                end
105
        end else begin
106
                if(startActivation) begin
107
                        waitTs <= 1'b1;
108
                        isoVdd <= 1'b1;
109
                        isoClkEn <= 1'b1;
110
                        if(16'h100 == resetCnt) begin
111
                                isActivated <=1'b1;
112
                                isoReset <=1'b1;
113
                        end else
114
                                resetCnt<=resetCnt + 1;
115 2 acapola
                end else begin
116 5 acapola
                        resetCnt<=16'b0;
117 2 acapola
                end
118
        end
119 5 acapola
end
120 2 acapola
endmodule

powered by: WebSVN 2.1.0

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