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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [bench/] [vhdl/] [tb_copyBlaze_ecoSystem_wb-timer.vhd] - Blame information for rev 36

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

Line No. Rev Author Line
1 34 ameziti
--------------------------------------------------------------------------------
2
-- Company: 
3
--
4
-- File: tb_copyBlaze_ecoSystem_wb-timer.vhd
5
--
6
-- Description:
7
--      projet copyblaze
8
--      copyBlaze_ecoSystem testbench
9
--
10
-- File history:
11
-- v1.0: 25/11/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_wb_timer
23
--
24
-- Description:
25
--      
26
--      REMARQUE:
27
--
28
--      
29
-- History:
30
-- 25/11/11 AM: Creation
31
-- ---------------------
32
-- xx/xx/xx AM: 
33
--                              
34
--------------------------------------------------------------------------------
35
entity tb_copyBlaze_ecoSystem_wb_timer is
36
end tb_copyBlaze_ecoSystem_wb_timer;
37
 
38
--------------------------------------------------------------------------------
39
-- Architecture: behavior
40
-- of entity : tb_copyBlaze_ecoSystem_wb_timer
41
--------------------------------------------------------------------------------
42
architecture behavior of tb_copyBlaze_ecoSystem_wb_timer 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
                                --RST_I                         : in    std_ulogic;
108
                                --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
                                CYC_O                           : out   std_ulogic
119
                );
120
        end component;
121
 
122
        component wb_timer_8
123
   port (
124
      clk      : in  std_ulogic;
125
      reset    : in  std_ulogic;
126
      -- Wishbone bus
127
      wb_adr_i : in  std_ulogic_vector(7 downto 0);
128
      wb_dat_i : in  std_ulogic_vector(7 downto 0);
129
      wb_dat_o : out std_ulogic_vector(7 downto 0);
130
      wb_cyc_i : in  std_ulogic;
131
      wb_stb_i : in  std_ulogic;
132
      wb_ack_o : out std_ulogic;
133
      wb_we_i  : in  std_ulogic;
134
      wb_irq0_o: out std_ulogic;
135
      wb_irq1_o: out std_ulogic );
136
        end component;
137
 
138
        --------------------------------------------------------------------------------
139
        -- Définition des signaux interne
140
        --------------------------------------------------------------------------------
141
        signal iClk                             : std_ulogic := '0';
142
        signal iReset                   : std_ulogic;
143
        signal iResetN                  : std_ulogic;
144
 
145
        signal iInterrupt               : std_ulogic;
146
        signal iInterrupt_Ack   : std_ulogic;
147
        signal iIn_port                 : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
148
        signal iOut_port                : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
149
        signal iPort_id                 : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
150
        signal iRead_strobe             : std_ulogic;
151
        signal iWrite_strobe    : std_ulogic;
152
 
153
        signal iFreeze                  : std_ulogic := '0'; -- Freeze the processor
154
 
155
        signal iReset_counter   : natural range 0 to CST_RESET_LENGTH := CST_RESET_LENGTH;       -- VERY BAD SOLUTION
156
        signal iCounter                 : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
157
        signal iWaveForms               : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
158
        signal iExtIntEvent             : std_ulogic;-- := '0';
159
 
160
        signal iWbSTB                   : std_ulogic;
161
        signal iWbCYC                   : std_ulogic;
162
        signal iWbACK                   : std_ulogic;-- := '0';--'0';
163
        signal iWbWE                    : std_ulogic;-- := '0';--'0';
164
 
165
        signal iWbDAT_I                 : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
166
        signal iWbDAT_O                 : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
167
        signal iWbADR                   : std_ulogic_vector(CST_WIDTH_DATA-1 downto 0);
168
 
169
begin
170
 
171
        -- ***************************************** --
172
        -- UUT : Unit Under Test : cp_copyBlaze_ecoSystem --
173
        -- ***************************************** --
174
        uut: cp_copyBlaze_ecoSystem
