allgemein: konstanten verwenden
[hwmod.git] / src / pc_communication.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 entity pc_communication is
7         port (
8                 sys_clk : in std_logic;
9                 sys_res_n : in std_logic;
10
11                 --button
12                 btn_a : in std_logic;
13
14                 --uart_tx
15                 tx_data : out std_logic_vector(7 downto 0);
16                 tx_new : out std_logic;
17                 tx_done : in std_logic;
18
19                 --uart_rx
20                 rx_data : in std_logic_vector(7 downto 0);
21                 rx_new : in std_logic;
22
23                 -- History
24                 pc_zeile : out hzeile;
25                 pc_spalte : out hspalte;
26                 pc_get :  out std_logic;
27                 pc_busy : in std_logic; --signals if the history module actually grants our request.
28                 pc_done : in std_logic;
29                 pc_char : in hbyte
30         );
31 end entity pc_communication;
32
33 architecture beh of pc_communication is
34         signal spalte, spalte_next : integer range 1 to HSPALTE_MAX + 1;
35         signal zeile , zeile_next : integer range 1 to HZEILE_MAX + 1;
36         signal get, get_next : std_logic;
37         signal new_i, new_i_next : std_logic;
38         signal tx_done_i, tx_done_i_next : std_logic;
39         signal tx_data_i, tx_data_i_next : std_logic_vector (7 downto 0);
40
41         type STATE_PC is (IDLE, WAIT_HIST, FETCH, FORWARD, WAIT_UART, UART_DONE);
42         signal state, state_next : STATE_PC ;
43
44 begin
45
46
47         pc_zeile <= hzeile(std_logic_vector(to_unsigned(zeile,7)));
48         pc_spalte <= hspalte(std_logic_vector(to_unsigned(spalte,7)));
49         pc_get <= get;
50         tx_new <= new_i;
51         tx_done_i_next <= tx_done;
52         tx_data <= tx_data_i;
53
54         sync: process (sys_clk, sys_res_n)
55         begin
56                 if sys_res_n = '0' then
57                         state <= IDLE;
58                         spalte <= 1;
59                         zeile <= 1;
60                         get <= '0';
61                         new_i <= '0';
62                         tx_data_i <= "00000000";
63                         tx_done_i <= '0';
64                 elsif rising_edge(sys_clk) then
65                         spalte <= spalte_next;
66                         zeile <= zeile_next;
67                         state <= state_next;
68                         get <= get_next;
69                         new_i <= new_i_next;
70                         tx_done_i <= tx_done_i_next;
71                         tx_data_i <= tx_data_i_next;
72                 end if;
73         end process sync;
74
75         output_pc : process (state, zeile, spalte, tx_data_i, tx_done_i, pc_char)
76         begin
77                 get_next <= '0';
78                 new_i_next <= '0';
79
80                 spalte_next <= spalte;
81                 zeile_next <= zeile;
82                 tx_data_i_next <= tx_data_i;
83
84                 case state is
85                         when IDLE =>
86                                 null;
87                         when FETCH =>
88                                 get_next <= '1';
89                         when WAIT_HIST =>
90                                 tx_data_i_next <= pc_char;
91                         when FORWARD =>
92                                 new_i_next <= '1';
93                         when WAIT_UART =>
94                                 new_i_next <= '1';
95                         when UART_DONE =>
96                                 if tx_data_i = x"00" or spalte = HSPALTE_MAX then
97                                         tx_data_i_next <= x"0a";
98                                         zeile_next <= zeile + 1;
99                                         spalte_next <= 1;
100                                         if zeile = HZEILE_MAX then
101                                                 zeile_next <= 1;
102                                         end if;
103                                 else
104                                         spalte_next <= spalte + 1;
105                                 end if;
106                 end case;
107         end process output_pc;
108
109         next_state_pc : process (btn_a, pc_busy, pc_done, rx_new, rx_data, spalte,
110                 state, tx_data_i ,tx_done_i, zeile)
111         begin
112                 state_next <= state;
113                 case state is
114                         when IDLE =>
115 --                              if (rx_new = '1' and rx_data = x"0a") or btn_a = '0' then
116                                 if (rx_new = '1') or btn_a = '0' then
117                                         state_next <= FETCH;
118                                 end if;
119                         when FETCH =>
120                                 if pc_busy = '1' then
121                                         state_next <= WAIT_HIST;
122                                 else
123                                         state_next <= FETCH;
124                                 end if;
125                         when WAIT_HIST =>
126                                 if (pc_done = '1') then
127                                         state_next <= FORWARD;
128                                 end if;
129                         when FORWARD =>
130                                 state_next <= WAIT_UART;
131                         when WAIT_UART =>
132                                 if (tx_done_i = '1') then
133                                         state_next <= UART_DONE;
134                                 end if;
135                         when UART_DONE =>
136                                 if (tx_data_i = x"00" or spalte = HSPALTE_MAX) and
137                                         zeile = HZEILE_MAX then
138                                         state_next <= IDLE;
139                                 else
140                                         state_next <= FETCH;
141                                 end if;
142                 end case;
143         end process next_state_pc;
144
145 end architecture beh;