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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [rtl/] [ibus/] [ibdr_dl11.vhd] - Blame information for rev 9

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

Line No. Rev Author Line
1 9 wfjm
-- $Id: ibdr_dl11.vhd 350 2010-12-28 16:40:11Z mueller $
2 2 wfjm
--
3
-- Copyright 2008-2010 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Module Name:    ibdr_dl11 - syn
16
-- Description:    ibus dev(rem): DL11-A/B
17
--
18
-- Dependencies:   -
19
-- Test bench:     -
20
-- Target Devices: generic
21 8 wfjm
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 10.1, 12.1; ghdl 0.18-0.29
22 2 wfjm
--
23
-- Synthesized (xst):
24
-- Date         Rev  ise         Target      flop lutl lutm slic t peri
25 9 wfjm
-- 2010-10-17   333 12.1    M53d xc3s1000-4    39  126    0   72 s  7.6
26
-- 2009-07-12   233 10.1.03 K39  xc3s1000-4    38  119    0   69 s  6.3
27
-- 2009-07-11   232 10.1.03 K39  xc3s1000-4    23   61    0   40 s  5.5
28 2 wfjm
--
29
-- Revision History: 
30
-- Date         Rev Version  Comment
31 8 wfjm
-- 2010-10-23   335   1.2.1  rename RRI_LAM->RB_LAM;
32
-- 2010-10-17   333   1.2    use ibus V2 interface
33 2 wfjm
-- 2010-06-11   303   1.1    use IB_MREQ.racc instead of RRI_REQ
34
-- 2009-07-12   233   1.0.5  add RESET, CE_USEC port; implement input rate limit
35
-- 2008-08-22   161   1.0.6  use iblib; add EI_ACK_* to proc_next sens. list
36
-- 2008-05-09   144   1.0.5  use intreq flop, use EI_ACK
37
-- 2008-03-22   128   1.0.4  rename xdone -> xval (no functional change)
38
-- 2008-01-27   115   1.0.3  bugfix: set ilam when rbuf read by cpu;
39
--                           add xdone and rrdy bits to rri xbuf read
40
-- 2008-01-20   113   1.0.2  fix maint mode logic (proper double buffer now)
41
-- 2008-01-20   112   1.0.1  use BRESET
42
-- 2008-01-05   108   1.0    Initial version 
43
------------------------------------------------------------------------------
44
 
45
library ieee;
46
use ieee.std_logic_1164.all;
47
use ieee.std_logic_arith.all;
48
 
49
use work.slvtypes.all;
50
use work.iblib.all;
51
 
