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

Subversion Repositories bitserial

[/] [bitserial/] [trunk/] [tb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 howe.r.j.8
-- File:        tb.vhd
2
-- Author:      Richard James Howe
3
-- Repository:  https://github.com/howerj/bit-serial
4
-- License:     MIT
5
-- Description: Test bench for top level entity
6
 
7
library ieee, work, std;
8
use ieee.std_logic_1164.all;
9
use ieee.numeric_std.all;
10
use work.util.all;
11
use std.textio.all;
12
 
13
entity tb is
14
end tb;
15
 
16
architecture testing of tb is
17
        constant g: common_generics           := default_settings;
18
        constant clock_period:       time     := 1000 ms / g.clock_frequency;
19
        constant baud:               positive := 115200 * 10; -- speed up TX/RX for simulation
20
        shared variable clocks:      integer  := 10000;
21
        shared variable forever:     integer  := 0;
22
        shared variable debug:       integer  := 1;
23
        constant N:                  positive := 16;
24
 
25
        signal ld: std_ulogic_vector(7 downto 0) := (others => '0');
26
        signal sw: std_ulogic_vector(7 downto 0) := x"AA";
27
        signal stop:   boolean    := false;
28
        signal clk:    std_ulogic := '0';
29
        signal halt:   std_ulogic := '0';
30
        signal rst:    std_ulogic := '1';
31
        signal tx, rx: std_ulogic := '0';
32
 
33
        impure function configure(the_file_name: in string) return boolean is
34
                file     in_file: text is in the_file_name;
35
                variable in_line: line;
36
                variable i:       integer;
37
        begin
38
                if endfile(in_file) then return false; end if;
39
                readline(in_file, in_line); read(in_line, i);
40
                clocks := i;
41
                readline(in_file, in_line); read(in_line, i);
42
                forever := i;
43
                readline(in_file, in_line); read(in_line, i);
44
                debug := i;
45
                return true;
46
        end function;
47
 
48
        signal configured: boolean := configure("tb.conf");
49
begin
50
        uut: entity work.top
51
                generic map(
52
                        g          => g,
53
                        file_name  => "bit.hex",
54
                        N          => N,
55
                        baud       => baud,
56
                        debug      => debug)
57
                port map (
58
                        clk  => clk,
59
--                      rst  => rst,
60
                        halt => halt,
61
                        ld   => ld,
62
                        sw   => sw,
63
                        tx   => tx,
64
                        rx   => rx);
65
 
66
        clock_process: process
67
                variable count: integer := 0;
68
                variable ll: line;
69
 
70
        begin
71
                rst  <= '1';
72
                stop <= false;
73
                wait for clock_period;
74
                rst  <= '0';
75
                while (count < clocks or forever /= 0)  and halt = '0' loop
76
                        clk <= '1';
77
                        wait for clock_period / 2;
78
                        clk <= '0';
79
                        wait for clock_period / 2;
80
                        count := count + 1;
81
                end loop;
82
                if halt = '1' then
83
                        write(ll, string'("{HALT}"));
84
                else
85
                        write(ll, string'("{CYCLES}"));
86
                end if;
87
 
88
                if debug > 0 then
89
                        writeline(OUTPUT, ll);
90
                end if;
91
 
92
                stop <= true;
93
                wait;
94
        end process;
95
 
96
        stimulus_process: process
97
        begin
98
                while stop = false loop
99
                        wait for clock_period;
100
                end loop;
101
                wait;
102
        end process;
103
end architecture;
104
 

powered by: WebSVN 2.1.0

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