175
                generic map
176
                (
177
                        GEN_WIDTH_DATA          => CST_WIDTH_DATA,
178
                        GEN_WIDTH_PC            => CST_WIDTH_PC,
179
                        GEN_WIDTH_INST          => CST_WIDTH_INST,
180
 
181
                        GEN_DEPTH_STACK         => CST_DEPTH_STACK,
182
                        GEN_DEPTH_BANC          => CST_DEPTH_BANC,
183
                        GEN_DEPTH_SCRATCH       => CST_DEPTH_SCRATCH,
184
 
185
                        GEN_INT_VECTOR          => CST_INT_VECTOR
186
                )
187
                Port map
188
                (
189
                        --------------------------------------------------------------------------------
190
                        -- Signaux Systeme
191
                        --------------------------------------------------------------------------------
192
                                Clk_i                           => iClk,
193
                                --Rst_i_n                               : in std_ulogic;
194
 
195
                        --------------------------------------------------------------------------------
196
                        -- Signaux Fonctionels
197
                        --------------------------------------------------------------------------------
198
                                Interrupt_i                     => iExtIntEvent,--iInterrupt,
199
                                Interrupt_Ack_o         => iInterrupt_Ack,
200
 
201
                                IN_PORT_i                       => iIn_port,
202
                                OUT_PORT_o                      => iOut_port,
203
                                PORT_ID_o                       => iPort_id,
204
                                READ_STROBE_o           => iRead_strobe,
205
                                WRITE_STROBE_o          => iWrite_strobe,
206
                        --------------------------------------------------------------------------------
207
                        -- Signaux WishBone
208
                        --------------------------------------------------------------------------------
209
                                Freeze_i                        => iFreeze,
210
 
211
                        --------------------------------------------------------------------------------
212
                        -- Signaux Wishbone Interface
213
                        --------------------------------------------------------------------------------
214
                                --RST_I                         => iReset,
215
                                --CLK_I                         => Clk_i,
216
 
217
                                ADR_O                           => iWbADR,
218
                                DAT_I                           => iWbDAT_I,--(others => '0'),
219
                                DAT_O                           => iWbDAT_O,--open,
220
                                WE_O                            => iWbWE,--open,
221
                                SEL_O                           => open,
222
 
223
                                STB_O                           => iWbSTB,
224
                                ACK_I                           => iWbACK,
225
                                CYC_O                           => iWbCYC
226
                );
227
 
228
        wb_timer : wb_timer_8
229
        port map(
230
                        clk      => iClk,
231
                        reset    => iResetN,
232
                        -- Wishbone bus
233
                        wb_adr_i => iWbADR,
234
                        wb_dat_i => iWbDAT_O,
235
                        wb_dat_o => iWbDAT_I,
236
                        wb_cyc_i => iWbCYC,
237
                        wb_stb_i => iWbSTB,
238
                        wb_ack_o => iWbACK,
239
                        wb_we_i  => iWbWE,
240
                        wb_irq0_o => iExtIntEvent,
241
                        wb_irq1_o => open
242
                );
243
 
244
        --------------------------------------------------------------------------------
245
        -- Process : Interrupt_Proc
246
        -- Description: Interrupt Logic for cp_copyBlaze_ecoSystem
247
        --------------------------------------------------------------------------------
248
        Interrupt_Proc: process(iReset, iClk)
249
        begin
250
                if (iReset='0') then
251
                        iInterrupt      <= '0';
252
                elsif ( rising_edge(iClk) ) then
253
                        if (iExtIntEvent='1') then
254
                                iInterrupt      <= '1';
255
                        elsif (iInterrupt_Ack='1') then
256
                                iInterrupt      <= '0';
257
                        end if;
258
                end if;
259
        end process Interrupt_Proc;
260
 
261
        --------------------------------------------------------------------------------
262
        -- Process : Reset_Proc
263
        -- Description: Reset Logic for cp_copyBlaze_ecoSystem
