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

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [sources/] [Uart.v] - Blame information for rev 15

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: 23:57:02 08/31/2010
4
 
5
$LastChangedDate: 2011-02-13 16:20:10 +0100 (Sun, 13 Feb 2011) $
6
$LastChangedBy: acapola $
7
$LastChangedRevision: 15 $
8
$HeadURL: file:///svn/iso7816_3_master/iso7816_3_master/trunk/sources/Uart.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
`default_nettype none
33 4 acapola
`timescale 1ns / 1ps
34 11 acapola
 
35
/*
36
Half duplex UART with 1 byte buffer
37
*/
38
module BasicHalfDuplexUart
39
#(//parameters to override
40
        parameter DIVIDER_WIDTH = 1,
41
        parameter CLOCK_PER_BIT_WIDTH = 13,     //allow to support default speed of ISO7816
42
        //invert the polarity of the output or not
43
        parameter IN_POLARITY = 1'b0,
44
        parameter PARITY_POLARITY = 1'b1,
45
        //default conventions
46
        parameter START_BIT = 1'b0,
47
        parameter STOP_BIT1 = 1'b1,
48
        parameter STOP_BIT2 = 1'b1
49
)
50
(
51 4 acapola
    output wire [7:0] rxData,
52
    output wire overrunErrorFlag,       //new data has been received before dataOut was read
53
    output wire dataOutReadyFlag,       //new data available
54
    output wire frameErrorFlag,         //bad parity or bad stop bits
55
    output wire txRun,                                  //tx is started
56
    output wire endOfRx,           //one cycle pulse: 1 during last cycle of last stop bit of rx
57
    output wire rxRun,                                  //rx is definitely started, one of the three flag will be set
58
    output wire rxStartBit,                     //rx is started, but we don't know yet if real rx or just a glitch
59
    output wire txFull,
60
    output wire isTx,              //1 only when tx is ongoing. Indicates the direction of the com line.
61 12 acapola
    output wire endOfTx,           //one cycle pulse: 1 during last cycle of last stop bit of tx
62 2 acapola
 
63 4 acapola
         input wire serialIn,                           //signals to merged into a inout signal according to "isTx"
64
         output wire serialOut,
65
         output wire comClk,
66 2 acapola
 
67 4 acapola
    input wire [DIVIDER_WIDTH-1:0] clkPerCycle,
68
         input wire [7:0] txData,
69
         input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
70
         input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
71
         input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
72
    input wire msbFirst,  //if 1, bits order is: startBit, b7, b6, b5...b0, parity
73
         input wire startTx,
74
         input wire ackFlags,
75
         input wire clk,
76
    input wire nReset
77 2 acapola
    );
78
 
79
wire rxSerialIn = isTx ? STOP_BIT1 : serialIn;
80
wire loadDataIn;
81
wire txStopBits;
82
assign isTx = txRun & ~txStopBits;
83
assign loadDataIn = startTx & ~rxStartBit & (~rxRun | endOfRx);
84
 
85 12 acapola
reg [CLOCK_PER_BIT_WIDTH-1:0] safeClocksPerBit;
86 15 acapola
reg safeStopBit2;
87
reg safeOddParity;
88
reg safeMsbFirst;
89 12 acapola
always @(posedge clk, negedge nReset) begin
90
        if(~nReset) begin
91
                safeClocksPerBit<=clocksPerBit;
92 15 acapola
                safeStopBit2<=stopBit2;
93
                safeOddParity<=oddParity;
94
                safeMsbFirst<=msbFirst;
95 12 acapola
        end else if(endOfRx|endOfTx|~(rxRun|rxStartBit|txRun)) begin
96
                safeClocksPerBit<=clocksPerBit;
97 15 acapola
                safeStopBit2<=stopBit2;
98
                safeOddParity<=oddParity;
99
                safeMsbFirst<=msbFirst;
100 12 acapola
        end
101 2 acapola
end
102 12 acapola
 
103 5 acapola
wire stopBit;
104 2 acapola
// Instantiate the module
105
RxCoreSelfContained #(
106 7 acapola
                .DIVIDER_WIDTH(DIVIDER_WIDTH),
107
                .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
108
                )
109 2 acapola
        rxCore (
110
    .dataOut(rxData),
111
    .overrunErrorFlag(overrunErrorFlag),
112
    .dataOutReadyFlag(dataOutReadyFlag),
113
    .frameErrorFlag(frameErrorFlag),
114
    .endOfRx(endOfRx),
115
    .run(rxRun),
116
    .startBit(rxStartBit),
117 5 acapola
         .stopBit(stopBit),
118
    .clkPerCycle(clkPerCycle),
119 12 acapola
    .clocksPerBit(safeClocksPerBit),
120 15 acapola
    .stopBit2(safeStopBit2),
121
    .oddParity(safeOddParity),
122
    .msbFirst(safeMsbFirst),
123 2 acapola
         .ackFlags(ackFlags),
124
    .serialIn(rxSerialIn),
125
    .comClk(comClk),
126
    .clk(clk),
127
    .nReset(nReset)
128
    );
129 7 acapola
TxCore #(.DIVIDER_WIDTH(DIVIDER_WIDTH),
130
                        .CLOCK_PER_BIT_WIDTH(CLOCK_PER_BIT_WIDTH)
131
                )
132 2 acapola
        txCore (
133
        .serialOut(serialOut),
134 12 acapola
        .run(txRun),
135
        .endOfTx(endOfTx),
136 2 acapola
        .full(txFull),
137
   .stopBits(txStopBits),
138
        .dataIn(txData),
139
        .clkPerCycle(clkPerCycle),
140 12 acapola
        .clocksPerBit(safeClocksPerBit),
141 15 acapola
        .stopBit2(safeStopBit2),
142
   .oddParity(safeOddParity),
143
   .msbFirst(safeMsbFirst),
144 2 acapola
        .loadDataIn(loadDataIn),
145
        .comClk(comClk),
146
   .clk(clk),
147
   .nReset(nReset)
148
);
149
 
150
endmodule
151 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.