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

Subversion Repositories uart2bus

[/] [uart2bus/] [trunk/] [vhdl/] [bench/] [uart2BusTop_txt_tb.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 smuller
-----------------------------------------------------------------------------------------
2
-- uart test bench   
3
--
4
-----------------------------------------------------------------------------------------
5
use std.textio.all;
6
library ieee;
7
use ieee.std_logic_1164.all;
8
use ieee.std_logic_unsigned.all;
9
use ieee.numeric_std.all;
10
use ieee.std_logic_textio.all;
11
 
12
-----------------------------------------------------------------------------------------
13
-- test bench implementation 
14
entity uart2BusTop_txt_tb is
15
end uart2BusTop_txt_tb;
16
 
17
architecture behavior of uart2BusTop_txt_tb is
18
 
19
  procedure sendSerial(data : integer; baud : in real; parity : in integer; stopbit : in real; bitnumber : in integer; baudError : in real; signal txd : inout std_logic) is
20
 
21
    variable shiftreg : std_logic_vector(7 downto 0);
22
    variable bitTime  : time;
23
 
24
    begin
25
      bitTime := 1000 ms / (baud + baud * baudError / 100.0);
26
      shiftreg := std_logic_vector(to_unsigned(data, shiftreg'length));
27
      txd <= '0';
28
      wait for bitTime;
29
      for index in 0 to bitnumber loop
30
        txd <= shiftreg(index);
31
        wait for bitTime;
32
      end loop;
33
      txd <= '1';
34
      wait for stopbit * bitTime;
35
    end procedure;
36
 
37
  procedure recvSerial( signal rxd : in std_logic; baud : in real; parity : in integer; stopbit : in real; bitnumber : in integer; baudError : in real; signal data : inout std_logic_vector(7 downto 0)) is
38
 
39
    variable bitTime  : time;
40
 
41
    begin
42
      bitTime := 1000 ms / (baud + baud * baudError / 100.0);
43
      wait until (rxd = '0');
44
      wait for bitTime / 2;
45
      wait for bitTime;
46
      for index in 0 to bitnumber loop
47
        data <= rxd & data(7 downto 1);
48
        wait for bitTime;
49
      end loop;
50
      wait for stopbit * bitTime;
51
    end procedure;
52
 
53
  component uart2BusTop
54
    generic
55
    (
56
      AW : integer := 8
57
    );
58
    port
59
    (
60
      clr        : in  std_logic;
61
      clk        : in  std_logic;
62
      serIn      : in  std_logic;
63
      serOut     : out std_logic;
64
      intRdData  : in  std_logic_vector(7 downto 0);
65
      intAddress : out std_logic_vector(7 downto 0);
66
      intWrData  : out std_logic_vector(7 downto 0);
67
      intWrite   : out std_logic;
68
      intRead    : out std_logic
69
    );
70
  end component;
71
 
72
  component regFileModel
73
    port
74
    (
75
      clr        : in  std_logic;
76
      clk        : in  std_logic;
77
      intAddress : in  std_logic_vector(7 downto 0);
78
      intWrData  : in  std_logic_vector(7 downto 0);
79
      intWrite   : in  std_logic;
80
      intRead    : in  std_logic;
81
      intRdData  : out std_logic_vector(7 downto 0));
82
  end component;
83
 
84
  -- Inputs
85
  signal clr            : std_logic := '0';
86
  signal clk            : std_logic := '0';
87
  signal serIn          : std_logic := '0';
88
  signal intRdData      : std_logic_vector(7 downto 0) := (others => '0');
89
 
90
        -- Outputs
91
  signal serOut         : std_logic;
92
  signal intAddress     : std_logic_vector(7 downto 0);
93
  signal intWrData      : std_logic_vector(7 downto 0);
94
  signal intWrite       : std_logic;
95
  signal intRead        : std_logic;
96
  signal recvData       : std_logic_vector(7 downto 0);
97
  signal newRxData      : std_logic;
98
 
99
  constant BAUD_115200  : real := 115200.0;
100
  constant BAUD_38400   : real := 38400.0;
101
  constant BAUD_28800   : real := 28800.0;
102
  constant BAUD_19200   : real := 19200.0;
103
  constant BAUD_9600    : real := 9600.0;
104
  constant BAUD_4800    : real := 4800.0;
105
  constant BAUD_2400    : real := 2400.0;
106
  constant BAUD_1200    : real := 1200.0;
107
 
108
  constant NSTOPS_1     : real := 1.0;
109
  constant NSTOPS_1_5   : real := 1.5;
110
  constant NSTOPS_2     : real := 2.0;
111
 
112
  constant PARITY_NONE  : integer := 0;
113
  constant PARITY_EVEN  : integer := 1;
114
  constant PARITY_ODD   : integer := 2;
115
  constant PARITY_MARK  : integer := 3;
116
  constant PARITY_SPACE : integer := 4;
117
 
118
  constant NBITS_7      : integer := 6;
119
  constant NBITS_8      : integer := 7;
120
 
121
  begin
122
    -- Instantiate the Unit Under Test (UUT)
123
    uut : uart2BusTop
124
      port map
125
      (
126
        clr => clr,
127
        clk => clk,
128
        serIn => serIn,
129
        serOut => serOut,
130
        intRdData => intRdData,
131
        intAddress => intAddress,
132
        intWrData => intWrData,
133
        intWrite => intWrite,
134
        intRead => intRead
135
      );
136
 
137
    rfm : regFileModel
138
    port map
139
    (
140
      clr => clr,
141
      clk => clk,
142
      intRdData => intRdData,
143
      intAddress => intAddress,
144
      intWrData => intWrData,
145
      intWrite => intWrite,
146
      intRead => intRead);
147
 
148
    -- clock generator - 25MHz clock 
149
    process
150
    begin
151
      clk <= '0';
152
      wait for 20 ns;
153
      clk <= '1';
154
      wait for 20 ns;
155
    end process;
156
 
157
    -- reset process definitions
158
    process
159
    begin
160
      clr <= '1';
161
      wait for 40 ns;
162
      clr <= '0';
163
      wait;
164
    end process;
165
 
166
    --------------------------------------------------------------------
167
    -- test bench receiver 
168
    process
169
 
170
    begin
171
      newRxData <= '0';
172
      recvData <= (others => '0');
173
      wait until (clr = '0');
174
      loop
175
        recvSerial(serOut, BAUD_115200, PARITY_NONE, NSTOPS_1, NBITS_8, 0.0, recvData);
176
        newRxData <= '1';
177
        wait for 25 ns;
178
        newRxData <= '0';
179
      end loop;
180
    end process;
181
 
182
    --------------------------------------------------------------------
183
    -- uart transmit - test bench control 
184
    process
185
 
186
      type     dataFile is file of character;
187
      file     testTextFile : dataFile open READ_MODE is "test.txt";
188
      variable charBuf      : character;
189
      variable data         : integer;
190
 
191
    begin
192
          -- default value of serial output 
193
      serIn <= '1';
194
      -- text mode simulation 
195
      write(tempLine, string'("Starting text mode simulation"));
196
      writeline(output, tempLine);
197
      wait until (clr = '0');
198
      wait until (rising_edge(clk));
199
      for index in 0 to 99 loop
200
        wait until (rising_edge(clk));
201
      end loop;
202
      while not endfile(testTextFile) loop
203
        -- transmit the byte in the command file one by one 
204
        read(testTextFile, charBuf);
205
        data := character'pos(charBuf);
206
        sendSerial(data, BAUD_115200, PARITY_NONE, NSTOPS_1, NBITS_8, 0.0, serIn);
207
        wait for 800 us;
208
      end loop;
209
      wait;
210
    end process;
211
  end;

powered by: WebSVN 2.1.0

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