uart_rx: ein prozessmodell. spart weitere 3 logic elements :P
[hwmod.git] / src / beh_pc_communication_tb.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5 use work.textmode_vga_component_pkg.all;
6 use work.textmode_vga_pkg.all;
7 use work.textmode_vga_platform_dependent_pkg.all;
8
9 -- this is for test file io
10 use std.textio.all;
11
12 entity beh_pc_communication_tb is
13 end entity beh_pc_communication_tb;
14
15 architecture sim of beh_pc_communication_tb is
16                 type byte_file_type is file of hbyte;
17                 subtype my_string is string(1 to 720);
18                 signal sys_clk : std_logic;
19                 signal sys_res_n : std_logic;
20                 signal btn_a : std_logic;
21                 signal tx_new : std_logic;
22                 signal tx_done : std_logic;
23                 signal rx_new : std_logic;
24                 signal pc_get : std_logic;
25                 signal pc_done : std_logic;
26                 signal rx_data, tx_data : std_logic_vector(7 downto 0);
27
28                 signal pc_zeile : hzeile;
29                 signal pc_spalte : hspalte;
30                 signal pc_char : hbyte;
31 begin
32         -- pc_communication
33         inst : pc_communication
34         port map (
35                 sys_clk => sys_clk,
36                 sys_res_n => sys_res_n,
37
38                 --button
39                 btn_a => btn_a,
40
41                 --uart_tx
42                 tx_data => tx_data,
43                 tx_new => tx_new,
44                 tx_done => tx_done,
45
46                 --uart_rx
47                 rx_data => rx_data,
48                 rx_new => rx_new,
49
50                 -- History
51                 pc_zeile => pc_zeile,
52                 pc_spalte => pc_spalte,
53                 pc_get => pc_get,
54                 pc_done => pc_done,
55                 pc_char => pc_char
56         );
57
58         clk : process
59         begin
60                 sys_clk <= '0';
61                 wait for 15 ns;
62                 sys_clk <= '1';
63                 wait for 15 ns;
64         end process clk;
65
66         stub_history : process
67                 file f : text open read_mode is "../../src/pc_communication.test";
68                 variable rb : character;
69                 variable good : boolean;
70                 variable i : integer;
71                 variable buf : my_string;
72                 variable l : line;
73         begin
74                 pc_char <= (others => '0');
75                 pc_done <= '0';
76                 wait until sys_res_n = '1';
77
78                 while not endfile (f) loop
79                         readline(f, l);
80                         buf := l.all;
81                         i := 1;
82                         while i < l'length loop
83                                 pc_done <= '0';
84                                 wait until rising_edge(pc_get);
85                                 wait for 150 ns;
86                                 pc_char <= (others => '0');
87                                 wait for 30 ns;
88                                 pc_char <= hbyte(std_logic_vector(to_unsigned(character'pos(buf(i)),8)));
89                                 i := i + 1;
90                                 pc_done <= '1';
91                                 wait for 30 ns;
92                         end loop;
93                 end loop;
94
95                 assert not endfile(f) report "test beendet" severity failure;
96         end process stub_history;
97
98         stub_uart : process
99         begin
100                 tx_done <= '0';
101                 wait until sys_res_n = '1';
102                 while true loop
103                         tx_done <= '0';
104                         wait until rising_edge(tx_new);
105                         wait for 300 ns;
106                         tx_done <= '1';
107                         wait for 30 ns;
108                 end loop;
109         end process stub_uart;
110
111         reset_and_button : process
112         begin
113                 -- init & reset
114                 -- we only simulate pressing of button a by now!
115                 sys_res_n <= '0';
116                 btn_a <= '1';
117                 rx_data <= ( others => '0');
118                 rx_new <= '0';
119                 
120                 wait for 90 ns;
121                 sys_res_n <= '1';
122                 wait for 30 ns;
123                 btn_a <= '0';
124                 wait for 30 ns;
125                 btn_a <= '1';
126                 wait;
127                 --wait for 1000 ns;
128                 --assert false report "test beendet" severity failure;
129         end process reset_and_button;
130
131 end architecture sim;