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 10

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 10 acapola
// Author: Sebastien Riou
5
// Creation date: 17:16:40 01/09/2011 
6 2 acapola
//
7 10 acapola
// Last change date:    $LastChangedDate: 2011-01-29 11:41:01 +0100 (Sat, 29 Jan 2011) $
8
// Last changed by:     $LastChangedBy: acapola $
9
// Last revision:               $LastChangedRevision: 10 $
10
// Head URL:                    $HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/sources/Iso7816_3_Master.v $                               
11 2 acapola
//
12
//////////////////////////////////////////////////////////////////////////////////
13
module Iso7816_3_Master(
14 4 acapola
    input wire nReset,
15
    input wire clk,
16
         input wire [15:0] clkPerCycle,//not supported yet
17
         input wire startActivation,//Starts activation sequence
18
         input wire startDeactivation,//Starts deactivation sequence
19
    input wire [7:0] dataIn,
20
    input wire nWeDataIn,
21 7 acapola
         input wire [12:0] cyclesPerEtu,
22 4 acapola
    output wire [7:0] dataOut,
23
    input wire nCsDataOut,
24
    output wire [7:0] statusOut,
25
    input wire nCsStatusOut,
26 2 acapola
         output reg isActivated,//set to high by activation sequence, set to low by deactivation sequence
27 4 acapola
         output wire useIndirectConvention,
28
         output wire tsError,//high if TS character is wrong
29
         output wire tsReceived,
30
         output wire atrIsEarly,//high if TS received before 400 cycles after reset release
31
         output wire atrIsLate,//high if TS is still not received after 40000 cycles after reset release
32 2 acapola
         //ISO7816 signals
33 4 acapola
    inout wire isoSio,
34
         output wire isoClk,
35 3 acapola
         output reg isoReset,
36
         output reg isoVdd
37 2 acapola
    );
38
 
39 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
40
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
41
 
42 4 acapola
wire serialOut;
43
assign isoSio = isTx ? serialOut : 1'bz;
44
pullup(isoSio);
45 3 acapola
wire comClk;
46 2 acapola
 
47 7 acapola
        HalfDuplexUartIf #(
48
                .DIVIDER_WIDTH(1'b1),
49
                .CLOCK_PER_BIT_WIDTH(4'd13)
50
                )
51
        uart (
52 2 acapola
                .nReset(nReset),
53
                .clk(clk),
54
                .clkPerCycle(1'b0),
55
                .dataIn(dataIn),
56
                .nWeDataIn(nWeDataIn),
57 7 acapola
                .clocksPerBit(cyclesPerEtu),
58 2 acapola
                .dataOut(dataOut),
59
                .nCsDataOut(nCsDataOut),
60
                .statusOut(statusOut),
61
                .nCsStatusOut(nCsStatusOut),
62
                .serialIn(isoSio),
63
                .serialOut(serialOut),
64
                .comClk(comClk)
65
        );
66
 
67
        reg isoClkEn;
68
        assign isoClk = isoClkEn ? comClk : 1'b0;
69
 
70 5 acapola
reg [16:0] resetCnt;
71
reg waitTs;
72
assign tsReceived = ~waitTs;
73
reg [7:0] ts;
74
assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
75
assign atrIsLate = resetCnt>(16'h100+16'd40000);
76
assign useIndirectConvention = ~waitTs & (ts==8'h3F);
77
assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
78
always @(posedge comClk, negedge nReset) begin
79
        if(~nReset) begin
80
                isoClkEn <= 1'b0;
81
                resetCnt<=16'b0;
82
                waitTs<=1'b1;
83
                isoReset <= 1'b0;
84
                isoVdd <= 1'b0;
85
                isActivated <= 1'b0;
86
        end else if(isActivated) begin
87
                if(waitTs) begin
88
                        if(statusOut[0]) begin
89
                                waitTs<=1'b0;
90
                                ts<=dataOut;
91
                        end
92
                        resetCnt<=resetCnt+1;
93
                end
94
                if(startDeactivation) begin
95
                        isoVdd <= 1'b0;
96 2 acapola
                        isoClkEn <= 1'b0;
97 5 acapola
                        isoReset <= 1'b0;
98 2 acapola
                        resetCnt<=16'b0;
99
                        isActivated <= 1'b0;
100 5 acapola
                end
101
        end else begin
102
                if(startActivation) begin
103
                        waitTs <= 1'b1;
104
                        isoVdd <= 1'b1;
105
                        isoClkEn <= 1'b1;
106
                        if(16'h100 == resetCnt) begin
107
                                isActivated <=1'b1;
108
                                isoReset <=1'b1;
109
                        end else
110
                                resetCnt<=resetCnt + 1;
111 2 acapola
                end else begin
112 5 acapola
                        resetCnt<=16'b0;
113 2 acapola
                end
114
        end
115 5 acapola
end
116 2 acapola
endmodule

powered by: WebSVN 2.1.0

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