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

Subversion Repositories opencpu32

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

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
      wait for 2 ns;
101
                rst <= '0';
102 42 leonardoar
                wait for 2 ns;
103
 
104 39 leonardoar
                readline(cmdfile,line_in);                       -- Read a line from the file
105
                read(line_in,instructionCode,good);     -- Read the CI input
106
                assert good report "Could not parse the line" severity ERROR;
107 42 leonardoar
                mem_data_in <= instructionCode;
108
 
109
      wait until mem_rd = '0';
110
 
111 39 leonardoar
                readline(cmdfile,line_in);                       -- Read a line from the file
112
                read(line_in,instructionCode,good);     -- Read the CI input
113
                assert good report "Could not parse the line" severity ERROR;
114
                mem_data_in <= instructionCode;
115 36 leonardoar
 
116 42 leonardoar
      wait until mem_rd = '0';
117
 
118 39 leonardoar
                readline(cmdfile,line_in);                       -- Read a line from the file
119
                read(line_in,instructionCode,good);     -- Read the CI input
120
                assert good report "Could not parse the line" severity ERROR;
121 42 leonardoar
                mem_data_in <= instructionCode;
122 39 leonardoar
 
123 42 leonardoar
                wait until mem_rd = '0';
124 39 leonardoar
 
125
                readline(cmdfile,line_in);                       -- Read a line from the file
126
                read(line_in,instructionCode,good);     -- Read the CI input
127
                assert good report "Could not parse the line" severity ERROR;
128
                mem_data_in <= instructionCode;
129
 
130 42 leonardoar
                wait until mem_rd = '0';
131 39 leonardoar
 
132
                readline(cmdfile,line_in);                       -- Read a line from the file
133
                read(line_in,instructionCode,good);     -- Read the CI input
134
                assert good report "Could not parse the line" severity ERROR;
135
                mem_data_in <= instructionCode;
136
 
137 42 leonardoar
                wait until mem_rd = '0';
138 39 leonardoar
 
139
                readline(cmdfile,line_in);                       -- Read a line from the file
140
                read(line_in,instructionCode,good);     -- Read the CI input
141
                assert good report "Could not parse the line" severity ERROR;
142
                mem_data_in <= instructionCode;
143
 
144
                wait for CLK_period;
145 36 leonardoar
 
146
      -- Finish simulation
147
                assert false report "NONE. End of simulation." severity failure;
148
                wait;
149
   end process;
150
 
151
END;

powered by: WebSVN 2.1.0

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