SURF  1.0
UartBrg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : UartBrg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-05-13
5 -- Last update: 2016-06-09
6 -------------------------------------------------------------------------------
7 -- Description: UART Baud Rate Generator
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 
21 use work.StdRtlPkg.all;
22 
23 --! @see entity
24  --! @ingroup protocols_uart
25 entity UartBrg is
26 
27  generic (
28  CLK_FREQ_G : real := 125.0E6; -- Default 125 MHz
29  BAUD_RATE_G : integer := 115200; -- Default 115.2 kbps
30  MULTIPLIER_G : integer := 16);
31  port (
32  clk : in sl;
33  rst : in sl;
34  clkEn : out sl);
35 
36 end entity UartBrg;
37 
38 architecture rtl of UartBrg is
39 
40  constant CLK_DIV_C : integer := integer(CLK_FREQ_G / real(BAUD_RATE_G * MULTIPLIER_G)) - 1;
41 
42  type RegType is record
43  count : integer;
44  clkEn : sl;
45  end record RegType;
46 
47  constant REG_INIT_C : RegType := (
48  count => 0,
49  clkEn => '0');
50 
51  signal r : RegType := REG_INIT_C;
52  signal rin : Regtype;
53 
54 begin
55 
56  comb : process (r, rst) is
57  variable v : RegType;
58  begin
59  v := r;
60 
61  v.count := r.count + 1;
62  v.clkEn := '0';
63  if (r.count = CLK_DIV_C) then
64  v.count := 0;
65  v.clkEn := '1';
66  end if;
67 
68  if (rst = '1') then
69  v := REG_INIT_C;
70  end if;
71 
72  rin <= v;
73  clkEn <= r.clkEn;
74  end process;
75 
76  seq : process (clk) is
77  begin
78  if (rising_edge(clk)) then
79  r <= rin;
80  end if;
81  end process;
82 
83 
84 end architecture rtl;
in rstsl
Definition: UartBrg.vhd:33
std_logic sl
Definition: StdRtlPkg.vhd:28
in clksl
Definition: UartBrg.vhd:32
out clkEnsl
Definition: UartBrg.vhd:34
BAUD_RATE_Ginteger := 115200
Definition: UartBrg.vhd:29
CLK_FREQ_Greal := 125.0E6
Definition: UartBrg.vhd:28
MULTIPLIER_Ginteger := 16
Definition: UartBrg.vhd:30