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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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