OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [sources/] [HalfDuplexUartIf.v] - Blame information for rev 18

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: 19:57:35 10/31/2010
4
 
5
$LastChangedDate: 2011-03-07 14:17:52 +0100 (Mon, 07 Mar 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 18 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/sources/HalfDuplexUartIf.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 11 acapola
 
34
module HalfDuplexUartIf
35
#(//parameters to override
36
        parameter DIVIDER_WIDTH = 1,
37
        parameter CLOCK_PER_BIT_WIDTH = 13      //allow to support default speed of ISO7816
38
)
39
(
40 4 acapola
    input wire nReset,
41
    input wire clk,
42
    input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
43
         input wire [7:0] dataIn,
44
    input wire nWeDataIn,
45 7 acapola
    input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
46 15 acapola
    input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
47
         input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
48
    input wire msbFirst,  //if 1, bits order is: startBit, b7, b6, b5...b0, parity
49
         output wire [7:0] dataOut,
50 4 acapola
    input wire nCsDataOut,
51
    output wire [7:0] statusOut,
52
    input wire nCsStatusOut,
53
    input wire serialIn,
54
         output wire serialOut,
55
         output wire comClk
56 2 acapola
    );
57 11 acapola
 
58 2 acapola
 
59
   reg [7:0] dataReg;
60
 
61
        // Inputs
62
        wire [7:0] txData;
63
        reg txPending;
64
        wire ackFlags;
65
 
66
        // Outputs
67
        wire [7:0] rxData;
68
        wire overrunErrorFlag;
69
        wire dataOutReadyFlag;
70
        wire frameErrorFlag;
71
        wire txRun;
72
   wire endOfRx;
73
        wire rxRun;
74
        wire rxStartBit;
75
        wire txFull;
76 3 acapola
        wire isTx;
77 2 acapola
 
78
   wire rxFlagsSet = dataOutReadyFlag | overrunErrorFlag | frameErrorFlag;
79
   reg bufferFull;
80
   reg [1:0] flagsReg;
81
 
82
   assign txData = dataReg;
83 15 acapola
 
84 2 acapola
   assign dataOut=dataReg;
85
   assign statusOut[7:0]={txRun, txPending, rxRun, rxStartBit, isTx, flagsReg, bufferFull};
86
 
87
reg waitTxFull0;//internal reg for managing bufferFull bit in Tx
88
 
89
assign ackFlags=~txPending & ~txRun & rxFlagsSet & ((bufferFull & ~nCsDataOut)| ~bufferFull);
90
 
91
always @(posedge clk, negedge nReset) begin
92
   if(~nReset) begin
93
      bufferFull <= 1'b0;
94
      flagsReg <= 1'b0;
95
      txPending <= 1'b0;
96
   end else begin
97
      if(ackFlags) begin
98
         dataReg <= rxData;
99
         flagsReg <= {overrunErrorFlag, frameErrorFlag};
100
         if(rxFlagsSet)
101
            bufferFull <= 1'b1;
102
         else
103
            bufferFull <= 1'b0;
104
      end else if(txPending) begin
105
         if(waitTxFull0) begin
106
            if(~txFull)
107
               waitTxFull0 <= 1'b0;
108
         end else if(txFull) begin//tx actually started, clear txPending and free buffer
109
            txPending <= 1'b0;
110
            bufferFull <= 1'b0; //buffer is empty
111
         end
112
      end else if(~nCsDataOut) begin
113
         bufferFull <= 1'b0;
114
      end else if(~nWeDataIn) begin
115
         dataReg <= dataIn;
116
         bufferFull <= 1'b1;
117
         txPending <= 1'b1;
118
         waitTxFull0 <= txFull;
119
      end
120
   end
121
end
122 18 acapola
wire endOfTx;
123 7 acapola
        BasicHalfDuplexUart #(
124
                .DIVIDER_WIDTH(DIVIDER_WIDTH),
125
                .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
126
                )
127 2 acapola
        uart (
128
                .rxData(rxData),
129
                .overrunErrorFlag(overrunErrorFlag),
130
                .dataOutReadyFlag(dataOutReadyFlag),
131
                .frameErrorFlag(frameErrorFlag),
132
                .txRun(txRun),
133
                .endOfRx(endOfRx),
134 18 acapola
                .endOfTx(endOfTx),
135 2 acapola
      .rxRun(rxRun),
136
                .rxStartBit(rxStartBit),
137
                .txFull(txFull),
138
                .isTx(isTx),
139
                .serialIn(serialIn),
140
                .serialOut(serialOut),
141 3 acapola
                .comClk(comClk),
142 2 acapola
                .txData(txData),
143
                .clocksPerBit(clocksPerBit),
144
                .stopBit2(stopBit2),
145
                .oddParity(oddParity),
146
      .msbFirst(msbFirst),
147
           .startTx(txPending),
148
                .ackFlags(ackFlags),
149
                .clkPerCycle(clkPerCycle),
150
                .clk(clk),
151
                .nReset(nReset)
152
        );
153
 
154
endmodule
155 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.