1 |
2 |
olupas |
--===========================================================================--
|
2 |
|
|
--
|
3 |
|
|
-- S Y N T H E Z I A B L E miniUART C O R E
|
4 |
|
|
--
|
5 |
|
|
-- www.OpenCores.Org - January 2000
|
6 |
|
|
-- This core adheres to the GNU public license
|
7 |
|
|
|
8 |
|
|
-- Design units : miniUART core for the OCRP-1
|
9 |
|
|
--
|
10 |
|
|
-- File name : clkUnit.vhd
|
11 |
|
|
--
|
12 |
|
|
-- Purpose : Implements an miniUART device for communication purposes
|
13 |
|
|
-- between the OR1K processor and the Host computer through
|
14 |
|
|
-- an RS-232 communication protocol.
|
15 |
|
|
--
|
16 |
|
|
-- Library : uart_lib.vhd
|
17 |
|
|
--
|
18 |
|
|
-- Dependencies : IEEE.Std_Logic_1164
|
19 |
|
|
--
|
20 |
|
|
--===========================================================================--
|
21 |
|
|
-------------------------------------------------------------------------------
|
22 |
|
|
-- Revision list
|
23 |
|
|
-- Version Author Date Changes
|
24 |
|
|
--
|
25 |
|
|
-- 0.1 Ovidiu Lupas 15 January 2000 New model
|
26 |
|
|
-- ovilup@mail.dnttm.ro
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
-- Description : Generates the Baud clock and enable signals for RX & TX
|
29 |
|
|
-- units.
|
30 |
|
|
-------------------------------------------------------------------------------
|
31 |
|
|
-- Entity for Baud rate generator Unit - 9600 baudrate --
|
32 |
|
|
-------------------------------------------------------------------------------
|
33 |
|
|
library ieee;
|
34 |
|
|
use ieee.std_logic_1164.all;
|
35 |
|
|
use ieee.numeric_std.all;
|
36 |
|
|
library work;
|
37 |
|
|
use work.UART_Def.all;
|
38 |
|
|
-------------------------------------------------------------------------------
|
39 |
|
|
-- Baud rate generator
|
40 |
|
|
-------------------------------------------------------------------------------
|
41 |
|
|
entity ClkUnit is
|
42 |
|
|
port (
|
43 |
|
|
SysClk : in Std_Logic; -- System Clock
|
44 |
|
|
EnableRx : out Std_Logic; -- Control signal
|
45 |
|
|
EnableTx : out Std_Logic; -- Control signal
|
46 |
|
|
Reset : in Std_Logic); -- Reset input
|
47 |
|
|
end entity; --================== End of entity ==============================--
|
48 |
|
|
-------------------------------------------------------------------------------
|
49 |
|
|
-- Architecture for Baud rate generator Unit
|
50 |
|
|
-------------------------------------------------------------------------------
|
51 |
|
|
architecture Behaviour of ClkUnit is
|
52 |
|
|
-----------------------------------------------------------------------------
|
53 |
|
|
-- Signals
|
54 |
|
|
-----------------------------------------------------------------------------
|
55 |
|
|
signal ClkDiv26 : Std_Logic;
|
56 |
|
|
signal tmpEnRX : Std_Logic;
|
57 |
|
|
signal tmpEnTX : Std_Logic;
|
58 |
|
|
begin
|
59 |
|
|
-----------------------------------------------------------------------------
|
60 |
|
|
-- Divides the system clock of 40 MHz by 26
|
61 |
|
|
-----------------------------------------------------------------------------
|
62 |
|
|
DivClk26 : process(SysClk,Reset)
|
63 |
|
|
constant CntOne : unsigned(4 downto 0) := "00001";
|
64 |
|
|
variable Cnt26 : unsigned(4 downto 0);
|
65 |
|
|
begin
|
66 |
|
|
if Rising_Edge(SysClk) then
|
67 |
|
|
if Reset = '0' then
|
68 |
|
|
Cnt26 := "00000";
|
69 |
|
|
ClkDiv26 <= '0';
|
70 |
|
|
else
|
71 |
|
|
Cnt26 := Cnt26 + CntOne;
|
72 |
|
|
case Cnt26 is
|
73 |
|
|
when "11010" =>
|
74 |
|
|
ClkDiv26 <= '1';
|
75 |
|
|
Cnt26 := "00000";
|
76 |
|
|
when others =>
|
77 |
|
|
ClkDiv26 <= '0';
|
78 |
|
|
end case;
|
79 |
|
|
end if;
|
80 |
|
|
end if;
|
81 |
|
|
end process;
|
82 |
|
|
-----------------------------------------------------------------------------
|
83 |
|
|
-- Provides the EnableRX signal, at ~ 155 KHz
|
84 |
|
|
-----------------------------------------------------------------------------
|
85 |
|
|
DivClk10 : process(SysClk,Reset,Clkdiv26)
|
86 |
|
|
constant CntOne : unsigned(3 downto 0) := "0001";
|
87 |
|
|
variable Cnt10 : unsigned(3 downto 0);
|
88 |
|
|
begin
|
89 |
|
|
if Rising_Edge(SysClk) then
|
90 |
|
|
if Reset = '0' then
|
91 |
|
|
Cnt10 := "0000";
|
92 |
|
|
tmpEnRX <= '0';
|
93 |
|
|
elsif ClkDiv26 = '1' then
|
94 |
|
|
Cnt10 := Cnt10 + CntOne;
|
95 |
|
|
end if;
|
96 |
|
|
case Cnt10 is
|
97 |
|
|
when "1010" =>
|
98 |
|
|
tmpEnRX <= '1';
|
99 |
|
|
Cnt10 := "0000";
|
100 |
|
|
when others =>
|
101 |
|
|
tmpEnRX <= '0';
|
102 |
|
|
end case;
|
103 |
|
|
end if;
|
104 |
|
|
end process;
|
105 |
|
|
-----------------------------------------------------------------------------
|
106 |
|
|
-- Provides the EnableTX signal, at 9.6 KHz
|
107 |
|
|
-----------------------------------------------------------------------------
|
108 |
|
|
DivClk16 : process(SysClk,Reset,tmpEnRX)
|
109 |
|
|
constant CntOne : unsigned(4 downto 0) := "00001";
|
110 |
|
|
variable Cnt16 : unsigned(4 downto 0);
|
111 |
|
|
begin
|
112 |
|
|
if Rising_Edge(SysClk) then
|
113 |
|
|
if Reset = '0' then
|
114 |
|
|
Cnt16 := "00000";
|
115 |
|
|
tmpEnTX <= '0';
|
116 |
|
|
elsif tmpEnRX = '1' then
|
117 |
|
|
Cnt16 := Cnt16 + CntOne;
|
118 |
|
|
end if;
|
119 |
|
|
case Cnt16 is
|
120 |
|
|
when "01111" =>
|
121 |
|
|
tmpEnTX <= '1';
|
122 |
|
|
Cnt16 := Cnt16 + CntOne;
|
123 |
|
|
when "10010" =>
|
124 |
|
|
Cnt16 := "00000";
|
125 |
|
|
when others =>
|
126 |
|
|
tmpEnTX <= '0';
|
127 |
|
|
end case;
|
128 |
|
|
end if;
|
129 |
|
|
end process;
|
130 |
|
|
|
131 |
|
|
EnableRX <= tmpEnRX;
|
132 |
|
|
EnableTX <= tmpEnTX;
|
133 |
|
|
end Behaviour; --==================== End of architecture ===================--
|