use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
+--------------------------------------------------------------------------------
+-- Baud generator is an adjustable clock frequency divider. Division factor
+-- is determined by the value present on the input vector named 'scale' and is
+-- equal to:
+-- f_OUT = f_IN / (2 * (1 + 'scale'))
+--
+-- The divided clock signal has a duty cycle of 50%.
+--
+-- The reset input signal is asynchronous. When held active, the output is 0.
+-- When released, the output starts a new period and goes high with the next
+-- rising edge of the input clock signal.
+--
+-- _ _ _ _ _ _ _ _ _ _ _ _
+-- CLK _| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_
+-- _________
+-- RESET ____________| |__________________________
+-- ___ __ ___ ___ ___
+-- CLK_BAUD _| |___| |____________| |___| |___| |___
+--
+--------------------------------------------------------------------------------
+
entity baud_gen is
generic (
SCALE_WIDTH : integer := 16
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
+--------------------------------------------------------------------------------
+-- This is a behavioral model of FIFO (Fisrt In First Out) memory.
+--
+-- All operations (except for reset) are synchronous to 'clk' rising edges.
+-- Reset makes fifo empty but actually does not change the content of memory.
+--
+-- The generic parameter 'width' determines the width of address vector used to
+-- access memory and so the size of memory.
+--
+-- When overflow occurs, the 'overflow' flag is set to 1 and the least recent
+-- data is rewritten by new data.
+--
+-- Underflow is not handled currently and causes misfunction.
+--------------------------------------------------------------------------------
+
entity fifo is
generic (
width : integer := 2
port (
clk : in std_logic;
reset : in std_logic;
- we : in std_logic;
- re : in std_logic;
- clear_ow : in std_logic;
+ we : in std_logic; -- write enable
+ re : in std_logic; -- read enable
+ clear_ow : in std_logic; -- clear overflow flag
d_in : in std_logic_vector (7 downto 0);
d_out : out std_logic_vector (7 downto 0);
- full : out std_logic;
- hfull : out std_logic;
- empty : out std_logic;
+ full : out std_logic; -- fifo is full
+ hfull : out std_logic; -- fifo is half full
+ empty : out std_logic; -- fifo is empty
overflow : out std_logic
);
end fifo;
begin
+ -- Handling of overflow output signal and internal length signal, storing
+ -- the number of occupied memory positions.
process (clk, reset)
begin
if (reset = '1') then
end process;
+ -- Handling of address registers and writing to memory.
process (clk, reset)
begin
if (reset = '1') then
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
+--------------------------------------------------------------------------------
+-- Output shift register
+--
+-- This entity can be used for generating of RS232 like output. Configuration is
+-- hard wired as 8N1 (8 bits of data, no parity, 1 stop bit).
+--
+-- All operations (except for 'reset') are synchronous to 'clk' rising edges.
+-- This clock signal also determines baud rate.
+--
+-- When 'ready' signal is high, next data vector can be written in by setting
+-- 'we' signal.
+--------------------------------------------------------------------------------
+
entity transmitter is
port (
clk : in std_logic;
--------------------------------------------------------------------------------
-architecture dataflow of transmitter is
+architecture behavioral of transmitter is
-- Output shift register (containing also start and stop bit).
signal tx_shift_reg : std_logic_vector (9 downto 0);
-- Register parallel to the output shift register where '1' shows the last
-- bit of the frame ('1' is in the place of stop bit).
signal tx_flag : std_logic_vector (9 downto 0);
- -- Transmitting of new frame could be started with next tx_clk.
+ -- Transmitting of new frame could be started with next clk.
signal tx_ready : std_logic;
--------------------------------------------------------------------------------
tx <= tx_shift_reg(0);
-end dataflow;
+end behavioral;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
+--------------------------------------------------------------------------------
+-- Transmitter control FSM
+--
+-- Finite state machine controlling interconnection of FIFO buffer and output
+-- shift register.
+--------------------------------------------------------------------------------
+
entity tx_control is
port (
clk : in std_logic;