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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [testSerial_receiver.vhd] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 leonardoar
--! @file
2
--! @brief Test serial_receiver module module
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5 2 leonardoar
LIBRARY ieee;
6
USE ieee.std_logic_1164.ALL;
7
 
8
--! Use CPU Definitions package
9
use work.pkgDefinitions.all;
10
 
11
ENTITY testSerial_receiver IS
12
END testSerial_receiver;
13
 
14 38 leonardoar
--! @brief Test serial_receiver module module
15
--! @details Receive some simulated byte stream and verify received values
16 2 leonardoar
ARCHITECTURE behavior OF testSerial_receiver IS
17
 
18
    -- Component Declaration for the Unit Under Test (UUT)
19
 
20
    COMPONENT serial_receiver
21 37 leonardoar
   Port (
22
                          rst : in STD_LOGIC;                                                                                                   --! Reset input           
23
                          baudOverSampleClk : in  STD_LOGIC;                                                            --! Baud oversampled 8x (Best way to detect start bit)
24
           serial_in : in  STD_LOGIC;                                                                                   --! Uart serial input
25
           data_ready : out  STD_LOGIC;                                                                         --! Data received and ready to be read
26
           data_byte : out  STD_LOGIC_VECTOR ((nBits-1) downto 0));      --! Data byte received
27 2 leonardoar
    END COMPONENT;
28
 
29
 
30
   --Inputs
31 37 leonardoar
   signal rst : std_logic := '0';                                        --! Signal to connect with UUT
32
   signal baudClk : std_logic := '0';                            --! Signal to connect with UUT
33
   signal baudOverSampleClk : std_logic := '0';  --! Signal to connect with UUT
34
   signal serial_in : std_logic := '0';                  --! Signal to connect with UUT
35 2 leonardoar
 
36
        --Outputs
37 37 leonardoar
   signal data_ready : std_logic;                                                                       --! Signal to connect with UUT
38
   signal data_byte : std_logic_vector((nBits-1) downto 0);      --! Signal to connect with UUT
39 2 leonardoar
 
40
   -- Clock period definitions
41
   constant baudClk_period : time := 8.6805 us;
42 35 leonardoar
   constant baudOverSampleClk_period : time :=1.085 us;
43 2 leonardoar
 
44
BEGIN
45
 
46 36 leonardoar
        --! Instantiate the Unit Under Test (UUT)
47 2 leonardoar
   uut: serial_receiver PORT MAP (
48 35 leonardoar
          rst => rst,
49 2 leonardoar
          baudOverSampleClk => baudOverSampleClk,
50
          serial_in => serial_in,
51
          data_ready => data_ready,
52
          data_byte => data_byte
53
        );
54
 
55
   -- Clock process definitions
56
   baudClk_process :process
57
   begin
58
                baudClk <= '0';
59
                wait for baudClk_period/2;
60
                baudClk <= '1';
61
                wait for baudClk_period/2;
62
   end process;
63
 
64
   baudOverSampleClk_process :process
65
   begin
66
                baudOverSampleClk <= '0';
67
                wait for baudOverSampleClk_period/2;
68
                baudOverSampleClk <= '1';
69
                wait for baudOverSampleClk_period/2;
70
   end process;
71
 
72
 
73
   -- Stimulus process
74
   stim_proc: process
75
   begin
76
      rst <= '1';
77
                serial_in <= '1';       -- Idle
78
      wait for 3 us;
79
                rst <= '0';
80
                wait for baudClk_period * 3;
81
 
82
                -- Receive 0xC4 value (11000100)
83
                -- Start bit here
84
                serial_in <= '0';
85
                wait for baudClk_period;
86
 
87
                serial_in <= '0';
88
      wait for baudClk_period;
89
                serial_in <= '0';
90
      wait for baudClk_period;
91
                serial_in <= '1';
92
      wait for baudClk_period;
93
                serial_in <= '0';
94
      wait for baudClk_period;
95
                serial_in <= '0';
96
      wait for baudClk_period;
97
                serial_in <= '0';
98
      wait for baudClk_period;
99
                serial_in <= '1';
100
      wait for baudClk_period;
101
                serial_in <= '1';
102
      wait for baudClk_period;
103
 
104
                -- Stop bit here
105 38 leonardoar
                serial_in <= '1';
106
                ---wait until data_ready = '1';
107
                assert data_byte = X"C4" report "Wrong result... expected 0xC4" severity failure;
108 15 leonardoar
                wait for baudClk_period * 8;
109 3 leonardoar
 
110
                -- Receive 0x55 value (01010101)
111
                -- Start bit here
112
                serial_in <= '0';
113
                wait for baudClk_period;
114
 
115
                serial_in <= '1';
116
      wait for baudClk_period;
117
                serial_in <= '0';
118
      wait for baudClk_period;
119
                serial_in <= '1';
120
      wait for baudClk_period;
121
                serial_in <= '0';
122
      wait for baudClk_period;
123
                serial_in <= '1';
124
      wait for baudClk_period;
125
                serial_in <= '0';
126
      wait for baudClk_period;
127
                serial_in <= '1';
128
      wait for baudClk_period;
129
                serial_in <= '0';
130
      wait for baudClk_period;
131
 
132
                -- Stop bit here
133
                serial_in <= '1';
134 4 leonardoar
                wait for baudClk_period * 1;
135 38 leonardoar
                ---wait until data_ready = '1';
136
                assert data_byte = X"55" report "Wrong result... expected 0x55" severity failure;
137 2 leonardoar
 
138
      -- Stop Simulation
139
                assert false report "NONE. End of simulation." severity failure;
140
 
141
      wait;
142
   end process;
143
 
144
END;

powered by: WebSVN 2.1.0

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