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

Subversion Repositories blue

[/] [blue/] [trunk/] [blue8/] [uart.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wd5gnr
/*
2
    This file is part of Blue8.
3
 
4
    Foobar is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    Foobar is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13
 
14
    You should have received a copy of the GNU Lesser General Public License
15
    along with Blue8.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
    Blue8 by Al Williams alw@al-williams.com
18
 
19
*/
20
 
21
`default_nettype none
22
 
23
module uart (input wire clk, input wire rst, input wire rxd,
24
  output wire txd,input wire [7:0] din, output wire [7:0] dout,
25
  output wire data_ready, input wire read,output wire tbre,output wire tsre,input wire write,
26
  output wire framing_error,output wire overrun_error);
27
 
28
 
29
parameter XTAL_CLK = 35000000;          //use 40MHz for BLUE, 50MHz for stand alone
30
parameter BAUD = 9600;
31
parameter CLK_DIV = XTAL_CLK / (BAUD * 16 * 2); //163 for 9600@50MHz,   130 @40MHz
32
parameter CW   = 8;      // must be enough bits to hold CLK_DIV
33
 
34
 
35
reg             [CW-1:0] clk_div;
36
reg                             baud_clk;
37
reg        clke;
38
 
39
always @(posedge clk or posedge rst)     // generate 16x baud clock
40
begin
41
  if (rst) begin
42
    clk_div  <= 0;
43
    baud_clk <= 0;
44
         clke<=1'b0;
45
  end else if (clk_div == CLK_DIV) begin
46
    clk_div  <= 0;
47
    baud_clk <= ~baud_clk;
48
         clke<=1'b0;
49
  end else begin
50
    clke<=1'b0;
51
    if (clk_div==CLK_DIV-1 && ~baud_clk) clke<=1'b1;
52
    clk_div  <= clk_div + 1;
53
    baud_clk <= baud_clk;
54
  end
55
end
56
 
57
 
58
rcvr u1 (clk,clke,rst,rxd,dout,data_ready,read,framing_error,overrun_error);
59
 
60
txmit u2 (clk,clke,rst,txd,din,tbre,tsre,write);
61
 
62
endmodule

powered by: WebSVN 2.1.0

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