2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
6 entity pc_communication is
8 sys_clk : in std_logic;
9 sys_res_n : in std_logic;
13 tx_data : out std_logic_vector(7 downto 0);
14 tx_new : out std_logic;
15 tx_done : in std_logic;
17 rx_data : in std_logic_vector(7 downto 0);
18 rx_new : in std_logic;
20 pc_zeile : out hzeile;
21 pc_spalte : out hspalte;
22 pc_get : out std_logic;
23 pc_done : in std_logic;
26 end entity pc_communication;
28 architecture beh of pc_communication is
29 signal spalte, spalte_next : integer range 1 to HSPALTE_MAX + 2;
30 signal zeile , zeile_next : integer range 0 to HZEILE_MAX + 1;
31 signal get, get_next : std_logic;
32 signal new_i, new_i_next : std_logic;
33 signal tx_done_i, tx_done_i_next : std_logic;
34 signal tx_data_i, tx_data_i_next : std_logic_vector (7 downto 0);
36 type STATE_PC is (IDLE, FETCH, FORWARD, UART_DONE, CR, CR_WAIT,
37 NL, NL_WAIT, PRINT_NO1, PRINT_NO1_WAIT, PRINT_NO2, PRINT_NO2_WAIT,
38 PRINT_NO3, PRINT_NO3_WAIT, PRINT_NO4, PRINT_NO4_WAIT, PRINT_NO5,
39 PRINT_NO5_WAIT, PRINT_NO6);
40 signal state, state_next : STATE_PC ;
42 pc_zeile <= hzeile(std_logic_vector(to_unsigned(zeile,7)));
43 pc_spalte <= hspalte(std_logic_vector(to_unsigned(spalte,7)));
46 tx_done_i_next <= tx_done;
49 sync: process (sys_clk, sys_res_n)
51 if sys_res_n = '0' then
59 elsif rising_edge(sys_clk) then
60 spalte <= spalte_next;
65 tx_done_i <= tx_done_i_next;
66 tx_data_i <= tx_data_i_next;
70 process (state, zeile, spalte, tx_data_i, tx_done_i, pc_char, rx_new, btn_a,
72 variable tmp : std_logic_vector(6 downto 0);
76 spalte_next <= spalte;
78 tx_data_i_next <= tx_data_i;
85 if ((rx_new = '1' and rx_data = x"41") or btn_a = '0') and tx_done_i = '0' then
86 state_next <= PRINT_NO1;
90 tx_data_i_next <= x"28"; -- '('
92 if tx_done_i = '1' then
93 state_next <= PRINT_NO1_WAIT;
95 when PRINT_NO1_WAIT =>
96 if tx_done_i = '0' then
97 state_next <= PRINT_NO2;
100 tx_data_i_next <= zeile2char(std_logic_vector(to_unsigned(zeile,7)), 1);
102 if tx_done_i = '1' then
103 state_next <= PRINT_NO2_WAIT;
105 when PRINT_NO2_WAIT =>
106 if tx_done_i = '0' then
107 state_next <= PRINT_NO3;
110 tx_data_i_next <= zeile2char(std_logic_vector(to_unsigned(zeile,7)), 2);
112 if tx_done_i = '1' then
113 state_next <= PRINT_NO3_WAIT;
115 when PRINT_NO3_WAIT =>
116 if tx_done_i = '0' then
117 state_next <= PRINT_NO4;
120 tx_data_i_next <= x"29"; -- ')'
122 if tx_done_i = '1' then
123 state_next <= PRINT_NO4_WAIT;
125 when PRINT_NO4_WAIT =>
126 if tx_done_i = '0' then
127 state_next <= PRINT_NO5;
130 tx_data_i_next <= x"24"; -- '$'
132 if tx_done_i = '1' then
133 state_next <= PRINT_NO5_WAIT;
135 when PRINT_NO5_WAIT =>
136 if tx_done_i = '0' then
137 state_next <= PRINT_NO6;
140 tx_data_i_next <= x"20"; -- ' '
142 if tx_done_i = '1' then
148 if pc_done = '1' and tx_done_i = '0' then
149 state_next <= FORWARD;
150 if pc_char = x"00" then
151 state_next <= UART_DONE;
155 tx_data_i_next <= pc_char;
157 -- halte pc_get weiterhin high sodass pc_char garantiert
158 -- gleicht bleibt (blockiert history!)
160 if tx_done_i = '1' then
161 state_next <= UART_DONE;
164 if tx_done_i = '0' then
166 spalte_next <= spalte + 1;
167 if spalte = HSPALTE_MAX + 1 then
170 zeile_next <= zeile + 1;
174 tx_data_i_next <= x"0a";
176 if tx_done_i = '1' then
177 state_next <= NL_WAIT;
180 if tx_done_i = '0' then
184 tx_data_i_next <= x"0d";
186 if tx_done_i = '1' then
187 state_next <= CR_WAIT;
190 if tx_done_i = '0' then
191 tmp := std_logic_vector(to_unsigned(zeile,7));
193 -- es handelt sich um eingabe im naechsten schritt
194 -- => print zeilennummer
195 state_next <= PRINT_NO1;
200 if zeile = HZEILE_MAX then
205 end architecture beh;