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

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [testOpenCpu.vhd] - Blame information for rev 47

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

Line No. Rev Author Line
1 36 leonardoar
--! @file
2
--! @brief Testbench for OpenCpu top design
3
 
4
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5
LIBRARY ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9
 
10
--! Use CPU Definitions package
11
use work.pkgOpenCPU32.all;
12
 
13 37 leonardoar
--! Adding library for File I/O 
14
-- More information on this site:
15 41 leonardoar
-- http://people.sabanciuniv.edu/erkays/el310/io_10.pdf
16 37 leonardoar
-- http://eesun.free.fr/DOC/vhdlref/refguide/language_overview/test_benches/reading_and_writing_files_with_text_i_o.htm
17 36 leonardoar
use std.textio.ALL;
18
use ieee.std_logic_textio.all;
19
 
20
ENTITY testOpenCpu IS
21 37 leonardoar
generic (n : integer := nBits - 1);                                                                                     --! Generic value (Used to easily change the size of the Alu on the package)
22 36 leonardoar
END testOpenCpu;
23
 
24
--! @brief openCpu Testbench file
25
--! @details This is the top-level test...
26
ARCHITECTURE behavior OF testOpenCpu IS
27
 
28
    --! Component declaration to instantiate the Multiplexer circuit                    
29
    COMPONENT openCpu
30 37 leonardoar
    generic (n : integer := nBits - 1);                                                                 --! Generic value (Used to easily change the size of the Alu on the package)
31
         Port ( rst : in  STD_LOGIC;                                                                                            --! Reset signal
32
           clk : in  STD_LOGIC;                                                                                         --! Clock signal
33
           mem_rd : out  STD_LOGIC;                                                                                     --! Main memory Read enable
34
           mem_rd_addr : out  STD_LOGIC_VECTOR (n downto 0);             --! Main memory Read address
35
           mem_wr : out  STD_LOGIC;                                                                                     --! Main memory Write enable
36
           mem_wr_addr : out  STD_LOGIC_VECTOR (n downto 0);             --! Main memory Write address
37
                          mem_data_in : in  STD_LOGIC_VECTOR (n downto 0);                       --! Data comming from main memory
38
                          mem_data_out : out  STD_LOGIC_VECTOR (n downto 0)              --! Data to main memory
39
                          );
40 36 leonardoar
    END COMPONENT;
41
 
42
 
43
   --Inputs
44 37 leonardoar
   signal rst : std_logic := '0';                                                                                                                --! Wire to connect Test signal to component
45
   signal clk : std_logic := '0';                                                                                                                --! Wire to connect Test signal to component
46
   signal mem_data_in : std_logic_vector(n downto 0) := (others => '0');  --! Wire to connect Test signal to component
47 36 leonardoar
 
48
        --Outputs
49 37 leonardoar
   signal mem_rd : std_logic;                                                                                                                           --! Wire to connect Test signal to component
50
   signal mem_rd_addr : std_logic_vector(n downto 0);                                                            --! Wire to connect Test signal to component
51
   signal mem_wr : std_logic;                                                                                                                           --! Wire to connect Test signal to component
52
   signal mem_wr_addr : std_logic_vector(n downto 0);                                                            --! Wire to connect Test signal to component
53
   signal mem_data_out : std_logic_vector(n downto 0);                                                   --! Wire to connect Test signal to component
54 36 leonardoar
 
55
   -- Clock period definitions
56
   constant clk_period : time := 10 ns;
57
 
58
BEGIN
59
 
60 37 leonardoar
        --! Instantiate the Unit Under Test (openCpu) (Doxygen bug if it's not commented!)
61 36 leonardoar
   uut: openCpu PORT MAP (
62
          rst => rst,
63
          clk => clk,
64
          mem_rd => mem_rd,
65
          mem_rd_addr => mem_rd_addr,
66
          mem_wr => mem_wr,
67
          mem_wr_addr => mem_wr_addr,
68
          mem_data_in => mem_data_in,
69
          mem_data_out => mem_data_out
70
        );
71
 
72
   -- Clock process definitions
73
   clk_process :process
74
   begin
75
                clk <= '0';
76
                wait for clk_period/2;
77
                clk <= '1';
78
                wait for clk_period/2;
79
   end process;
80
 
81
 
82
   -- Stimulus process
83 39 leonardoar
   stim_proc: process
84
        file cmdfile: TEXT;                             -- Define the file 'handle'
85 40 leonardoar
        variable line_in: Line; -- Line buffer
86 39 leonardoar
        variable good: boolean;                         -- Flag to detect a good line read
87
        variable instructionCode : std_logic_vector(n downto 0);
88 36 leonardoar
   begin
89
      -- Reset operation
90 39 leonardoar
                REPORT "RESET" SEVERITY NOTE;
91 40 leonardoar
                -- Open source file for reading...
92 39 leonardoar
                FILE_OPEN(cmdfile,"testCode/testCodeBin.dat",READ_MODE);
93
 
94
                -- Check end of file
95
                if endfile(cmdfile) then
96
                        assert false report "End of file found..." severity failure;
97
                end if;
98
 
99 36 leonardoar
                rst <= '1';
100 45 leonardoar
      wait for 15 ns;
101 36 leonardoar
                rst <= '0';
102 45 leonardoar
                wait for 15 ns;
103
 
104
                while not endfile( cmdfile ) loop
105
                        readline(cmdfile,line_in);                       -- Read a line from the file
106
                        read(line_in,instructionCode,good);     -- Read the CI input
107
                        assert good report "Could not parse the line" severity ERROR;
108
                        mem_data_in <= instructionCode;
109 42 leonardoar
 
110 45 leonardoar
                        wait until mem_rd = '0';
111
                end loop;
112 39 leonardoar
 
113 45 leonardoar
                wait until mem_rd = '0';
114 36 leonardoar
 
115
      -- Finish simulation
116
                assert false report "NONE. End of simulation." severity failure;
117
                wait;
118
   end process;
119
 
120
END;

powered by: WebSVN 2.1.0

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