1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
-- tb_capitalisation.vhd
----------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_capitalisation is
end tb_capitalisation;
architecture behavior of tb_capitalisation is
constant board_clk_period : time := 10 ns;
constant board_clk_freq: integer :=100E6; --100MHz
signal board_clk : std_logic := '0';
signal reset : std_logic := '0';
signal rx : std_logic := '1';
signal tx : std_logic;
procedure tx_char (signal txpin : out std_logic;
txdata : in character; baudrate : in integer) is
constant bittime : time := (integer(1000000000.0/real(baudrate))) * 1 ns;
variable c : std_logic_vector(7 downto 0);
begin
c := std_logic_vector(to_unsigned(character'pos(txdata), 8));
txpin <= '0'; -- Startbit
wait for bittime;
for i in 0 to 7 loop
txpin <= c(i);
wait for bittime;
end loop;
txpin <= '1'; -- Stopbit
wait for bittime;
end tx_char;
-- Component Declaration for the Unit Under Test (UUT)
component top_capitalisation is
generic (clk_freq : integer;
baudrate : integer);
port(
board_clk : in std_logic ;
reset : in std_logic ;
rx : in std_logic ;
tx : out std_logic );
end component;
begin
-- Instantiate the Unit Under Test (UUT)
UART_example: top_capitalisation
generic map (
clk_freq => board_clk_freq,
baudrate =>115200)
port map(
board_clk => board_clk,
reset => reset,
rx => rx,
tx => tx );
process
begin
wait for 80000 ns;
tx_char(RX, '$', 115200);
tx_char(RX, 'g', 115200);
tx_char(RX, '#', 115200);
wait for 50 us;
tx_char(RX, 'b', 115200);
tx_char(RX, 'c', 115200);
wait; -- will wait forever
end process;
-- Clock process definitions
board_clk_process : process
begin
board_clk <= '0';
wait for board_clk_period/2;
board_clk <= '1';
wait for board_clk_period/2;
end process;
-- Stimulus process
process
begin
reset <= '1';
wait for 100 ns;
reset <='0';
wait;
end process;
end;
|