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 11

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

Line No. Rev Author Line
1 11 acapola
/*
2
Author: Sebastien Riou (acapola)
3
Creation date: 17:16:40 01/09/2011
4
 
5
$LastChangedDate: 2011-01-29 13:16:17 +0100 (Sat, 29 Jan 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 11 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/sources/Iso7816_3_Master.v $
9
 
10
This file is under the BSD licence:
11
Copyright (c) 2011, Sebastien Riou
12
 
13
All rights reserved.
14
 
15
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
 
17
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
18
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
19
The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32 4 acapola
`default_nettype none
33 2 acapola
module Iso7816_3_Master(
34 4 acapola
    input wire nReset,
35
    input wire clk,
36
         input wire [15:0] clkPerCycle,//not supported yet
37
         input wire startActivation,//Starts activation sequence
38
         input wire startDeactivation,//Starts deactivation sequence
39
    input wire [7:0] dataIn,
40
    input wire nWeDataIn,
41 7 acapola
         input wire [12:0] cyclesPerEtu,
42 4 acapola
    output wire [7:0] dataOut,
43
    input wire nCsDataOut,
44
    output wire [7:0] statusOut,
45
    input wire nCsStatusOut,
46 2 acapola
         output reg isActivated,//set to high by activation sequence, set to low by deactivation sequence
47 4 acapola
         output wire useIndirectConvention,
48
         output wire tsError,//high if TS character is wrong
49
         output wire tsReceived,
50
         output wire atrIsEarly,//high if TS received before 400 cycles after reset release
51
         output wire atrIsLate,//high if TS is still not received after 40000 cycles after reset release
52 2 acapola
         //ISO7816 signals
53 4 acapola
    inout wire isoSio,
54
         output wire isoClk,
55 3 acapola
         output reg isoReset,
56
         output reg isoVdd
57 2 acapola
    );
58
 
59 3 acapola
wire txRun,txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull;
60
assign {txRun, txPending, rxRun, rxStartBit, isTx, overrunErrorFlag, frameErrorFlag, bufferFull} = statusOut;
61
 
62 4 acapola
wire serialOut;
63
assign isoSio = isTx ? serialOut : 1'bz;
64
pullup(isoSio);
65 3 acapola
wire comClk;
66 2 acapola
 
67 7 acapola
        HalfDuplexUartIf #(
68
                .DIVIDER_WIDTH(1'b1),
69
                .CLOCK_PER_BIT_WIDTH(4'd13)
70
                )
71
        uart (
72 2 acapola
                .nReset(nReset),
73
                .clk(clk),
74
                .clkPerCycle(1'b0),
75
                .dataIn(dataIn),
76
                .nWeDataIn(nWeDataIn),
77 7 acapola
                .clocksPerBit(cyclesPerEtu),
78 2 acapola
                .dataOut(dataOut),
79
                .nCsDataOut(nCsDataOut),
80
                .statusOut(statusOut),
81
                .nCsStatusOut(nCsStatusOut),
82
                .serialIn(isoSio),
83
                .serialOut(serialOut),
84
                .comClk(comClk)
85
        );
86
 
87
        reg isoClkEn;
88
        assign isoClk = isoClkEn ? comClk : 1'b0;
89
 
90 5 acapola
reg [16:0] resetCnt;
91
reg waitTs;
92
assign tsReceived = ~waitTs;
93
reg [7:0] ts;
94
assign atrIsEarly = ~waitTs & (resetCnt<(16'h100+16'd400));
95
assign atrIsLate = resetCnt>(16'h100+16'd40000);
96
assign useIndirectConvention = ~waitTs & (ts==8'h3F);
97
assign tsError = ~waitTs & (ts!=8'h3B) & ~useIndirectConvention;
98
always @(posedge comClk, negedge nReset) begin
99
        if(~nReset) begin
100
                isoClkEn <= 1'b0;
101
                resetCnt<=16'b0;
102
                waitTs<=1'b1;
103
                isoReset <= 1'b0;
104
                isoVdd <= 1'b0;
105
                isActivated <= 1'b0;
106
        end else if(isActivated) begin
107
                if(waitTs) begin
108
                        if(statusOut[0]) begin
109
                                waitTs<=1'b0;
110
                                ts<=dataOut;
111
                        end
112
                        resetCnt<=resetCnt+1;
113
                end
114
                if(startDeactivation) begin
115
                        isoVdd <= 1'b0;
116 2 acapola
                        isoClkEn <= 1'b0;
117 5 acapola
                        isoReset <= 1'b0;
118 2 acapola
                        resetCnt<=16'b0;
119
                        isActivated <= 1'b0;
120 5 acapola
                end
121
        end else begin
122
                if(startActivation) begin
123
                        waitTs <= 1'b1;
124
                        isoVdd <= 1'b1;
125
                        isoClkEn <= 1'b1;
126
                        if(16'h100 == resetCnt) begin
127
                                isActivated <=1'b1;
128
                                isoReset <=1'b1;
129
                        end else
130
                                resetCnt<=resetCnt + 1;
131 2 acapola
                end else begin
132 5 acapola
                        resetCnt<=16'b0;
133 2 acapola
                end
134
        end
135 5 acapola
end
136 2 acapola
endmodule
137 11 acapola
`default_nettype wire

powered by: WebSVN 2.1.0

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