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