OpenCores
URL https://opencores.org/ocsvn/simple_uart_for_fpga/simple_uart_for_fpga/trunk

Subversion Repositories simple_uart_for_fpga

[/] [simple_uart_for_fpga/] [trunk/] [source/] [uart_tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jakubcabal
--------------------------------------------------------------------------------
2
-- PROJECT: SIMPLE UART FOR FPGA
3
--------------------------------------------------------------------------------
4
-- MODULE:  TESTBANCH OF UART TOP MODULE
5
-- AUTHORS: Jakub Cabal <jakubcabal@gmail.com>
6
-- lICENSE: The MIT License (MIT)
7
-- WEBSITE: https://github.com/jakubcabal/uart_for_fpga
8
--------------------------------------------------------------------------------
9
 
10
library IEEE;
11
use IEEE.STD_LOGIC_1164.ALL;
12
use IEEE.NUMERIC_STD.ALL;
13
 
14
entity UART_TB is
15
end UART_TB;
16
 
17
architecture FULL of UART_TB is
18
 
19
        signal CLK           : std_logic := '0';
20
        signal RST           : std_logic := '0';
21
        signal tx_uart       : std_logic;
22
        signal rx_uart       : std_logic := '1';
23
        signal data_vld      : std_logic;
24
        signal data_out      : std_logic_vector(7 downto 0);
25
        signal frame_error   : std_logic;
26
        signal data_send     : std_logic;
27
        signal busy          : std_logic;
28
        signal data_in       : std_logic_vector(7 downto 0);
29
 
30
    constant clk_period  : time := 20 ns;
31
        constant uart_period : time := 8680.56 ns;
32
        constant data_value  : std_logic_vector(7 downto 0) := "10100111";
33
        constant data_value2 : std_logic_vector(7 downto 0) := "00110110";
34
 
35
begin
36
 
37
        utt: entity work.UART
38
    generic map (
39
        CLK_FREQ    => 50e6,
40
        BAUD_RATE   => 115200,
41
        PARITY_BIT  => "none"
42
    )
43
    port map (
44
        CLK         => CLK,
45
        RST         => RST,
46
        -- UART INTERFACE
47
        UART_TXD    => tx_uart,
48
        UART_RXD    => rx_uart,
49
        -- USER DATA INPUT INTERFACE
50
        DATA_OUT    => data_out,
51
        DATA_VLD    => data_vld,
52
        FRAME_ERROR => frame_error,
53
        -- USER DATA OUTPUT INTERFACE
54
        DATA_IN     => data_in,
55
        DATA_SEND   => data_send,
56
        BUSY        => busy
57
    );
58
 
59
        clk_process : process
60
        begin
61
                CLK <= '0';
62
                wait for clk_period/2;
63
                CLK <= '1';
64
                wait for clk_period/2;
65
        end process;
66
 
67
        test_rx_uart : process
68
        begin
69
                rx_uart <= '1';
70
                RST <= '1';
71
                wait for 100 ns;
72
        RST <= '0';
73
 
74
                wait until rising_edge(CLK);
75
 
76
                rx_uart <= '0'; -- start bit
77
                wait for uart_period;
78
 
79
                for i in 0 to (data_value'LENGTH-1) loop
80
                        rx_uart <= data_value(i); -- data bits
81
                        wait for uart_period;
82
                end loop;
83
 
84
                rx_uart <= '1'; -- stop bit
85
                wait for uart_period;
86
 
87
                rx_uart <= '0'; -- start bit
88
                wait for uart_period;
89
 
90
                for i in 0 to (data_value2'LENGTH-1) loop
91
                        rx_uart <= data_value2(i); -- data bits
92
                        wait for uart_period;
93
                end loop;
94
 
95
                rx_uart <= '1'; -- stop bit
96
                wait for uart_period;
97
 
98
                wait;
99
 
100
        end process;
101
 
102
        test_tx_uart : process
103
        begin
104
                data_send <= '0';
105
                RST <= '1';
106
                wait for 100 ns;
107
        RST <= '0';
108
 
109
                wait until rising_edge(CLK);
110
 
111
                data_send <= '1';
112
                data_in <= data_value;
113
 
114
                wait until rising_edge(CLK);
115
 
116
                data_send <= '0';
117
 
118
                wait until rising_edge(CLK);
119
 
120
                wait for 80 us;
121
                wait until rising_edge(CLK);
122
 
123
                data_send <= '1';
124
                data_in <= data_value2;
125
 
126
                wait until rising_edge(CLK);
127
 
128
                data_send <= '0';
129
 
130
                wait until rising_edge(CLK);
131
 
132
                wait;
133
 
134
        end process;
135
 
136
end FULL;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.