52
-- ----------------------------------------------------------------------------
53
entity ibdr_dl11 is                     -- ibus dev(rem): DL11-A/B
54
  generic (
55
    IB_ADDR : slv16 := conv_std_logic_vector(8#177560#,16));
56
  port (
57
    CLK : in slbit;                     -- clock
58
    CE_USEC : in slbit;                 -- usec pulse
59
    RESET : in slbit;                   -- system reset
60
    BRESET : in slbit;                  -- ibus reset
61 8 wfjm
    RB_LAM : out slbit;                 -- remote attention
62 2 wfjm
    IB_MREQ : in ib_mreq_type;          -- ibus request
63
    IB_SRES : out ib_sres_type;         -- ibus response
64
    EI_REQ_RX : out slbit;              -- interrupt request, receiver
65
    EI_REQ_TX : out slbit;              -- interrupt request, transmitter
66
    EI_ACK_RX : in slbit;               -- interrupt acknowledge, receiver
67
    EI_ACK_TX : in slbit                -- interrupt acknowledge, transmitter
68
  );
69
end ibdr_dl11;
70
 
71
architecture syn of ibdr_dl11 is
72
 
73
  constant ibaddr_rcsr : slv2 := "00";  -- rcsr address offset
74
  constant ibaddr_rbuf : slv2 := "01";  -- rbuf address offset
75
  constant ibaddr_xcsr : slv2 := "10";  -- xcsr address offset
76
  constant ibaddr_xbuf : slv2 := "11";  -- xbuf address offset
77
 
78
  subtype  rcsr_ibf_rrlim   is integer range 14 downto 12;
79
  constant rcsr_ibf_rdone : integer :=  7;
80
  constant rcsr_ibf_rie :   integer :=  6;
81
 
82
  constant xcsr_ibf_xrdy :  integer :=  7;
83
  constant xcsr_ibf_xie :   integer :=  6;
84
  constant xcsr_ibf_xmaint: integer :=  2;
85
 
86
  constant xbuf_ibf_xval :  integer :=  8;
87
  constant xbuf_ibf_rrdy :  integer :=  9;
88
 
89
  type regs_type is record              -- state registers
90 8 wfjm
    ibsel : slbit;                      -- ibus select
91 2 wfjm
    rrlim : slv3;                       -- rcsr: receiver rate limit
92
    rdone : slbit;                      -- rcsr: receiver done
93
    rie : slbit;                        -- rcsr: receiver interrupt enable
94
    rbuf : slv8;                        -- rbuf:
95
    rval : slbit;                       -- rx rbuf valid
96
    rintreq : slbit;                    -- rx interrupt request
97
    rdlybsy : slbit;                    -- rx delay busy
98
    rdlycnt : slv10;                    -- rx delay counter
99
    xrdy : slbit;                       -- xcsr: transmitter ready
100
    xie : slbit;                        -- xcsr: transmitter interrupt enable
101
    xmaint : slbit;                     -- xcsr: maintenance mode
102
    xbuf : slv8;                        -- xbuf:
103
    xintreq : slbit;                    -- tx interrupt request
104
  end record regs_type;
105
 
106
  constant regs_init : regs_type := (
107 8 wfjm
    '0',                                -- ibsel
108 2 wfjm
    (others=>'0'),                      -- rrlim
109
    '0','0',                            -- rdone, rie
110
    (others=>'0'),                      -- rbuf
111
    '0','0','0',                        -- rval,rintreq,rdlybsy
112
    (others=>'0'),                      -- rdlycnt
113
    '1',                                -- xrdy !! is set !!
114
    '0','0',                            -- xie,xmaint
115
    (others=>'0'),                      -- xbuf
116
    '0'                                 -- xintreq
117
  );
118
 
119
  signal R_REGS : regs_type := regs_init;
120
  signal N_REGS : regs_type := regs_init;
121
 
122
begin
123
 
124
  proc_regs: process (CLK)
125
  begin
126
    if CLK'event and CLK='1' then
127
      if BRESET = '1' then
128
        R_REGS <= regs_init;
129
        if RESET = '0' then               -- if RESET=0 we do just an ibus reset
130
          R_REGS.rrlim   <= N_REGS.rrlim;   -- don't reset rx rate limit
131
          R_REGS.rdlybsy <= N_REGS.rdlybsy; -- don't reset rx delay busy
132
          R_REGS.rdlycnt <= N_REGS.rdlycnt; -- don't reset rx delay counter
133
        end if;
134 8 wfjm
      else
135 2 wfjm
        R_REGS <= N_REGS;
136
      end if;
137
    end if;
138
  end process proc_regs;
139
 
140
  proc_next : process (CE_USEC, R_REGS, IB_MREQ, EI_ACK_RX, EI_ACK_TX)
141
    variable r : regs_type := regs_init;
142
    variable n : regs_type := regs_init;
143
    variable idout : slv16 := (others=>'0');
144 8 wfjm
    variable ibreq : slbit := '0';
145 2 wfjm
    variable ibrd : slbit := '0';
146
    variable ibw0 : slbit := '0';
147
    variable ibw1 : slbit := '0';
148
    variable ilam : slbit := '0';
149
    variable rdlystart : slbit := '0';
150
    variable rdlyinit : slv10 := (others=>'0');
151
  begin
152
 
153
    r := R_REGS;
154
    n := R_REGS;
155
 
156
    idout := (others=>'0');
157 8 wfjm
    ibreq := IB_MREQ.re or IB_MREQ.we;
158
    ibrd  := IB_MREQ.re;
159 2 wfjm
    ibw0  := IB_MREQ.we and IB_MREQ.be0;
160
    ibw1  := IB_MREQ.we and IB_MREQ.be1;
161
    ilam  := '0';
162
    rdlystart := '0';
163
 
164
    -- ibus address decoder
165 8 wfjm
    n.ibsel := '0';
166
    if IB_MREQ.aval='1' and
167
       IB_MREQ.addr(12 downto 3)=IB_ADDR(12 downto 3) then
168
      n.ibsel := '1';
169 2 wfjm
    end if;
170
 
171
    -- ibus transactions
172 8 wfjm
    if r.ibsel = '1' then
173 2 wfjm
      case IB_MREQ.addr(2 downto 1) is
174
 
175
        when ibaddr_rcsr =>             -- RCSR -- receive control status ----
176
          idout(rcsr_ibf_rdone) := r.rdone;
177
          idout(rcsr_ibf_rie)   := r.rie;
178
 
179
          if IB_MREQ.racc = '0' then     -- cpu ---------------------
180
            if ibw0 = '1' then
181
              n.rie := IB_MREQ.din(rcsr_ibf_rie);
182
              if IB_MREQ.din(rcsr_ibf_rie) = '1' then
183
                if r.rdone='1' and r.rie='0' then -- ie set while done=1
184
                  n.rintreq := '1';               -- request interrupt
185
                end if;
186
              else
187
                n.rintreq := '0';
188
              end if;
189
            end if;
190
 
191
          else                          -- rri ---------------------
192
            idout(rcsr_ibf_rrlim) := r.rrlim;
193
            if ibw1 = '1' then
194
              n.rrlim := IB_MREQ.din(rcsr_ibf_rrlim);
195
            end if;
196
          end if;
197
 
198
        when ibaddr_rbuf =>             -- RBUF -- receive data buffer -------
199
 
200
          idout(r.rbuf'range)   := r.rbuf;
201
 
202
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
203
            if ibrd = '1' then
204
              n.rdone   := '0';           -- clear DONE
205
              n.rval    := '0';           -- clear rbuf valid
206
              n.rintreq := '0';           -- clear pending interrupts
207
              rdlystart := '1';           -- start rx delay counter
208
              if r.xmaint = '0' then      -- if not in loop-back
209
                ilam := '1';                -- request rb attention
210
              end if;
211
            end if;
212
 
213
          else                          -- rri ---------------------
214
            if ibw0 = '1' then
215
              n.rbuf := IB_MREQ.din(n.rbuf'range);
216
              n.rval := '1';              -- set rbuf valid
217
              if r.rdlybsy = '0' then     -- if rdly timer not running
218
                n.rdone := '1';             -- set DONE
219
                if r.rie = '1' then         -- if rx interrupt enabled
220
                  n.rintreq := '1';           -- request interrupt
221
                end if;
222
              end if;
223
            end if;
224
          end if;
225
 
226
        when ibaddr_xcsr =>             -- XCSR -- transmit control status ---
227
 
228
          idout(xcsr_ibf_xrdy)  := r.xrdy;
229
          idout(xcsr_ibf_xie)   := r.xie;
230
          idout(xcsr_ibf_xmaint):= r.xmaint;
231
 
232
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
233
            if ibw0 = '1' then
234
              n.xie   := IB_MREQ.din(xcsr_ibf_xie);
235
              if IB_MREQ.din(xcsr_ibf_xie) = '1' then
236
                if r.xrdy='1' and r.xie='0' then -- ie set while ready=1
237
                  n.xintreq := '1';               -- request interrupt
238
                end if;
239
              else
240
                n.xintreq := '0';
241
              end if;
242
              n.xmaint := IB_MREQ.din(xcsr_ibf_xmaint);
243
            end if;
244
          end if;
245
 
246
        when ibaddr_xbuf =>             -- XBUF -- transmit data buffer ------
247
 
248
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
249
            if ibw0 = '1' then
250
              n.xbuf := IB_MREQ.din(n.xbuf'range);
251
              n.xrdy := '0';
252
              n.xintreq := '0';
253
              if r.xmaint = '0' then
254
                ilam := '1';
255
              end if;
256
            end if;
257
 
258
          else                          -- rri ---------------------
259
            idout(r.xbuf'range)  := r.xbuf;
260
            if r.xmaint = '0' then        -- if not in maintenace mode
261
              idout(xbuf_ibf_xval) := not r.xrdy;
262
              idout(xbuf_ibf_rrdy) := not r.rval;
263
            end if;
264
            if ibrd = '1' then
265
              n.xrdy := '1';
266
              if r.xie = '1' then
267
                n.xintreq := '1';
268
              end if;
269
            end if;
270
          end if;
271
 
272
        when others => null;
273
      end case;
274
 
275
    else                                -- if unselected handle loop-back
276
      if r.xmaint = '1' and               -- if in maintenace mode
277
          r.xrdy='0' and                  -- and transmit pending
278
          r.rdone='0' and                 -- and receive buffer empty
279
          r.rdlybsy='0' then              -- and rdly timer not running
280
        n.rbuf  := r.xbuf;                  -- copy transmit to receive buffer
281
        n.xrdy  := '1';                     -- mark transmit done
282
        n.rdone := '1';                     -- make receive done
283
        if r.rie = '1' then                 -- if rx interrupt enabled
284
          n.rintreq := '1';                   -- request it
285
        end if;
286
        if r.xie = '1' then                 -- if tx interrupt enabled
287
          n.xintreq := '1';                   -- request it
288
        end if;
289
      end if;
290
 
291
    end if;
292
 
293
    -- other state changes
294
 
295
    rdlyinit := (others=>'0');
296
    case r.rrlim is
297
      when "000" => rdlyinit := "0000000000"; -- rlim=0 -> disabled
298
      when "001" => rdlyinit := "0000000011"; -- rlim=1 -> delay by    3+ usec
299
      when "010" => rdlyinit := "0000001111"; -- rlim=2 -> delay by   15+ usec
300
      when "011" => rdlyinit := "0000111111"; -- rlim=3 -> delay by   63+ usec
301
      when "100" => rdlyinit := "0001111111"; -- rlim=4 -> delay by  127+ usec
302
      when "101" => rdlyinit := "0011111111"; -- rlim=5 -> delay by  255+ usec
303
      when "110" => rdlyinit := "0111111111"; -- rlim=6 -> delay by  511+ usec
304
      when "111" => rdlyinit := "1111111111"; -- rlim=7 -> delay by 1023+ usec
305
      when others => null;
306
    end case;
307
 
308
    if rdlystart = '1' then                 -- if rdly timer start requested
309
      n.rdlycnt := rdlyinit;                  -- init counter
310
      if r.rrlim /= "000" then                -- rate limiter enabled ?
311
        n.rdlybsy := '1';                       -- set busy 
312
      end if;
313
    elsif CE_USEC = '1' then                -- if end-of-usec
314
      n.rdlycnt := unsigned(r.rdlycnt) - 1;   -- decrement
315
      if r.rdlybsy='1' and                   -- if delay busy
316
          unsigned(r.rdlycnt) = 0 then        --   and counter at zero
317
        n.rdlybsy := '0';                       -- clear busy
318
        if n.rval = '1' then                    -- if rbuf is valid or is set
319
                                                --   valid this cycle (use n.!!)
320
          n.rdone := '1';                         -- set DONE
321
          if r.rie = '1' then                     -- if rx interrupt enabled
322
            n.rintreq := '1';                       -- request interrupt 
323
          end if;
324
        end if;
325
      end if;
326
    end if;
327
 
328
    if EI_ACK_RX = '1' then
329
      n.rintreq := '0';
330
    end if;
331
    if EI_ACK_TX = '1' then
332
      n.xintreq := '0';
333
    end if;
334
 
335
    N_REGS <= n;
336
 
337
    IB_SRES.dout <= idout;
338 8 wfjm
    IB_SRES.ack  <= r.ibsel and ibreq;
339 2 wfjm
    IB_SRES.busy <= '0';
340
 
341 8 wfjm
    RB_LAM    <= ilam;
342 2 wfjm
    EI_REQ_RX <= r.rintreq;
343
    EI_REQ_TX <= r.xintreq;
344
 
345
  end process proc_next;
346
 
347
 
348
end syn;

powered by: WebSVN 2.1.0

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