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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [testUart_communication_block.vhd] - Blame information for rev 39

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 leonardoar
--! @file
2
--! @brief Test communication block
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5 11 leonardoar
LIBRARY ieee;
6
USE ieee.std_logic_1164.ALL;
7 12 leonardoar
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9 11 leonardoar
 
10
--! Use Global Definitions package
11
use work.pkgDefinitions.all;
12
 
13
ENTITY testUart_communication_block IS
14
END testUart_communication_block;
15
 
16 39 leonardoar
--! @brief Test communication block
17
--! @details This will include all blocks used in uart (transmiter, receiver, baud generator)
18 11 leonardoar
ARCHITECTURE behavior OF testUart_communication_block IS
19
 
20
    -- Component Declaration for the Unit Under Test (UUT)
21
 
22
    COMPONENT uart_communication_blocks
23 37 leonardoar
    Port ( rst : in  STD_LOGIC;                                                                                                                 --! Global reset
24
           clk : in  STD_LOGIC;                                                                                                                 --! Global clock
25
                          cycle_wait_baud : in std_logic_vector((nBitsLarge-1) downto 0);        --! Number of cycles to wait in order to generate desired baud
26
           byte_tx : in  STD_LOGIC_VECTOR ((nBits-1) downto 0);                          --! Byte to transmit
27
           byte_rx : out  STD_LOGIC_VECTOR ((nBits-1) downto 0);                         --! Byte to receive
28
           data_sent_tx : out  STD_LOGIC;                                                                                               --! Indicate that byte has been sent
29
           data_received_rx : out  STD_LOGIC;                                                                           --! Indicate that we got a byte
30
                          serial_out : out std_logic;                                                                                                   --! Uart serial out
31
                          serial_in : in std_logic;                                                                                                     --! Uart serial in
32
           start_tx : in  STD_LOGIC);                                                                                                   --! Initiate transmission
33 11 leonardoar
    END COMPONENT;
34
 
35
 
36
   --Inputs
37 37 leonardoar
   signal rst : std_logic := '0';                                                                                                                                                        --! Signal to connect with UUT
38
   signal clk : std_logic := '0';                                                                                                                                                        --! Signal to connect with UUT
39
   signal cycle_wait_baud : std_logic_vector((nBitsLarge-1) downto 0) := (others => '0'); --! Signal to connect with UUT
40
   signal byte_tx : std_logic_vector((nBits-1) downto 0) := (others => '0');                                      --! Signal to connect with UUT
41
   signal serial_in : std_logic := '0';                                                                                                                                  --! Signal to connect with UUT
42
   signal start_tx : std_logic := '0';                                                                                                                                           --! Signal to connect with UUT
43 11 leonardoar
 
44
        --Outputs
45 37 leonardoar
   signal byte_rx : std_logic_vector((nBits-1) downto 0);                                                                                        --! Signal to connect with UUT
46
   signal data_sent_tx : std_logic;                                                                                                                                                     --! Signal to connect with UUT
47
   signal data_received_rx : std_logic;                                                                                                                                 --! Signal to connect with UUT
48
   signal serial_out : std_logic;                                                                                                                                                       --! Signal to connect with UUT
49 11 leonardoar
 
50
   -- Clock period definitions   
51 32 leonardoar
        constant clk_period : time := 20 ns; -- 0.543us (1.8432Mhz) 20ns (50Mhz)
52 11 leonardoar
 
53
BEGIN
54
 
55 36 leonardoar
        --! Instantiate the Unit Under Test (UUT)
56 11 leonardoar
   uut: uart_communication_blocks PORT MAP (
57
          rst => rst,
58
          clk => clk,
59
          cycle_wait_baud => cycle_wait_baud,
60
          byte_tx => byte_tx,
61
          byte_rx => byte_rx,
62
          data_sent_tx => data_sent_tx,
63
          data_received_rx => data_received_rx,
64
          serial_out => serial_out,
65
          serial_in => serial_in,
66
          start_tx => start_tx
67
        );
68
 
69
   -- Clock process definitions
70
   clk_process :process
71
   begin
72
                clk <= '0';
73
                wait for clk_period/2;
74
                clk <= '1';
75
                wait for clk_period/2;
76
   end process;
77
 
78
 
79
   -- Stimulus process
80
   stim_proc: process
81
   begin
82
      -- Setup communication blocks
83
                rst <= '1';
84 12 leonardoar
                serial_in <= '1'; -- Idle..
85 32 leonardoar
                cycle_wait_baud <= conv_std_logic_vector(434, (nBitsLarge));
86 12 leonardoar
                start_tx <= '0';
87 11 leonardoar
      wait for 2 ns;
88
                rst <= '0';
89 12 leonardoar
 
90
                -- Send data..
91
                start_tx <= '1';
92
                byte_tx <= "01010101";
93
                wait until data_sent_tx = '1';
94 11 leonardoar
 
95 12 leonardoar
      wait for clk_period*3;
96
                start_tx <= '0';
97
                wait for clk_period*3;
98
 
99
                start_tx <= '1';
100
                byte_tx <= "11000100";
101
                wait until data_sent_tx = '1';
102
 
103
                wait for clk_period*3;
104
                start_tx <= '0';
105
                wait for clk_period*3;
106
 
107
                -- Receive data...
108
                -- Receive 0x55 value (01010101)
109
                serial_in <= '0'; -- Start bit
110
                wait for 8.68 us;
111
 
112
                serial_in <= '1';
113
      wait for 8.68 us;
114
                serial_in <= '0';
115
      wait for 8.68 us;
116
                serial_in <= '1';
117
      wait for 8.68 us;
118
                serial_in <= '0';
119
      wait for 8.68 us;
120
                serial_in <= '1';
121
      wait for 8.68 us;
122
                serial_in <= '0';
123
      wait for 8.68 us;
124
                serial_in <= '1';
125
      wait for 8.68 us;
126
                serial_in <= '0';
127
      wait for 8.68 us;
128
 
129
                -- Stop bit here
130
                serial_in <= '1';
131 32 leonardoar
                wait for clk_period*200;
132 12 leonardoar
 
133
                -- Receive 0xC4 value (11000100)
134
                serial_in <= '0'; -- Start bit
135
                wait for 8.68 us;
136
 
137
                serial_in <= '0';
138
      wait for 8.68 us;
139
                serial_in <= '0';
140
      wait for 8.68 us;
141
                serial_in <= '1';
142
      wait for 8.68 us;
143
                serial_in <= '0';
144
      wait for 8.68 us;
145
                serial_in <= '0';
146
      wait for 8.68 us;
147
                serial_in <= '0';
148
      wait for 8.68 us;
149
                serial_in <= '1';
150
      wait for 8.68 us;
151
                serial_in <= '1';
152
      wait for 8.68 us;
153
 
154
                -- Stop bit here
155
                serial_in <= '1';
156 32 leonardoar
                wait for clk_period*200;
157 12 leonardoar
 
158
 
159 11 leonardoar
 
160 12 leonardoar
      -- Stop Simulation
161
                assert false report "NONE. End of simulation." severity failure;
162
 
163 11 leonardoar
   end process;
164
 
165
END;

powered by: WebSVN 2.1.0

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