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 3

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

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

powered by: WebSVN 2.1.0

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