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 8

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 7 acapola
         input wire [12:0] cyclesPerEtu,
31 4 acapola
    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 7 acapola
        HalfDuplexUartIf #(
57
                .DIVIDER_WIDTH(1'b1),
58
                .CLOCK_PER_BIT_WIDTH(4'd13)
59
                )
60
        uart (
61 2 acapola
                .nReset(nReset),
62
                .clk(clk),
63
                .clkPerCycle(1'b0),
64
                .dataIn(dataIn),
65
                .nWeDataIn(nWeDataIn),
66 7 acapola
                .clocksPerBit(cyclesPerEtu),
67 2 acapola
                .dataOut(dataOut),
68
                .nCsDataOut(nCsDataOut),
69
                .statusOut(statusOut),
70
                .nCsStatusOut(nCsStatusOut),
71
                .serialIn(isoSio),
72
                .serialOut(serialOut),
73
                .comClk(comClk)
74
        );
75
 
76
        reg isoClkEn;
77
        assign isoClk = isoClkEn ? comClk : 1'b0;
78
 
79 5 acapola
reg [16:0] resetCnt;
80
reg waitTs;
81
assign tsReceived = ~waitTs;
82
reg [7:0] ts;
83
assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
84
assign atrIsLate = resetCnt>(16'h100+16'd40000);
85
assign useIndirectConvention = ~waitTs & (ts==8'h3F);
86
assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
87
always @(posedge comClk, negedge nReset) begin
88
        if(~nReset) begin
89
                isoClkEn <= 1'b0;
90
                resetCnt<=16'b0;
91
                waitTs<=1'b1;
92
                isoReset <= 1'b0;
93
                isoVdd <= 1'b0;
94
                isActivated <= 1'b0;
95
        end else if(isActivated) begin
96
                if(waitTs) begin
97
                        if(statusOut[0]) begin
98
                                waitTs<=1'b0;
99
                                ts<=dataOut;
100
                        end
101
                        resetCnt<=resetCnt+1;
102
                end
103
                if(startDeactivation) begin
104
                        isoVdd <= 1'b0;
105 2 acapola
                        isoClkEn <= 1'b0;
106 5 acapola
                        isoReset <= 1'b0;
107 2 acapola
                        resetCnt<=16'b0;
108
                        isActivated <= 1'b0;
109 5 acapola
                end
110
        end else begin
111
                if(startActivation) begin
112
                        waitTs <= 1'b1;
113
                        isoVdd <= 1'b1;
114
                        isoClkEn <= 1'b1;
115
                        if(16'h100 == resetCnt) begin
116
                                isActivated <=1'b1;
117
                                isoReset <=1'b1;
118
                        end else
119
                                resetCnt<=resetCnt + 1;
120 2 acapola
                end else begin
121 5 acapola
                        resetCnt<=16'b0;
122 2 acapola
                end
123
        end
124 5 acapola
end
125 2 acapola
endmodule

powered by: WebSVN 2.1.0

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