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

Subversion Repositories wb2hpi

[/] [wb2hpi/] [trunk/] [rtl/] [vhdl/] [wb2hpi_WBslave.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 gvozden
----------------------------------------------------------------------
2
----                                                              ----
3
----  File name "wb2hpi_WBslave.vhd"                              ----
4
----                                                              ----
5
----  This file is part of the "WB2HPI" project                   ----
6
----  http://www.opencores.org/cores/wb2hpi/                      ----
7
----                                                              ----
8
----  Author(s):                                                  ----
9
----      - Gvozden Marinkovic (gvozden@opencores.org)            ----
10
----      - Dusko Krsmanovic   (dusko@opencores.org)              ----
11
----                                                              ----
12
----  All additional information is avaliable in the README       ----
13
----  file.                                                       ----
14
----                                                              ----
15
----                                                              ----
16
----------------------------------------------------------------------
17
----                                                              ----
18
---- Copyright (C) 2002 Gvozden Marinkovic, gvozden@opencores.org ----
19
----                                                              ----
20
---- This source file may be used and distributed without         ----
21
---- restriction provided that this copyright statement is not    ----
22
---- removed from the file and that any derivative work contains  ----
23
---- the original copyright notice and the associated disclaimer. ----
24
----                                                              ----
25
---- This source file is free software; you can redistribute it   ----
26
---- and/or modify it under the terms of the GNU Lesser General   ----
27
---- Public License as published by the Free Software Foundation; ----
28
---- either version 2.1 of the License, or (at your option) any   ----
29
---- later version.                                               ----
30
----                                                              ----
31
---- This source is distributed in the hope that it will be       ----
32
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
33
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
34
---- PURPOSE.  See the GNU Lesser General Public License for more ----
35
---- details.                                                     ----
36
----                                                              ----
37
---- You should have received a copy of the GNU Lesser General    ----
38
---- Public License along with this source; if not, download it   ----
39
---- from http://www.opencores.org/lgpl.shtml                     ----
40
----                                                              ----
41
----------------------------------------------------------------------
42
 
43
--==================================================================-- 
44
-- Design        : wb2hpi_WBslave 
45
--                ( entity i architecture ) 
46
-- 
47
-- File          : wb2hpi_WBslave.vhd 
48
-- 
49
-- Errors        : 
50
-- 
51
-- Library       : ieee.std_logic_1164 
52
-- 
53
-- Dependency    : 
54
-- 
55
-- Author        : Gvozden Marinkovic 
56
--                 mgvozden@eunet.yu 
57
-- 
58
-- Simulators    : ActiveVHDL 3.5 on a WindowsXP PC   
59
----------------------------------------------------------------------
60
-- Description   :  WB Slave for WB2HPI application
61
----------------------------------------------------------------------
62
-- Copyright (c) 2002  Gvozden Marinkovic
63
-- 
64
-- This VHDL design file is an open design; you can redistribute it 
65
-- and/or modify it and/or implement it after contacting the author
66
--==================================================================-- 
67
 
68
--************************** CVS history ***************************--
69
-- $Author: gvozden $
70
-- $Date: 2003-01-16 18:06:20 $
71
-- $Revision: 1.1.1.1 $  
72
-- $Name: not supported by cvs2svn $
73
--************************** CVS history ***************************--
74
 
75
library ieee;
76
use ieee.std_logic_1164.all;
77
 
78
---------------------------------------------------------------------- 
79
-- entity wb2hpi_WBslave 
80
---------------------------------------------------------------------- 
81
entity wb2hpi_WBslave is
82
    port (
83
        -- WISHBONE common signals to MASTER and SLAVE
84
        WB_CLK_I        : in  std_logic;                     -- Clock
85
        WB_RST_I        : in  std_logic;                     -- Reset
86
 
87
        -- WISHBONE SLAVE signals
88
        WBS_CYC_I       : in  std_logic;                     -- Cycle in progress
89
        WBS_STB_I       : in  std_logic;                     -- Strobe
90
        WBS_WE_I        : in  std_logic;                     -- Write enable
91
        WBS_CAB_I       : in  std_logic;
92
        WBS_ADR_I       : in  std_logic_vector(31 downto 0); -- Address
93
        WBS_DAT_I       : in  std_logic_vector(31 downto 0); -- Data input
94
        WBS_SEL_I       : in  std_logic_vector(3  downto 0); -- Select
95
        WBS_ACK_O       : out std_logic;                     -- Acknowledge
96
        WBS_ERR_O       : out std_logic;                     -- Error
97
        WBS_RTY_O       : out std_logic;                     -- Retry
98
        WBS_DAT_O       : out std_logic_vector(31 downto 0); -- Data output       
99
 
100
        -- To PCI signals
101
        int_req         : out std_logic;                     -- Interrupt request
102
 
103
        -- To HPI Interface        
104
        hpi_data_r      : out std_logic_vector(17 downto 0); -- HPI data (to DSP)
105
        hpi_address_r   : out std_logic_vector(15 downto 0); -- HPI address (to DSP) 
106
        hpi_command_r   : out std_logic_vector( 2 downto 0); -- HPI command   
107
        pci_address_r   : out std_logic_vector(31 downto 1); -- Memory buffrer address
108
        pci_counter_r   : out std_logic_vector(15 downto 0); -- Number of words for transfer  
109
        start_hpi_comm  : out std_logic;                     -- Start HPI command
110
        hpi_reset       : out std_logic;                     -- Reset HPI Logic
111
        dsp_reset       : out std_logic;                     -- Reset DSP
112
 
113
        -- From HPI Interface
114
        hpi_data_out    : in  std_logic_vector(15 downto 0); -- Data out (To-WB)
115
        hpi_ready       : in  std_logic;                     -- Ready for HPI Access
116
        hpi_counter     : in  std_logic_vector(15 downto 0);
117
        hpi_pci_addr    : in  std_logic_vector(31 downto 1);
118
        hpi_int_req1    : in  std_logic;                     -- Interrupt request 1 (End Block Transfer)
119
        hpi_int_req2    : in  std_logic;                     -- Interrupt request 2 (from DSP)
120
        dsp_ready       : in  std_logic;                     -- DSP Ready
121
        dsp_hint        : in  std_logic;                     -- DSP Host Interrupt
122
        hpi_end_transfer: in  std_logic;                     -- HPI End Transfer
123
        hpi_data_is_rdy : in  std_logic;                     -- HPI Data Ready 
124
 
125
        -- From WB master
126
        pci_error       : in  std_logic;                     -- PCI error
127
 
128
        -- To Test LED
129
        led             : out std_logic                      -- Control LED
130
    );
131
end entity wb2hpi_WBslave;
132
 
133
---------------------------------------------------------------------- 
134
-- architecture wb2hpi_WBslave 
135
---------------------------------------------------------------------- 
136
architecture behavioral of wb2hpi_WBslave is
137
 
138
---------------------------------------------------------------------- 
139
-- constant declaration
140
---------------------------------------------------------------------- 
141
-- Registers Addresses
142
constant ADR_IR         : std_logic_vector(3 downto 0):="0001";-- Interrupt requests
143
constant ADR_MR         : std_logic_vector(3 downto 0):="0010";-- Interrupt mask  
144
constant ADR_LED        : std_logic_vector(3 downto 0):="0111";-- LED 
145
constant ADR_HPI_COMM   : std_logic_vector(3 downto 0):="1000";-- HPI command 
146
constant ADR_HPI_PCI_ADR: std_logic_vector(3 downto 0):="1001";-- PCI address
147
constant ADR_HPI_READ   : std_logic_vector(3 downto 0):="1010";-- HPI data 
148
constant ADR_HPI_CNT    : std_logic_vector(3 downto 0):="1011";-- HPI word counter 
149
constant ADR_CONTROL    : std_logic_vector(3 downto 0):="1100";-- DSP control
150
constant ADR_STATUS     : std_logic_vector(3 downto 0):="1101";-- DSP status 
151
constant ADR_MAP_DSP    : std_logic_vector(3 downto 0):="1111";-- MAP DSP  
152
 
153
constant COM_MAP_READ   : std_logic_vector(2 downto 0):= "110";-- Map DSP read
154
constant COM_MAP_WRITE  : std_logic_vector(2 downto 0):= "111";-- Map DSP write
155
 
156
---------------------------------------------------------------------- 
157
-- type declaration 
158
---------------------------------------------------------------------- 
159
type wbs_state is (IDLE, RTY, ACK, START_MAP_READ, WAIT_HPI);-- WB Slave states 
160
type pci_state is (IDLE, SET_START, WAIT_END);
161
 
162
---------------------------------------------------------------------- 
163
-- signal declaration 
164
---------------------------------------------------------------------- 
165
-- Registers
166
signal ctl_mr           : std_logic_vector( 1 downto 0);     -- Interrupt mask 
167
signal ctl_ir           : std_logic_vector( 1 downto 0);     -- Interrupt requests
168
signal led_r            : std_logic_vector( 0 downto 0);     -- LED
169
signal control_r        : std_logic_vector( 1 downto 0);     -- DSP control       
170
signal status_r         : std_logic_vector( 5 downto 0);     -- DSP status
171
signal hpi_dat_r        : std_logic_vector(17 downto 0);
172
signal hpi_com_r        : std_logic_vector(2  downto 0);
173
 
174
-- Control signals
175
signal sel              : std_logic_vector(15 downto 0);     -- Register selections                      
176
signal valid_access     : boolean;                           -- Valid address detected
177
signal write_ir         : std_logic;                         -- Strobe
178
 
179
-- FSM States
180
signal current_state, next_state: wbs_state;
181
 
182
---------------------------------------------------------------------- 
183
-- alias declaration 
184
---------------------------------------------------------------------- 
185
alias local_address     : std_logic_vector(3  downto  0) is WBS_ADR_I(19 downto 16);
186
 
187
-- Register selection signals                          
188
alias sel_led           : std_logic is sel(0);
189
alias sel_mr            : std_logic is sel(1);
190
alias sel_ir            : std_logic is sel(2);
191
alias sel_pci_address   : std_logic is sel(3);
192
alias sel_pci_counter   : std_logic is sel(4);
193
alias sel_hpi_command   : std_logic is sel(5);
194
alias sel_hpi_data      : std_logic is sel(6);
195
alias sel_control       : std_logic is sel(7);
196
alias sel_status        : std_logic is sel(8);
197
alias sel_map_dsp       : std_logic is sel(10);
198
 
199
-- HPI 
200
alias WBS_HPI_COMM : std_logic_vector(2  downto 0) is WBS_DAT_I(18 downto 16);
201
alias WBS_HPI_REG  : std_logic_vector(1  downto 0) is WBS_DAT_I(21 downto 20);
202
alias WBS_HPI_DATA : std_logic_vector(15 downto 0) is WBS_DAT_I(15 downto  0);
203
 
204
begin               -- architecture Behavioral of myWBSlave 
205
 
206
    -- purpose: access cycle validation
207
    -- type   : combinational
208
    -- inputs : WBS_SEL_I, WBS_CYC_I, WBS_STB_I, sel_map_dsp
209
    -- outputs: valid_access 
210
    valid_access <= (WBS_CYC_I = '1'  and
211
                     WBS_STB_I = '1') and (
212
                       (WBS_SEL_I = "1111" and sel_map_dsp = '0') or
213
                       (WBS_SEL_I = "1100" and sel_map_dsp = '1') or
214
                       (WBS_SEL_I = "0011" and sel_map_dsp = '1')
215
                    );
216
 
217
    -- purpose: ack or retry on valid cycle
218
    -- type   : combinational
219
    -- inputs : valid_access, WBS_WE_I, current_state, sel, hpi_ready
220
    -- outputs: next_state
221
    fsm_set_next: process (valid_access, WBS_WE_I,
222
                           current_state, sel_map_dsp,
223
                           sel, hpi_ready) is
224
    begin
225
        next_state <= IDLE;                                   -- Default state is IDLE    
226
 
227
        case (current_state) is
228
        when IDLE =>
229
            if (valid_access) then                            -- Valid cycle detected
230
                next_state <= ACK;
231
                if ((sel_hpi_command = '1'  or                -- Retry if HPI interface
232
                     sel_hpi_data    = '1'  or                -- is busy
233
                     sel_pci_address = '1'  or
234
                     sel_map_dsp     = '1') and
235
                     hpi_ready ='0') then
236
                   next_state <= RTY;
237
                elsif (sel_map_dsp = '1' and WBS_WE_I = '0') then
238
                   next_state <= START_MAP_READ;
239
                end if;
240
            end if;
241
        when START_MAP_READ =>
242
            next_state <= WAIT_HPI;
243
        when WAIT_HPI =>
244
            next_state <= WAIT_HPI;
245
            if (hpi_ready = '1') then
246
                next_state <= ACK;
247
            end if;
248
        when ACK | RTY =>
249
            next_state <= IDLE;
250
        when others => null;
251
        end case;
252
    end process fsm_set_next;
253
 
254
    -- purpose: generate delayed WISHBONE ack/err
255
    -- type   : sequential
256
    -- inputs : WB_CLK_I, WB_RST_I, WBS_CYC_I, WBS_STB_I,
257
    --          valid_access, next_state 
258
    -- outputs: WBS_ACK_O, WBS_ERR_O, WBS_RTY_O         
259
    ack_err: process (WB_CLK_I, WB_RST_I) is
260
    begin
261
        if (WB_RST_I = '1') then
262
            WBS_ACK_O <= '0';
263
            WBS_ERR_O <= '0';
264
            WBS_RTY_O <= '0';
265
        elsif rising_edge (WB_CLK_I) then
266
            WBS_ACK_O <= '0';
267
            WBS_ERR_O <= '0';
268
            WBS_RTY_O <= '0';
269
            if (valid_access) then
270
                case (next_state) is
271
                   when ACK => WBS_ACK_O <= '1';
272
                   when RTY => WBS_RTY_O <= '1';
273
                   when others => null;
274
                end case;
275
            elsif (WBS_CYC_I = '1' and WBS_STB_I = '1') then
276
                WBS_ERR_O <= '1';
277
            end if;
278
        end if;
279
    end process ack_err;
280
 
281
    -- purpose: finite state machines
282
    -- type   : sequential
283
    -- inputs : WB_CLK_I, WB_RST_I, next_state
284
    -- outputs: current_state 
285
    fsm_set_state: process (WB_CLK_I, WB_RST_I, next_state) is
286
    begin
287
        if (WB_RST_I = '1') then
288
            current_state <= IDLE;
289
        elsif rising_edge(WB_CLK_I) then
290
            current_state <= next_state;
291
        end if;
292
    end process fsm_set_state;
293
 
294
    -- purpose: address decoder
295
    -- type   : combinational
296
    -- inputs : local_address
297
    -- outputs: sel   
298
    address_decode: process (local_address) is
299
    begin
300
        sel <= (others => '0');
301
        case (local_address) is
302
            when ADR_LED         => sel_led         <= '1';
303
            when ADR_MR          => sel_mr          <= '1';
304
            when ADR_IR          => sel_ir          <= '1';
305
            when ADR_HPI_PCI_ADR => sel_pci_address <= '1';
306
            when ADR_HPI_READ    => sel_hpi_data    <= '1';
307
            when ADR_HPI_CNT     => sel_pci_counter <= '1';
308
            when ADR_HPI_COMM    => sel_hpi_command <= '1';
309
            when ADR_CONTROL     => sel_control     <= '1';
310
            when ADR_STATUS      => sel_status      <= '1';
311
            when ADR_MAP_DSP     => sel_map_dsp     <= '1';
312
            when others => null;
313
        end case;
314
    end process address_decode;
315
 
316
    -- purpose: write access control 
317
    -- type   : sequential
318
    -- inputs : WB_CLK_I, WB_RST_I, WBS_WE_I, next_state, sel, valid_access
319
    -- outputs: data_str, led_reg, ctl_mr, dsp_control_r    
320
    write: process (WB_CLK_I, WB_RST_I) is
321
    begin
322
        if (WB_RST_I = '1') then
323
            ctl_mr           <= (others => '0');
324
            led_r            <= (others => '0');
325
            control_r        <= (others => '0');
326
            control_r(0)     <= '1';
327
            start_hpi_comm   <= '0';
328
            write_ir         <= '0';
329
                        hpi_dat_r        <= (others => '0');
330
            hpi_address_r    <= (others => '0');
331
            hpi_com_r        <= (others => '0');
332
            pci_address_r    <= (others => '0');
333
            pci_counter_r    <= (others => '0');
334
        elsif (rising_edge(WB_CLK_I)) then
335
            start_hpi_comm <= '0';
336
            write_ir  <= '0';
337
            if (next_state = ACK and WBS_WE_I = '1') then
338
                                case (local_address) is
339
                        when ADR_LED =>
340
                        led_r <= WBS_DAT_I(led_r'range);
341
                        when ADR_IR =>
342
                                    write_ir <= '1';
343
                        when ADR_MR =>
344
                        ctl_mr  <= WBS_DAT_I(ctl_mr'range);
345
                        when ADR_CONTROL =>
346
                            control_r <= WBS_DAT_I(control_r'range);
347
                        when ADR_HPI_COMM =>
348
                                start_hpi_comm <= '1';
349
                                hpi_com_r <= WBS_HPI_COMM;
350
                                hpi_dat_r (15 downto  0) <= WBS_HPI_DATA;
351
                                hpi_dat_r (17 downto 16) <= WBS_HPI_REG;
352
                        when ADR_HPI_PCI_ADR =>
353
                                pci_address_r <= WBS_DAT_I(pci_address_r'range);
354
                            when ADR_HPI_CNT =>
355
                                pci_counter_r <= WBS_DAT_I(pci_counter_r'range);
356
                            when ADR_MAP_DSP =>
357
                                start_hpi_comm <= '1';
358
                            hpi_com_r <= COM_MAP_WRITE;
359
                                                hpi_address_r  (15 downto 0) <= '0' & WBS_ADR_I(15 downto 2) & '0';
360
                                hpi_dat_r (15 downto 0) <= WBS_DAT_I(15 downto 0);
361
                                if (WBS_SEL_I(1) = '0') then
362
                                    hpi_address_r (0) <= '1';
363
                                    hpi_dat_r(15 downto 0) <= WBS_DAT_I(31 downto 16);
364
                                end if;
365
                                        when others => null;
366
                    end case;
367
            elsif (next_state = START_MAP_READ) then
368
                hpi_com_r <= COM_MAP_READ;
369
                start_hpi_comm <= '1';
370
                        hpi_address_r  (15 downto 0) <= '0' & WBS_ADR_I(15 downto 2) & '0';
371
                        if (WBS_SEL_I(1) = '0') then
372
                            hpi_address_r (0) <= '1';
373
                        end if;
374
            end if;
375
        end if;
376
    end process write;
377
 
378
    -- purpose: set/reset interrupt request 0
379
    -- type   : sequential
380
    -- inputs : WB_RST_I, WBS_DAT_I, data_str, sel_ir, hpi_int_req1 
381
    -- outputs: ctl_ir(0)
382
    interrupt_request0: process (WB_RST_I, WBS_DAT_I,
383
                                 write_ir, sel_ir, hpi_int_req1) is
384
    begin
385
        if (WB_RST_I = '1') then
386
           ctl_ir(0) <= '0';
387
        elsif (sel_ir = '1' and WBS_DAT_I(0) = '1') then
388
            if (write_ir = '1') then
389
                ctl_ir(0) <= '0';
390
            end if;
391
        elsif rising_edge(hpi_int_req1) then
392
           ctl_ir(0) <= '1';
393
        end if;
394
    end process interrupt_request0;
395
 
396
    -- purpose: set/reset interrupt request 1
397
    -- type   : sequential
398
    -- inputs : WB_RST_I, WBS_DAT_I, data_str, sel_ir, hpi_int_req2 
399
    -- outputs: ctl_ir(1)
400
    interrupt_request1: process (WB_RST_I, WBS_DAT_I,
401
                                 write_ir, sel_ir, hpi_int_req2) is
402
    begin
403
        if (WB_RST_I = '1') then
404
           ctl_ir(1) <= '0';
405
        elsif (sel_ir = '1' and WBS_DAT_I(1) = '1') then
406
            if (write_ir = '1') then
407
                ctl_ir(1) <= '0';
408
            end if;
409
        elsif rising_edge(hpi_int_req2) then
410
           ctl_ir(1) <= '1';
411
        end if;
412
    end process interrupt_request1;
413
 
414
    -- purpose: read access control
415
    -- type   : combinational 
416
    -- inputs : local_address, ctl_mr, ctl_ir, led_reg, hpi_counter, hpi_data_out, 
417
    --          hpi_pci_addr, dsp_control_r, dsp_status_r, hpi_comm_r
418
    -- outputs: WBS_DAT_O   
419
    read: process (local_address, hpi_dat_r, ctl_ir, ctl_mr, led_r, hpi_counter, hpi_data_out,
420
                   control_r, status_r, hpi_pci_addr, hpi_com_r, WBS_SEL_I) is
421
    begin
422
        WBS_DAT_O <= (others => '0');
423
        case (local_address) is
424
            when ADR_IR          => WBS_DAT_O(ctl_ir'range)       <= ctl_ir;
425
            when ADR_MR          => WBS_DAT_O(ctl_mr'range)       <= ctl_mr;
426
            when ADR_LED         => WBS_DAT_O(led_r'range)        <= led_r;
427
            when ADR_HPI_PCI_ADR => WBS_DAT_O(hpi_pci_addr'range) <= hpi_pci_addr;
428
            when ADR_HPI_READ    => WBS_DAT_O(hpi_data_out'range) <= hpi_data_out;
429
            when ADR_HPI_CNT     => WBS_DAT_O(hpi_counter'range)  <= hpi_counter;
430
            when ADR_HPI_COMM    => WBS_DAT_O(21 downto 20)       <= hpi_dat_r(17 downto 16);
431
                                    WBS_DAT_O(18 downto 16)       <= hpi_com_r;
432
            when ADR_CONTROL     => WBS_DAT_O(control_r'range)    <= control_r;
433
            when ADR_STATUS      => WBS_DAT_O(status_r'range)     <= status_r;
434
            when ADR_MAP_DSP     => WBS_DAT_O(15 downto 0)        <= hpi_data_out;
435
                                    if (WBS_SEL_I(1) = '0') then
436
                                        WBS_DAT_O(31 downto 16)   <= hpi_data_out;
437
                                    end if;
438
        when others => null;
439
        end case;
440
    end process read;
441
 
442
        hpi_data_r    <= hpi_dat_r;
443
        hpi_command_r <= hpi_com_r;
444
 
445
    -- purpose: set WB interrupt request signal (to PCI)
446
    -- type   : combinational 
447
    -- inputs : ctl_ir, ctl_mr 
448
    -- outputs: int_req 
449
    int_req <= (ctl_ir(0) and ctl_mr(0)) or
450
               (ctl_ir(1) and ctl_mr(1));
451
 
452
    -- purpose: drive dev. board LED
453
    -- type   : combinational 
454
    -- inputs : led_reg 
455
    -- outputs: led
456
          led <= not led_r(0);
457
--    led <= not control_r(0);        
458
 
459
    -- purpose: Reset DSP
460
    -- type   : combinational 
461
    -- inputs : dsp_control_r(0)
462
    -- outputs: dsp_reset
463
    dsp_reset <= not control_r(0);
464
 
465
    -- purpose: Reset HPI interface
466
    -- type   : combinational 
467
    -- inputs : dsp_control_r(1)
468
    -- outputs: hpi_reset
469
    hpi_reset <= control_r(1);
470
 
471
 
472
    -- purpose: DSP Status register
473
    -- type   : combinational 
474
    -- inputs : hpi_data_is_rdy, hpi_end_transfer, hpi_ready,
475
    --          dsp_ready, dsp_hint, pci_error
476
    -- outputs: dsp_status_r
477
    status_r(0) <= hpi_data_is_rdy;
478
    status_r(1) <= hpi_end_transfer;
479
    status_r(2) <= hpi_ready;
480
    status_r(3) <= pci_error;
481
    status_r(4) <= dsp_ready;
482
    status_r(5) <= dsp_hint;
483
 
484
end architecture behavioral;
485
 
486
 
487
 
488
 
489
 
490
 
491
 
492
 
493
 
494
 
495
 
496
 
497
 
498
 
499
 
500
 
501
 
502
 
503
 
504
 
505
 
506
 

powered by: WebSVN 2.1.0

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