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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [bench/] [vhdl/] [tb_copyBlaze_ecoSystem_wb-uart.vhd] - Blame information for rev 42

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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