264
        --------------------------------------------------------------------------------
265
        Reset_Proc: process(iClk)
266
        begin
267
                -- delayed iReset circuit
268
                if ( rising_edge(iClk) ) then
269
                        if ( iReset_counter = 0 ) then
270
                                iReset                  <=      '1';
271
                        else
272
                                iReset                  <=      '0';
273
                                iReset_counter  <=      iReset_counter - 1;
274
                        end if;
275
                end if;
276
        end process Reset_Proc;
277
        iResetN <=      not(iReset);
278
 
279
        --------------------------------------------------------------------------------
280
        -- Process : IO_Proc
281
        -- Description: adding the output registers to the processor
282
        --------------------------------------------------------------------------------
283
        IO_Proc: process(iClk)
284
        begin
285
                -- waveform register at iAddress 02
286
                if ( rising_edge(iClk) ) then
287
                        if (iPort_id(1)='1' and iWrite_strobe='1') then
288
                                iWaveForms <= iOut_port;
289
                        end if;
290
                end if;
291
 
292
                -- Interrupt iCounter register at iAddress 04
293
                if ( rising_edge(iClk) ) then
294
                        if (iPort_id(2)='1' and iWrite_strobe='1') then
295
                                iCounter <= iOut_port;
296
                        end if;
297
                end if;
298
 
299
        end process IO_Proc;
300
 
301
        -- ********************* --
302
        -- STIMULIS FOR THE TEST --
303
        -- ********************* --
304
        -- Unused inputs on processor
305
        iIn_port        <= x"28";
306
 
307
        --iClk <= not iClk after 0.5 * CST_PERIOD;
308
        --------------------------------------------------------------------------------
309
        -- Process : INT_Proc
310
        -- Description: Nominal 100MHz clock which also defines number of cycles in simulation 
311
        --------------------------------------------------------------------------------
312
        INT_Proc : process
313
                variable max_cycles             : integer :=    CST_MAX_CYCLES;
314
                variable cycle_count    : integer :=    0;
315
        begin
316
                -- Define the clock cycles and the clock cycle iCounter
317
                while cycle_count < max_cycles loop
318
 
319
--                      wait until rising_edge(iClk) ;
320
                                iClk <= '0';
321
                        wait for CST_PERIOD;
322
                                iClk <= '1';
323
                                cycle_count := cycle_count + 1;
324
                        wait for CST_PERIOD;
325
 
326
 
327
                        --Now define stimulus relative to a given clock cycle
328
                        case cycle_count is
329
                                -- *************** --
330
                                -- INTERRUPT EVENT --
331
                                -- *************** --
332
                                --when 30 =>    iExtIntEvent <= '1'; 
333
                                --when 34 =>    iExtIntEvent <= '0'; 
334
                --
335
                                --when 67 =>    iExtIntEvent <= '1'; -- Take care when the "iIE" bit is not set. In this case how to manage Interrupt_Ack_o
336
                                --when 71 =>    iExtIntEvent <= '0'; 
337
 
338
                                --when 300 =>           iExtIntEvent <= '1'; 
339
                                --when 304 =>           iExtIntEvent <= '0'; 
340
 
341
                                -- ************ --
342
                                -- FREEZE EVENT --
343
                                -- ************ --
344
                                when 130 =>             iFreeze <= '1';
345
                                when 150 =>             iFreeze <= '0';
346
 
347
                                -- ****** --
348
                                -- WB ACK --
349
                                -- ****** --
350
                                --when 420      =>              iWbACK  <= '1';
351
                                --when 420+1    =>              iWbACK  <= '0';
352
 
353
                                when others =>  --iExtIntEvent <= iExtIntEvent;   -- hold last defined value
354
 
355
                        end case;
356
 
357
                end loop;
358
 
359
                wait; -- end of simulation.
360
 
361
        end process INT_Proc;
362
 
363
end behavior;

powered by: WebSVN 2.1.0

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