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;
15 tx_data : out std_logic_vector(7 downto 0);
16 tx_new : out std_logic;
17 tx_done : in std_logic;
20 rx_data : in std_logic_vector(7 downto 0);
21 rx_new : in std_logic;
24 pc_zeile : out hzeile;
25 pc_spalte : out hspalte;
26 pc_get : out std_logic;
27 pc_done : in std_logic;
30 end entity pc_communication;
32 architecture beh of pc_communication is
33 signal spalte, spalte_next : integer range 1 to HSPALTE_MAX + 2;
34 signal zeile , zeile_next : integer range 0 to HZEILE_MAX + 1;
35 signal get, get_next : std_logic;
36 signal new_i, new_i_next : std_logic;
37 signal tx_done_i, tx_done_i_next : std_logic;
38 signal tx_data_i, tx_data_i_next : std_logic_vector (7 downto 0);
40 type STATE_PC is (IDLE, FETCH, FORWARD, WAIT_UART, UART_DONE, CR, CR_WAIT,
41 NL, NL_WAIT, PRINT_NO1, PRINT_NO1_WAIT, PRINT_NO2, PRINT_NO2_WAIT,
42 PRINT_NO3, PRINT_NO3_WAIT, PRINT_NO4, PRINT_NO4_WAIT, PRINT_NO5,
43 PRINT_NO5_WAIT, PRINT_NO6, PRINT_NO0_WAIT);
44 signal state, state_next : STATE_PC ;
46 pc_zeile <= hzeile(std_logic_vector(to_unsigned(zeile,7)));
47 pc_spalte <= hspalte(std_logic_vector(to_unsigned(spalte,7)));
50 tx_done_i_next <= tx_done;
53 sync: process (sys_clk, sys_res_n)
55 if sys_res_n = '0' then
63 elsif rising_edge(sys_clk) then
64 spalte <= spalte_next;
69 tx_done_i <= tx_done_i_next;
70 tx_data_i <= tx_data_i_next;
74 process (state, zeile, spalte, tx_data_i, tx_done_i, pc_char, rx_new, btn_a,
76 variable tmp : std_logic_vector(6 downto 0);
80 spalte_next <= spalte;
82 tx_data_i_next <= tx_data_i;
87 -- if (rx_new = '1' and rx_data = x"0a") or btn_a = '0' then
88 if (rx_new = '1') or btn_a = '0' then
89 state_next <= PRINT_NO0_WAIT;
92 when PRINT_NO0_WAIT =>
93 if tx_done_i = '0' then
94 state_next <= PRINT_NO1;
97 tx_data_i_next <= x"28"; -- '('
99 if tx_done_i = '1' then
100 state_next <= PRINT_NO1_WAIT;
102 when PRINT_NO1_WAIT =>
103 if tx_done_i = '0' then
104 state_next <= PRINT_NO2;
107 tx_data_i_next <= zeile2char(std_logic_vector(to_unsigned(zeile,7)), 1);
109 if tx_done_i = '1' then
110 state_next <= PRINT_NO2_WAIT;
112 when PRINT_NO2_WAIT =>
113 if tx_done_i = '0' then
114 state_next <= PRINT_NO3;
117 tx_data_i_next <= zeile2char(std_logic_vector(to_unsigned(zeile,7)), 2);
119 if tx_done_i = '1' then
120 state_next <= PRINT_NO3_WAIT;
122 when PRINT_NO3_WAIT =>
123 if tx_done_i = '0' then
124 state_next <= PRINT_NO4;
127 tx_data_i_next <= x"29"; -- ')'
129 if tx_done_i = '1' then
130 state_next <= PRINT_NO4_WAIT;
132 when PRINT_NO4_WAIT =>
133 if tx_done_i = '0' then
134 state_next <= PRINT_NO5;
137 tx_data_i_next <= x"24"; -- '$'
139 if tx_done_i = '1' then
140 state_next <= PRINT_NO5_WAIT;
142 when PRINT_NO5_WAIT =>
143 if tx_done_i = '0' then
144 state_next <= PRINT_NO6;
147 tx_data_i_next <= x"20"; -- ' '
149 if tx_done_i = '1' then
155 if pc_done = '1' and tx_done_i = '0' then
156 state_next <= FORWARD;
157 if pc_char = x"00" then
158 state_next <= UART_DONE;
162 tx_data_i_next <= pc_char;
164 -- halte pc_get weiterhin high sodass pc_char garantiert gleich bleibt
166 state_next <= WAIT_UART;
170 if tx_done_i = '1' then
171 state_next <= UART_DONE;
175 spalte_next <= spalte + 1;
176 if spalte = HSPALTE_MAX + 1 then
179 zeile_next <= zeile + 1;
182 tx_data_i_next <= x"0a";
184 if tx_done_i = '1' then
185 state_next <= NL_WAIT;
190 tx_data_i_next <= x"0d";
192 if tx_done_i = '1' then
193 state_next <= CR_WAIT;
196 tmp := std_logic_vector(to_unsigned(zeile,7));
198 -- es handelt sich um eingabe
199 -- => print zeilennummer
200 state_next <= PRINT_NO0_WAIT;
204 if zeile = HZEILE_MAX then
211 end architecture beh;