OpenCores
URL https://opencores.org/ocsvn/hpc-16/hpc-16/trunk

Subversion Repositories hpc-16

[/] [hpc-16/] [trunk/] [impl0/] [sim/] [testbench/] [test2.vhd] - Blame information for rev 18

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

Line No. Rev Author Line
1 5 umairsiddi
--------------------------------------------------------------
2
-- test2.vhd
3
--------------------------------------------------------------
4
-- project: HPC-16 Microprocessor
5
--
6
-- usage: basic testbench top-level
7
--
8
-- dependency: cpu.vhd, ramNx16.vhd
9
--
10
-- Author: M. Umair Siddiqui (umairsiddiqui@opencores.org)
11
---------------------------------------------------------------
12
------------------------------------------------------------------------------------
13
--                                                                                --
14
--    Copyright (c) 2005, M. Umair Siddiqui all rights reserved                   --
15
--                                                                                --
16
--    This file is part of HPC-16.                                                --
17
--                                                                                --
18
--    HPC-16 is free software; you can redistribute it and/or modify              --
19
--    it under the terms of the GNU Lesser General Public License as published by --
20
--    the Free Software Foundation; either version 2.1 of the License, or         --
21
--    (at your option) any later version.                                         --
22
--                                                                                --
23
--    HPC-16 is distributed in the hope that it will be useful,                   --
24
--    but WITHOUT ANY WARRANTY; without even the implied warranty of              --
25
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               --
26
--    GNU Lesser General Public License for more details.                         --
27
--                                                                                --
28
--    You should have received a copy of the GNU Lesser General Public License    --
29
--    along with HPC-16; if not, write to the Free Software                       --
30
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   --
31
--                                                                                --
32
------------------------------------------------------------------------------------
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use ieee.std_logic_arith.all;
36
use ieee.std_logic_unsigned.all;
37
-----------------------------------------------------------
38
entity test2 is
39
  generic
40
  (
41
    clk_period          : time    := 40 ns;
42
    half_clk_period     : time    := 20 ns;
43
    --
44
    cpu_pc_preset_value : std_logic_vector(15 downto 0) := X"0000";
45
    cpu_sp_preset_value : std_logic_vector(15 downto 0) := X"001e";
46
    --
47
    ram_adr_width       : integer := 4;
48
 
49
    file_name_prefix    : string  := "prog1";
50
    sim_stop_time       : time    := 1500 ns
51
  );
52
end test2;
53
 
54
architecture sim of test2 is
55
  ----------------------------------------
56
  -- cpu interface signal
57
  ----------------------------------------
58
  signal clk_i : std_logic;
59
  signal rst_i : std_logic;
60
  signal ack_i : std_logic;
61
  signal intr_i : std_logic;
62
  --
63
  signal sel_o : std_logic_vector(1 downto 0);
64
  signal stb_o : std_logic;
65
  signal cyc_o : std_logic;
66
  signal we_o  : std_logic;
67
  --
68
  signal inta_cyc_o : std_logic;
69
  signal i_cyc_o    : std_logic;
70
  signal c_cyc_o    : std_logic;
71
  signal d_cyc_o    : std_logic;
72
  --
73
  signal adr_o : std_logic_vector(15 downto 0);
74
  signal dat_io : std_logic_vector(15 downto 0);
75
  -----------------------------------------
76
  -- ram interfacing
77
  -----------------------------------------
78
  signal ram_cs : std_logic;
79
  signal ram_oe : std_logic;
80
begin
81
  ------------------------------------------------------------------------  
82
  ram_cs_gen : process(stb_o, adr_o)
83
    variable temp : integer;
84
    constant max_loc : integer := (2 ** (ram_adr_width + 1)) - 1;
85
  begin
86
    if stb_o = '1' then
87
      temp := conv_integer(adr_o);
88
      if 0 <= temp and temp <= max_loc then
89
        ram_cs <= '1';
90
      else
91
        ram_cs <= '0';
92
      end if;
93
    end if;
94
  end process ram_cs_gen;
95
  ----------------------------------------------------------------------
96
  ram_oe <= not we_o;
97
  ----------------------------------------------------------------------
98
  clk_gen : process
99
  begin
100
    wait for half_clk_period;
101
    clk_i <= '1';
102
    wait for half_clk_period;
103
    clk_i <= '0';
104
    if now >= sim_stop_time then
105
      assert false
106
        report "simulation completed (not an error)"
107
        severity error;
108
      wait;
109
    end if;
110
  end process;
111
  -----------------------------------------------------------------------
112
  rst_gen : process
113
  begin
114
    wait for half_clk_period;
115
    rst_i <= '1';
116
    wait for 4 * clk_period;
117
    rst_i <= '0';
118
    wait;
119
  end process;
120
  -----------------------------------------------------------------------
121
  ram: entity work.ramNx16(async)
122
  generic map
123
  (
124
    init_file_name => file_name_prefix & "_init_ram.txt",
125
    adr_width => ram_adr_width
126
  )
127
  port map
128
  (
129
    clk => clk_i,
130
    adr => adr_o(ram_adr_width downto 1),
131
    dat_i => dat_io,
132
    --
133
    cs => ram_cs,
134
    we => we_o,
135
    ub => sel_o(1),
136
    lb => sel_o(0),
137
    oe => ram_oe,
138
    --
139
    dat_o => dat_io
140
  );
141
  -------------------------------------------------------------------------
142
  cpu : entity work.cpu
143
  generic map
144
  (
145
    pc_preset_value => cpu_pc_preset_value,
146
    sp_preset_value => cpu_sp_preset_value
147
  )
148
  port map
149
  (
150
     CLK_I => clk_i,
151
     RST_I => rst_i,
152
     ACK_I => ack_i,
153
     INTR_I => intr_i,
154
     --
155
     SEL_O => sel_o,
156
     STB_O => stb_o,
157
     CYC_O => cyc_o,
158
     WE_O => we_o,
159
     --
160
     INTA_CYC_O => inta_cyc_o,
161
     I_CYC_O => i_cyc_o,
162
     C_CYC_O => c_cyc_o,
163
     D_CYC_O => d_cyc_o,
164
     --
165
     DAT_IO => dat_io,
166
     ADR_O => adr_o
167
  );
168
-------------------------------------------------- 
169
  ack_gen : ack_i <= stb_o;
170
end sim;

powered by: WebSVN 2.1.0

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