| 1 |
2 |
ameziti |
--------------------------------------------------------------------------------
|
| 2 |
|
|
-- Company:
|
| 3 |
|
|
--
|
| 4 |
|
|
-- File: tb_copyBlaze_ecoSystem.vhd
|
| 5 |
|
|
--
|
| 6 |
|
|
-- Description:
|
| 7 |
|
|
-- projet copyblaze
|
| 8 |
|
|
-- copyBlaze_ecoSystem testbench
|
| 9 |
|
|
--
|
| 10 |
|
|
-- File history:
|
| 11 |
|
|
-- v1.0: 21/10/11: Creation
|
| 12 |
|
|
--
|
| 13 |
|
|
-- Targeted device: ProAsic A3P250 VQFP100
|
| 14 |
|
|
-- Author: AbdAllah Meziti
|
| 15 |
|
|
--------------------------------------------------------------------------------
|
| 16 |
|
|
|
| 17 |
|
|
library ieee;
|
| 18 |
|
|
use ieee.std_logic_1164.all;
|
| 19 |
|
|
use ieee.numeric_std.all;
|
| 20 |
|
|
|
| 21 |
|
|
--------------------------------------------------------------------------------
|
| 22 |
|
|
-- Entity: tb_copyBlaze_ecoSystem
|
| 23 |
|
|
--
|
| 24 |
|
|
-- Description:
|
| 25 |
|
|
--
|
| 26 |
|
|
-- REMARQUE:
|
| 27 |
|
|
--
|
| 28 |
|
|
--
|
| 29 |
|
|
-- History:
|
| 30 |
|
|
-- 21/10/11 AM: Creation
|
| 31 |
|
|
-- ---------------------
|
| 32 |
|
|
-- xx/xx/xx AM:
|
| 33 |
|
|
--
|
| 34 |
|
|
--------------------------------------------------------------------------------
|
| 35 |
|
|
entity tb_copyBlaze_ecoSystem is
|
| 36 |
|
|
end tb_copyBlaze_ecoSystem;
|
| 37 |
|
|
|
| 38 |
|
|
--------------------------------------------------------------------------------
|
| 39 |
|
|
-- Architecture: behavior
|
| 40 |
|
|
-- of entity : tb_copyBlaze_ecoSystem
|
| 41 |
|
|
--------------------------------------------------------------------------------
|
| 42 |
|
|
architecture behavior of tb_copyBlaze_ecoSystem is
|
| 43 |
|
|
|
| 44 |
|
|
--------------------------------------------------------------------------------
|
| 45 |
|
|
-- Définition des constantes
|
| 46 |
|
|
--------------------------------------------------------------------------------
|
| 47 |
|
|
-- Constant for testbench
|
| 48 |
|
|
constant CST_RESET_LENGTH : positive := 7;
|
| 49 |
|
|
constant CST_MAX_CYCLES : positive := 500;
|
| 50 |
|
|
|
| 51 |
|
|
constant CST_FREQ : integer := 4; -- Mhz
|
| 52 |
|
|
constant CST_PERIOD : time := 1 us/CST_FREQ;
|
| 53 |
|
|
|
| 54 |
|
|
-- Constant for the cp_copyBlaze_ecoSystem generic
|
| 55 |
|
|
constant CST_WIDTH_DATA : positive := 8;
|
| 56 |
|
|
constant CST_WIDTH_PC : positive := 10;
|
| 57 |
|
|
constant CST_WIDTH_INST : positive := 18;
|
| 58 |
|
|
|
| 59 |
|
|
constant CST_DEPTH_STACK : positive := 31;
|
| 60 |
|
|
constant CST_DEPTH_BANC : positive := 16;
|
| 61 |
|
|
constant CST_DEPTH_SCRATCH : positive := 64;
|
| 62 |
|
|
|
| 63 |
|
|
constant CST_INT_VECTOR : std_ulogic_vector(11 downto 0) := x"3FF";
|
| 64 |
|
|
|
| 65 |
|
|
--------------------------------------------------------------------------------
|
| 66 |
|
|
-- Déclaration des composants
|
| 67 |
|
|
--------------------------------------------------------------------------------
|
| 68 |
|
|
component cp_copyBlaze_ecoSystem
|
| 69 |
|
|
generic
|
| 70 |
|
|
(
|
| 71 |
|
|
GEN_WIDTH_DATA : positive := 8;
|
| 72 |
|
|
GEN_WIDTH_PC : positive := 10;
|
| 73 |
|
|
GEN_WIDTH_INST : positive := 18;
|
| 74 |
|
|
|
| 75 |
|
|
GEN_DEPTH_STACK : positive := 15; -- Taille (en octet) de la Stack
|
| 76 |
|
|
GEN_DEPTH_BANC : positive := 16; -- Taille (en octet) du Banc Register
|
| 77 |
|
|
GEN_DEPTH_SCRATCH : positive := 64; -- Taille (en octet) du Scratch Pad
|
| 78 |
|
|
|
| 79 |
|
|
GEN_INT_VECTOR : std_ulogic_vector(11 downto 0) := x"3FF"
|
| 80 |
|
|
);
|
| 81 |
|
|
Port (
|
| 82 |
|
|
--------------------------------------------------------------------------------
|
| 83 |
|
|
-- Signaux Systeme
|
| 84 |
|
|
--------------------------------------------------------------------------------
|
| 85 |
|
|
Clk_i : in std_ulogic;
|
| 86 |
|
|
--Rst_i_n : in std_ulogic;
|
| 87 |
|
|
|
| 88 |
|
|
--------------------------------------------------------------------------------
|
| 89 |
|
|
-- Signaux Fonctionels
|
| 90 |
|
|
--------------------------------------------------------------------------------
|
| 91 |
|
|
Interrupt_i : in std_ulogic;
|
| 92 |
|
|
Interrupt_Ack_o : out std_ulogic;
|
| 93 |
|
|
|
| 94 |
|
|
IN_PORT_i : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 95 |
|
|
OUT_PORT_o : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 96 |
|
|
PORT_ID_o : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 97 |
|
|
READ_STROBE_o : out std_ulogic;
|
| 98 |
|
|
WRITE_STROBE_o : out std_ulogic;
|
| 99 |
|
|
--------------------------------------------------------------------------------
|
| 100 |
|
|
-- Signaux WishBone
|
| 101 |
|
|
--------------------------------------------------------------------------------
|
| 102 |
|
|
Freeze_i : in std_ulogic;
|
| 103 |
|
|
|
| 104 |
|
|
--------------------------------------------------------------------------------
|
| 105 |
|
|
-- Signaux Wishbone Interface
|
| 106 |
|
|
--------------------------------------------------------------------------------
|
| 107 |
13 |
ameziti |
--RST_I : in std_ulogic;
|
| 108 |
2 |
ameziti |
--CLK_I : in std_ulogic;
|
| 109 |
|
|
|
| 110 |
|
|
ADR_O : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 111 |
|
|
DAT_I : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 112 |
|
|
DAT_O : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
|
| 113 |
|
|
WE_O : out std_ulogic;
|
| 114 |
|
|
SEL_O : out std_ulogic_vector(1 downto 0);
|
| 115 |
|
|
|
| 116 |
|
|
STB_O : out std_ulogic;
|
| 117 |
|
|
ACK_I : in std_ulogic;
|
| 118 |
6 |
ameziti |
CYC_O : out std_ulogic
|
| 119 |
2 |
ameziti |
);
|
| 120 |
|
|
end component;
|
| 121 |
|
|
|
| 122 |
|
|
component WBOPRT08
|
| 123 |
|
|
port(
|
| 124 |
|
|
-- WISHBONE SLAVE interface:
|
| 125 |
|
|
ACK_O : out std_ulogic;
|
| 126 |
|
|
CLK_I : in std_ulogic;
|
| 127 |
|
|
DAT_I : in std_ulogic_vector( 7 downto 0 );
|
| 128 |
|
|
DAT_O : out std_ulogic_vector( 7 downto 0 );
|
| 129 |
|
|
RST_I : in std_ulogic;
|
| 130 |
|
|
STB_I : in std_ulogic;
|
| 131 |
|
|
WE_I : in std_ulogic;
|
| 132 |
|
|
-- Output port (non-WISHBONE signals):
|
| 133 |
|
|
PRT_O : out std_ulogic_vector( 7 downto 0 )
|
| 134 |
|
|
);
|
| 135 |
|
|
end component;
|
| 136 |
|
|
|
| 137 |
|
|
--------------------------------------------------------------------------------
|
| 138 |
|
|
-- Définition des signaux interne
|
| 139 |
|
|
--------------------------------------------------------------------------------
|
| 140 |
|
|
signal iClk : std_ulogic := '0';
|
| 141 |
|
|
signal iReset : std_ulogic;
|
| 142 |
|
|
signal iResetN : std_ulogic;
|
| 143 |
|
|
|
| 144 |
13 |
ameziti |
signal iInterrupt : std_ulogic;
|
| 145 |
|
|
signal iInterrupt_Ack : std_ulogic;
|
| 146 |
2 |
ameziti |
signal iIn_port : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 147 |
|
|
signal iOut_port : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 148 |
|
|
signal iPort_id : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 149 |
|
|
signal iRead_strobe : std_ulogic;
|
| 150 |
|
|
signal iWrite_strobe : std_ulogic;
|
| 151 |
|
|
|
| 152 |
|
|
signal iFreeze : std_ulogic := '0'; -- Freeze the processor
|
| 153 |
|
|
|
| 154 |
|
|
signal iReset_counter : natural range 0 to CST_RESET_LENGTH := CST_RESET_LENGTH; -- VERY BAD SOLUTION
|
| 155 |
|
|
signal iCounter : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 156 |
|
|
signal iWaveForms : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 157 |
|
|
signal iExtIntEvent : std_ulogic := '0';
|
| 158 |
|
|
|
| 159 |
|
|
signal iWbSTB : std_ulogic;
|
| 160 |
|
|
signal iWbACK : std_ulogic;-- := '0';--'0';
|
| 161 |
|
|
signal iWbWE : std_ulogic;-- := '0';--'0';
|
| 162 |
|
|
|
| 163 |
|
|
signal iWbDAT_I : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 164 |
|
|
signal iWbDAT_O : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
|
| 165 |
|
|
|
| 166 |
|
|
begin
|
| 167 |
|
|
|
| 168 |
|
|
-- ***************************************** --
|
| 169 |
|
|
-- UUT : Unit Under Test : cp_copyBlaze_ecoSystem --
|
| 170 |
|
|
-- ***************************************** --
|
| 171 |
|
|
uut: cp_copyBlaze_ecoSystem
|
| 172 |
|
|
generic map
|
| 173 |
|
|
(
|
| 174 |
|
|
GEN_WIDTH_DATA => CST_WIDTH_DATA,
|
| 175 |
|
|
GEN_WIDTH_PC => CST_WIDTH_PC,
|
| 176 |
|
|
GEN_WIDTH_INST => CST_WIDTH_INST,
|
| 177 |
|
|
|
| 178 |
|
|
GEN_DEPTH_STACK => CST_DEPTH_STACK,
|
| 179 |
|
|
GEN_DEPTH_BANC => CST_DEPTH_BANC,
|
| 180 |
|
|
GEN_DEPTH_SCRATCH => CST_DEPTH_SCRATCH,
|
| 181 |
|
|
|
| 182 |
|
|
GEN_INT_VECTOR => CST_INT_VECTOR
|
| 183 |
|
|
)
|
| 184 |
|
|
Port map
|
| 185 |
|
|
(
|
| 186 |
|
|
--------------------------------------------------------------------------------
|
| 187 |
|
|
-- Signaux Systeme
|
| 188 |
|
|
--------------------------------------------------------------------------------
|
| 189 |
|
|
Clk_i => iClk,
|
| 190 |
|
|
--Rst_i_n : in std_ulogic;
|
| 191 |
|
|
|
| 192 |
|
|
--------------------------------------------------------------------------------
|
| 193 |
|
|
-- Signaux Fonctionels
|
| 194 |
|
|
--------------------------------------------------------------------------------
|
| 195 |
|
|
Interrupt_i => iInterrupt,
|
| 196 |
|
|
Interrupt_Ack_o => iInterrupt_Ack,
|
| 197 |
|
|
|
| 198 |
|
|
IN_PORT_i => iIn_port,
|
| 199 |
|
|
OUT_PORT_o => iOut_port,
|
| 200 |
|
|
PORT_ID_o => iPort_id,
|
| 201 |
|
|
READ_STROBE_o => iRead_strobe,
|
| 202 |
|
|
WRITE_STROBE_o => iWrite_strobe,
|
| 203 |
|
|
--------------------------------------------------------------------------------
|
| 204 |
|
|
-- Signaux WishBone
|
| 205 |
|
|
--------------------------------------------------------------------------------
|
| 206 |
|
|
Freeze_i => iFreeze,
|
| 207 |
|
|
|
| 208 |
|
|
--------------------------------------------------------------------------------
|
| 209 |
|
|
-- Signaux Wishbone Interface
|
| 210 |
|
|
--------------------------------------------------------------------------------
|
| 211 |
6 |
ameziti |
--RST_I => iReset,
|
| 212 |
2 |
ameziti |
--CLK_I => Clk_i,
|
| 213 |
|
|
|
| 214 |
|
|
ADR_O => open,
|
| 215 |
|
|
DAT_I => iWbDAT_I,--(others => '0'),
|
| 216 |
|
|
DAT_O => iWbDAT_O,--open,
|
| 217 |
|
|
WE_O => iWbWE,--open,
|
| 218 |
|
|
SEL_O => open,
|
| 219 |
|
|
|
| 220 |
|
|
STB_O => iWbSTB,
|
| 221 |
|
|
ACK_I => iWbACK,
|
| 222 |
6 |
ameziti |
CYC_O => open
|
| 223 |
2 |
ameziti |
);
|
| 224 |
|
|
|
| 225 |
|
|
WB_port : WBOPRT08
|
| 226 |
|
|
port map
|
| 227 |
|
|
(
|
| 228 |
|
|
-- WISHBONE SLAVE interface:
|
| 229 |
|
|
ACK_O => iWbACK,
|
| 230 |
|
|
CLK_I => iClk,
|
| 231 |
|
|
DAT_I => iWbDAT_O,
|
| 232 |
|
|
DAT_O => iWbDAT_I,
|
| 233 |
|
|
RST_I => iResetN,
|
| 234 |
|
|
STB_I => iWbSTB,
|
| 235 |
|
|
WE_I => iWbWE,
|
| 236 |
|
|
-- Output port (non-WISHBONE signals):
|
| 237 |
|
|
PRT_O => open --: out std_ulogic_vector( 7 downto 0 )
|
| 238 |
|
|
);
|
| 239 |
|
|
|
| 240 |
|
|
--------------------------------------------------------------------------------
|
| 241 |
|
|
-- Process : Interrupt_Proc
|
| 242 |
|
|
-- Description: Interrupt Logic for cp_copyBlaze_ecoSystem
|
| 243 |
|
|
--------------------------------------------------------------------------------
|
| 244 |
|
|
Interrupt_Proc: process(iReset, iClk)
|
| 245 |
|
|
begin
|
| 246 |
|
|
if (iReset='0') then
|
| 247 |
|
|
iInterrupt <= '0';
|
| 248 |
|
|
elsif ( rising_edge(iClk) ) then
|
| 249 |
|
|
if (iExtIntEvent='1') then
|
| 250 |
|
|
iInterrupt <= '1';
|
| 251 |
|
|
elsif (iInterrupt_Ack='1') then
|
| 252 |
|
|
iInterrupt <= '0';
|
| 253 |
|
|
end if;
|
| 254 |
|
|
end if;
|
| 255 |
|
|
end process Interrupt_Proc;
|
| 256 |
|
|
|
| 257 |
|
|
--------------------------------------------------------------------------------
|
| 258 |
|
|
-- Process : Reset_Proc
|
| 259 |
|
|
-- Description: Reset Logic for cp_copyBlaze_ecoSystem
|
| 260 |
|
|
--------------------------------------------------------------------------------
|
| 261 |
|
|
Reset_Proc: process(iClk)
|
| 262 |
|
|
begin
|
| 263 |
|
|
-- delayed iReset circuit
|
| 264 |
|
|
if ( rising_edge(iClk) ) then
|
| 265 |
|
|
if ( iReset_counter = 0 ) then
|
| 266 |
|
|
iReset <= '1';
|
| 267 |
|
|
else
|
| 268 |
|
|
iReset <= '0';
|
| 269 |
|
|
iReset_counter <= iReset_counter - 1;
|
| 270 |
|
|
end if;
|
| 271 |
|
|
end if;
|
| 272 |
|
|
end process Reset_Proc;
|
| 273 |
|
|
iResetN <= not(iReset);
|
| 274 |
|
|
|
| 275 |
|
|
--------------------------------------------------------------------------------
|
| 276 |
|
|
-- Process : IO_Proc
|
| 277 |
|
|
-- Description: adding the output registers to the processor
|
| 278 |
|
|
--------------------------------------------------------------------------------
|
| 279 |
|
|
IO_Proc: process(iClk)
|
| 280 |
|
|
begin
|
| 281 |
|
|
-- waveform register at iAddress 02
|
| 282 |
|
|
if ( rising_edge(iClk) ) then
|
| 283 |
|
|
if (iPort_id(1)='1' and iWrite_strobe='1') then
|
| 284 |
|
|
iWaveForms <= iOut_port;
|
| 285 |
|
|
end if;
|
| 286 |
|
|
end if;
|
| 287 |
|
|
|
| 288 |
|
|
-- Interrupt iCounter register at iAddress 04
|
| 289 |
|
|
if ( rising_edge(iClk) ) then
|
| 290 |
|
|
if (iPort_id(2)='1' and iWrite_strobe='1') then
|
| 291 |
|
|
iCounter <= iOut_port;
|
| 292 |
|
|
end if;
|
| 293 |
|
|
end if;
|
| 294 |
|
|
|
| 295 |
|
|
end process IO_Proc;
|
| 296 |
|
|
|
| 297 |
|
|
-- ********************* --
|
| 298 |
|
|
-- STIMULIS FOR THE TEST --
|
| 299 |
|
|
-- ********************* --
|
| 300 |
|
|
-- Unused inputs on processor
|
| 301 |
|
|
iIn_port <= x"28";
|
| 302 |
|
|
|
| 303 |
|
|
--iClk <= not iClk after 0.5 * CST_PERIOD;
|
| 304 |
|
|
--------------------------------------------------------------------------------
|
| 305 |
|
|
-- Process : INT_Proc
|
| 306 |
|
|
-- Description: Nominal 100MHz clock which also defines number of cycles in simulation
|
| 307 |
|
|
--------------------------------------------------------------------------------
|
| 308 |
|
|
INT_Proc : process
|
| 309 |
|
|
variable max_cycles : integer := CST_MAX_CYCLES;
|
| 310 |
|
|
variable cycle_count : integer := 0;
|
| 311 |
|
|
begin
|
| 312 |
|
|
-- Define the clock cycles and the clock cycle iCounter
|
| 313 |
|
|
while cycle_count < max_cycles loop
|
| 314 |
|
|
|
| 315 |
|
|
-- wait until rising_edge(iClk) ;
|
| 316 |
|
|
iClk <= '0';
|
| 317 |
|
|
wait for CST_PERIOD;
|
| 318 |
|
|
iClk <= '1';
|
| 319 |
|
|
cycle_count := cycle_count + 1;
|
| 320 |
|
|
wait for CST_PERIOD;
|
| 321 |
|
|
|
| 322 |
|
|
|
| 323 |
|
|
--Now define stimulus relative to a given clock cycle
|
| 324 |
|
|
case cycle_count is
|
| 325 |
|
|
-- *************** --
|
| 326 |
|
|
-- INTERRUPT EVENT --
|
| 327 |
|
|
-- *************** --
|
| 328 |
|
|
--when 30 => iExtIntEvent <= '1';
|
| 329 |
|
|
--when 34 => iExtIntEvent <= '0';
|
| 330 |
|
|
--
|
| 331 |
|
|
--when 67 => iExtIntEvent <= '1'; -- Take care when the "iIE" bit is not set. In this case how to manage Interrupt_Ack_o
|
| 332 |
|
|
--when 71 => iExtIntEvent <= '0';
|
| 333 |
|
|
|
| 334 |
|
|
when 300 => iExtIntEvent <= '1';
|
| 335 |
|
|
when 304 => iExtIntEvent <= '0';
|
| 336 |
|
|
|
| 337 |
|
|
-- ************ --
|
| 338 |
|
|
-- FREEZE EVENT --
|
| 339 |
|
|
-- ************ --
|
| 340 |
|
|
when 130 => iFreeze <= '1';
|
| 341 |
|
|
when 150 => iFreeze <= '0';
|
| 342 |
|
|
|
| 343 |
|
|
-- ****** --
|
| 344 |
|
|
-- WB ACK --
|
| 345 |
|
|
-- ****** --
|
| 346 |
|
|
--when 420 => iWbACK <= '1';
|
| 347 |
|
|
--when 420+1 => iWbACK <= '0';
|
| 348 |
|
|
|
| 349 |
|
|
when others => iExtIntEvent <= iExtIntEvent; -- hold last defined value
|
| 350 |
|
|
|
| 351 |
|
|
end case;
|
| 352 |
|
|
|
| 353 |
|
|
end loop;
|
| 354 |
|
|
|
| 355 |
|
|
wait; -- end of simulation.
|
| 356 |
|
|
|
| 357 |
|
|
end process INT_Proc;
|
| 358 |
|
|
|
| 359 |
|
|
end behavior;
|