Line 18... |
Line 18... |
|
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use work.mlite_pack.all;
|
use work.mlite_pack.all;
|
|
|
entity uart is
|
entity uart is
|
generic(save_file_name : string);
|
generic(log_file : string := "UNUSED");
|
port(clk : in std_logic;
|
port(clk : in std_logic;
|
reset : in std_logic;
|
reset : in std_logic;
|
uart_sel : in std_logic;
|
uart_sel : in std_logic;
|
data : in std_logic_vector(7 downto 0);
|
data : in std_logic_vector(7 downto 0);
|
read_pin : in std_logic;
|
uart_read : in std_logic;
|
write_pin : out std_logic;
|
uart_write : out std_logic;
|
pause : out std_logic);
|
pause : out std_logic);
|
end; --entity ram
|
end; --entity ram
|
|
|
architecture logic of uart is
|
architecture logic of uart is
|
signal uart_data_reg : std_logic_vector(8 downto 0);
|
signal uart_data_reg : std_logic_vector(8 downto 0);
|
signal uart_bits_reg : std_logic_vector(3 downto 0);
|
signal uart_bits_reg : std_logic_vector(3 downto 0);
|
signal uart_div_reg : std_logic_vector(7 downto 0);
|
signal uart_div_reg : std_logic_vector(7 downto 0);
|
|
|
begin
|
begin
|
|
|
uart_proc: process(clk, reset, uart_sel, data,
|
uart_proc: process(clk, reset, uart_sel, data,
|
uart_data_reg, uart_bits_reg, uart_div_reg)
|
uart_data_reg, uart_bits_reg, uart_div_reg)
|
file store_file : text is out save_file_name;
|
|
variable hex_file_line : line;
|
|
variable c : character;
|
|
variable index : natural;
|
|
variable line_length : natural := 0;
|
|
variable uart_data_next : std_logic_vector(8 downto 0);
|
variable uart_data_next : std_logic_vector(8 downto 0);
|
variable uart_bits_next : std_logic_vector(3 downto 0);
|
variable uart_bits_next : std_logic_vector(3 downto 0);
|
variable uart_div_next : std_logic_vector(7 downto 0);
|
variable uart_div_next : std_logic_vector(7 downto 0);
|
begin
|
begin
|
uart_data_next := uart_data_reg;
|
uart_data_next := uart_data_reg;
|
uart_bits_next := uart_bits_reg;
|
uart_bits_next := uart_bits_reg;
|
uart_div_next := uart_div_reg;
|
uart_div_next := uart_div_reg;
|
|
|
if uart_bits_reg = "0000" and uart_sel = '1' then
|
if uart_bits_reg = "0000" and uart_sel = '1' then
|
uart_data_next := '1' & data;
|
uart_data_next := data & '0';
|
uart_bits_next := "1001";
|
uart_bits_next := "1010";
|
uart_div_next := ZERO(7 downto 0);
|
uart_div_next := ZERO(7 downto 0);
|
--"10001100"
|
elsif uart_bits_reg /= "0000" and
|
elsif uart_bits_reg /= "0000" and uart_div_reg = "00000100" then
|
((log_file /= "UNUSED" and uart_div_reg = "00000010") or
|
uart_data_next := uart_data_reg(7 downto 0) & '0';
|
(log_file = "UNUSED" and uart_div_reg = "10001100")) then
|
|
uart_data_next := '1' & uart_data_reg(8 downto 1);
|
uart_bits_next := uart_bits_reg - 1;
|
uart_bits_next := uart_bits_reg - 1;
|
uart_div_next := ZERO(7 downto 0);
|
uart_div_next := ZERO(7 downto 0);
|
else
|
else
|
uart_div_next := uart_div_reg + 1;
|
uart_div_next := uart_div_reg + 1;
|
end if;
|
end if;
|
|
|
if reset = '1' then
|
if reset = '1' then
|
uart_data_next := ZERO(8 downto 0);
|
uart_data_next := ONES(8 downto 0);
|
uart_bits_next := "0000";
|
uart_bits_next := "0000";
|
uart_div_next := ZERO(7 downto 0);
|
uart_div_next := ZERO(7 downto 0);
|
end if;
|
end if;
|
|
|
if rising_edge(clk) then
|
if rising_edge(clk) then
|
|
uart_data_reg <= uart_data_next;
|
|
uart_bits_reg <= uart_bits_next;
|
|
uart_div_reg <= uart_div_next;
|
|
end if;
|
|
|
|
uart_write <= uart_data_reg(0);
|
|
if uart_bits_reg = ZERO(7 downto 0) or uart_sel = '1' then
|
|
pause <= '0';
|
|
elsif log_file = "UNUSED" then
|
|
pause <= '1';
|
|
else
|
|
-- pause <= '1';
|
|
pause <= '0';
|
|
end if;
|
|
end process;
|
|
|
|
uart_logger:
|
|
if log_file /= "UNUSED" generate
|
|
uart_proc: process(clk, uart_sel, data)
|
|
file store_file : text is out log_file;
|
|
variable hex_file_line : line;
|
|
variable c : character;
|
|
variable index : natural;
|
|
variable line_length : natural := 0;
|
|
begin
|
|
if rising_edge(clk) then
|
if uart_sel = '1' then
|
if uart_sel = '1' then
|
-- Debug log file
|
|
index := conv_integer(data(6 downto 0));
|
index := conv_integer(data(6 downto 0));
|
if index /= 10 then
|
if index /= 10 then
|
c := character'val(index);
|
c := character'val(index);
|
write(hex_file_line, c);
|
write(hex_file_line, c);
|
line_length := line_length + 1;
|
line_length := line_length + 1;
|
end if;
|
end if;
|
if index = 10 or line_length >= 72 then
|
if index = 10 or line_length >= 72 then
|
writeline(store_file, hex_file_line);
|
writeline(store_file, hex_file_line);
|
line_length := 0;
|
line_length := 0;
|
end if;
|
end if;
|
end if;
|
end if; --uart_sel
|
|
end if; --rising_edge(clk)
|
uart_data_reg <= uart_data_next;
|
end process; --uart_proc
|
uart_bits_reg <= uart_bits_next;
|
end generate; --uart_logger
|
uart_div_reg <= uart_div_next;
|
|
end if;
|
|
|
|
write_pin <= uart_data_reg(8);
|
|
if uart_bits_reg = ZERO(7 downto 0) or uart_sel = '1' then
|
|
-- pause <= '0';
|
|
else
|
|
-- pause <= '1';
|
|
end if;
|
|
pause <= '0';
|
|
end process;
|
|
|
|
end; --architecture logic
|
end; --architecture logic
|
|
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|