first data receive, data garbage
[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 pc_busy : std_logic;
27                 signal rx_data, tx_data : std_logic_vector(7 downto 0);
28
29                 signal pc_zeile : hzeile;
30                 signal pc_spalte : hspalte;
31                 signal pc_char : hbyte;
32 begin
33         -- pc_communication
34         inst : entity work.pc_communication(beh)
35         port map (
36                 sys_clk => sys_clk,
37                 sys_res_n => sys_res_n,
38
39                 --button
40                 btn_a => btn_a,
41
42                 --uart_tx
43                 tx_data => tx_data,
44                 tx_new => tx_new,
45                 tx_done => tx_done,
46
47                 --uart_rx
48                 rx_data => rx_data,
49                 rx_new => rx_new,
50
51                 -- History
52                 pc_zeile => pc_zeile,
53                 pc_spalte => pc_spalte,
54                 pc_get => pc_get,
55                 pc_done => pc_done,
56                 pc_busy => pc_busy,
57                 pc_char => pc_char
58         );
59
60         clk : process
61         begin
62                 sys_clk <= '0';
63                 wait for 15 ns;
64                 sys_clk <= '1';
65                 wait for 15 ns;
66         end process clk;
67
68         stub_history : process
69                 file f : text open read_mode is "../../src/pc_communication.test";
70                 variable rb : character;
71                 variable good : boolean;
72                 variable i : integer;
73                 variable buf : my_string;
74                 variable l : line;
75         begin
76                 pc_char <= (others => '0');
77                 pc_done <= '0';
78                 pc_busy <= '0';
79                 wait until sys_res_n = '1';
80
81                 while not endfile (f) loop
82                         readline(f, l);
83                         buf := l.all;
84                         i := 1;
85                         while i < l'length loop
86                                 pc_done <= '0';
87                                 wait until rising_edge(pc_get);
88                                 wait for 150 ns;
89                                 pc_char <= (others => '0');
90                                 pc_busy <= '1';
91                                 wait for 30 ns;
92                                 pc_char <= hbyte(std_logic_vector(to_unsigned(character'pos(buf(i)),8)));
93                                 i := i + 1;
94                                 pc_busy <= '0';
95                                 pc_done <= '1';
96                                 wait for 30 ns;
97                         end loop;
98                 end loop;
99
100                 assert not endfile(f) report "test beendet" severity failure;
101         end process stub_history;
102
103         stub_uart : process
104         begin
105                 tx_done <= '0';
106                 wait until sys_res_n = '1';
107                 while true loop
108                         tx_done <= '0';
109                         wait until rising_edge(tx_new);
110                         wait for 300 ns;
111                         tx_done <= '1';
112                         wait for 30 ns;
113                 end loop;
114         end process stub_uart;
115
116         reset_and_button : process
117         begin
118                 -- init & reset
119                 -- we only simulate pressing of button a by now!
120                 sys_res_n <= '0';
121                 btn_a <= '1';
122                 rx_data <= ( others => '0');
123                 rx_new <= '0';
124                 
125                 wait for 90 ns;
126                 sys_res_n <= '1';
127                 wait for 30 ns;
128                 btn_a <= '0';
129                 wait for 30 ns;
130                 btn_a <= '1';
131                 wait;
132                 --wait for 1000 ns;
133                 --assert false report "test beendet" severity failure;
134         end process reset_and_button;
135
136 end architecture sim;