initial counter working
[hwmod.git] / src / uart_tx.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 --use work.gen_pkg.all;
5
6 --package int_types is
7 --      type STATE_UART_TX is (IDLE, STARTBITS, PAYLOAD, PARITY, STOP, DONE);
8 --      type PARITY_TYPE is (ODD, EVEN, NONE);
9 --end package int_types;
10
11 entity uart_tx is
12 port(
13         sys_clk : in std_logic;
14         sys_res : in std_logic;
15         --txd : out std_logic;
16         --tx_data : in std_logic;
17         tx_new : in std_logic;
18         tx_done : out std_logic
19 );
20 end entity uart_tx;
21
22 architecture beh of uart_tx is
23         signal timer : integer range 0 to 65535;
24         signal timer_next : integer range 0 to 65535;
25         constant timer_max : integer := 35;
26         signal counter : integer;
27         signal counter_next : integer;
28 begin
29         process (sys_clk, sys_res)
30         begin
31                 if sys_res = '0' then
32                         counter <= 0;
33                         timer <= 0;
34                 elsif rising_edge(sys_clk) then
35                         counter <= counter_next;
36                         timer <= timer_next;
37                 end if;
38         end process;
39
40
41         process (timer, counter)
42         begin
43                 if (timer = timer_max) then
44                         timer_next <= 0;
45                         counter_next <= counter + 1;
46                 else
47                         timer_next <= timer + 1;
48                         counter_next <= counter;
49                 end if;
50         end process;
51
52         tx_done <= '0';
53
54 end architecture beh;