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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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