2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 --use work.gen_pkg.all;
7 -- type STATE_UART_RX is (IDLE, BUSY, DONE);
8 --end package int_types;
12 sys_clk : in std_logic;
13 sys_res : in std_logic;
14 txd : in std_logic; -- warning: this is asynchronous input!
15 tx_data : out std_logic_vector(7 downto 0); -- map this to a larger register with containing input
16 tx_new : out std_logic;
20 architecture beh of uart_rx is
21 constant timer_max : integer := 35;
23 signal timer, timer_next : integer range 0 to 65535;
24 signal counter, counter_next : integer range 0 to 15;
25 signal state, state_next : STATE_UART_RX;
26 signal tx_data_pref : std_logic_vector(7 downto 0); -- FIXME: this isnt named next so that the interface isn't called tx_data_next ...
30 process(sys_clk, sys_res_n)
32 if sys_res_n = ‘0‘ then
36 elsif rising_edge(sys_clk) then
39 tx_data_prev <= tx_data;
43 process(state, txd, counter)
54 if (counter = 9) then --FIXME: is this true?
70 -- Calculate the outputs
71 -- based on the current
79 tx_data(counter-2) <= txd;
85 -- END FIXME: do fill this out CORRECTLY
87 process (sys_clk, sys_res)
92 elsif rising_edge(sys_clk) then
93 counter <= counter_next;
100 if (timer = timer_max) then
103 timer_next <= timer + 1;
107 process (timer, counter, tx_new)
109 if (tx_new = '1') then
110 if (timer = timer_max) then
111 if (counter > 10) then
114 counter_next <= counter + 1;
117 counter_next <= counter;
124 process (counter, txd)
126 tx_data <= tx_data_prev;
127 -- TODO: we probably want oversampling and averaging + failure!
128 -- FIXME: this is per se not synthesisable
130 when 0 => --start bit
148 when 9 => -- stop bit
150 when others => -- idle
157 end architecture beh;