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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 8 wfjm
-- $Id: ibdr_rk11.vhd 335 2010-10-24 22:24:23Z 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_rk11 - syn
16
-- Description:    ibus dev(rem): RK11-A/B
17
--
18
-- Dependencies:   ram_1swar_gen
19
-- Test bench:     -
20
-- Target Devices: generic
21 8 wfjm
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 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 8 wfjm
-- 2010-10-17   333  12.1    M53 xc3s1000-4    46  248   16  137 s  7.2
26 2 wfjm
-- 2009-06-01   221  10.1.03 K39 xc3s1000-4    46  249   16  148 s  7.1
27
-- 2008-01-06   111   8.2.03 I34 xc3s1000-4    36  189   16  111 s  6.0
28
--
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-05-24   219   1.0.9  add CE_MSEC input; inc sector counter every msec
35
--                           BUGFIX: sector counter now counts 000,...,013.
36
-- 2009-05-21   217   1.0.8  cancel pending interrupt requests when IE=0
37
-- 2009-05-16   216   1.0.7  BUGFIX: correct interrupt on IE 0->1 logic
38
--                           BUGFIX: re-work the seek complete handling
39
-- 2008-08-22   161   1.0.6  use iblib
40
-- 2008-05-30   151   1.0.5  BUGFIX: do control reset locally now, add CRDONE
41
-- 2008-03-30   131   1.0.4  issue interrupt when IDE bit set with GO=0
42
-- 2008-02-23   118   1.0.3  remove redundant condition in rkda access code
43
--                           fix bug in control reset logic (we's missing)
44
-- 2008-01-20   113   1.0.2  Fix busy handling when control reset done
45
-- 2008-01-20   112   1.0.1  Fix scp handling; use BRESET
46
-- 2008-01-06   111   1.0    Initial version 
47
------------------------------------------------------------------------------
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.std_logic_arith.all;
52
 
53
use work.slvtypes.all;
54
use work.memlib.all;
55
use work.iblib.all;
56
 
57
-- ----------------------------------------------------------------------------
58
entity ibdr_rk11 is                     -- ibus dev(rem): RK11
59
                                        -- fixed address: 177400
60
  port (
61
    CLK : in slbit;                     -- clock
62
    CE_MSEC : in slbit;                 -- msec pulse
63
    BRESET : in slbit;                  -- ibus reset
64 8 wfjm
    RB_LAM : out slbit;                 -- remote attention
65 2 wfjm
    IB_MREQ : in ib_mreq_type;          -- ibus request
66
    IB_SRES : out ib_sres_type;         -- ibus response
67
    EI_REQ : out slbit;                 -- interrupt request
68
    EI_ACK : in slbit                   -- interrupt acknowledge
69
  );
70
end ibdr_rk11;
71
 
72
architecture syn of ibdr_rk11 is
73
 
74
  constant ibaddr_rk11 : slv16 := conv_std_logic_vector(8#177400#,16);
75
 
76
  constant ibaddr_rkds : slv3 := "000";  -- rkds address offset
77
  constant ibaddr_rker : slv3 := "001";  -- rker address offset
78
  constant ibaddr_rkcs : slv3 := "010";  -- rkcs address offset
79
  constant ibaddr_rkwc : slv3 := "011";  -- rkwc address offset
80
  constant ibaddr_rkba : slv3 := "100";  -- rkba address offset
81 5 wfjm
  constant ibaddr_rkda : slv3 := "101";  -- rkda address offset
82 2 wfjm
  constant ibaddr_rkmr : slv3 := "110";  -- rkmr address offset
83
  constant ibaddr_rkdb : slv3 := "111";  -- rkdb address offset
84
 
85
  subtype  rkds_ibf_id      is integer range 15 downto 13;
86
  constant rkds_ibf_adry  : integer :=  6;
87
  constant rkds_ibf_scsa  : integer :=  4;
88
  subtype  rkds_ibf_sc      is integer range  3 downto  0;
89
 
90
  subtype  rker_ibf_he      is integer range 15 downto  5;
91
  constant rker_ibf_cse   : integer :=  1;
92
  constant rker_ibf_wce   : integer :=  0;
93
 
94
  constant rkcs_ibf_err   : integer := 15;
95
  constant rkcs_ibf_he    : integer := 14;
96
  constant rkcs_ibf_scp   : integer := 13;
97
  constant rkcs_ibf_maint : integer := 12;
98
  constant rkcs_ibf_rdy   : integer :=  7;
99
  constant rkcs_ibf_ide   : integer :=  6;
100
  subtype  rkcs_ibf_mex     is integer range  5 downto  4;
101
  subtype  rkcs_ibf_func    is integer range  3 downto  1;
102
  constant rkcs_ibf_go    : integer :=  0;
103
 
104
  subtype  rkda_ibf_drsel   is integer range 15 downto 13;
105
 
106
  subtype  rkmr_ibf_rid     is integer range 15 downto 13;  -- rem id
107
  constant rkmr_ibf_crdone: integer := 11;                  -- contr. reset done
108
  constant rkmr_ibf_sbclr : integer := 10;                  -- clear sbusy's 
109
  constant rkmr_ibf_creset: integer :=  9;                  -- control reset
110
  constant rkmr_ibf_fdone : integer :=  8;                  -- func done
111
  subtype  rkmr_ibf_sdone   is integer range  7 downto  0;  -- seek done
112
 
113
  type state_type is (
114
    s_idle,
115
    s_init
116
  );
117
 
118
  type regs_type is record              -- state registers
119 8 wfjm
    ibsel : slbit;                      -- ibus select
120 2 wfjm
    state : state_type;                 -- state
121
    id : slv3;                          -- rkds: drive id of search done
122
    sc : slv4;                          -- rkds: sector counter
123
    cse : slbit;                        -- rker: check sum error
124
    wce : slbit;                        -- rker: write check error
125
    he : slbit;                         -- rkcs: hard error
126
    scp : slbit;                        -- rkcs: seek complete
127
    maint : slbit;                      -- rkcs: maintenance mode
128
    rdy   : slbit;                      -- rkcs: control ready
129
    ide   : slbit;                      -- rkcs: interrupt on done enable
130
    drsel : slv3;                       -- rkda: currently selected drive
131
    fireq : slbit;                      -- func done interrupt request flag
132
    sireq : slv8;                       -- seek done interrupt request flags
133
    sbusy : slv8;                       -- seek busy flags
134
    rid   : slv3;                       -- drive id for rem ds reads
135
    icnt  : slv3;                       -- init state counter
136
    creset : slbit;                     -- control reset flag
137
    crdone : slbit;                     -- control reset done since last fdone
138
  end record regs_type;
139
 
140
  constant regs_init : regs_type := (
141 8 wfjm
    '0',                                -- ibsel
142
    s_init,                             -- state
143 2 wfjm
    (others=>'0'),                      -- id
144
    (others=>'0'),                      -- sc
145
    '0','0',                            -- cse, wce
146
    '0','0','0',                        -- he, scp, maint
147
    '1',                                -- rdy (SET TO 1)
148
    '0',                                -- ide
149
    (others=>'0'),                      -- drsel
150
    '0',                                -- fireq
151
    (others=>'0'),                      -- sireq
152
    (others=>'0'),                      -- sbusy
153
    (others=>'0'),                      -- rid
154
    (others=>'0'),                      -- icnt
155
    '0','1'                             -- creset, crdone
156
  );
157
 
158
  signal R_REGS : regs_type := regs_init;
159
  signal N_REGS : regs_type := regs_init;
160
 
161
  signal MEM_1_WE : slbit := '0';
162
  signal MEM_0_WE : slbit := '0';
163
  signal MEM_ADDR : slv4  := (others=>'0');
164
  signal MEM_DIN  : slv16 := (others=>'0');
165
  signal MEM_DOUT : slv16 := (others=>'0');
166
 
167
begin
168
 
169
  MEM_1 : ram_1swar_gen
170
    generic map (
171
      AWIDTH => 4,
172
      DWIDTH => 8)
173
    port map (
174
      CLK  => CLK,
175
      WE   => MEM_1_WE,
176
      ADDR => MEM_ADDR,
177
      DI   => MEM_DIN(ibf_byte1),
178
      DO   => MEM_DOUT(ibf_byte1));
179
 
180
  MEM_0 : ram_1swar_gen
181
    generic map (
182
      AWIDTH => 4,
183
      DWIDTH => 8)
184
    port map (
185
      CLK  => CLK,
186
      WE   => MEM_0_WE,
187
      ADDR => MEM_ADDR,
188
      DI   => MEM_DIN(ibf_byte0),
189
      DO   => MEM_DOUT(ibf_byte0));
190
 
191
  proc_regs: process (CLK)
192
  begin
193
    if CLK'event and CLK='1' then
194
      if BRESET='1' or R_REGS.creset='1' then
195
        R_REGS <= regs_init;
196
        if R_REGS.creset = '1' then
197
          R_REGS.sbusy <= N_REGS.sbusy;
198
        end if;
199
      else
200
        R_REGS <= N_REGS;
201
      end if;
202
    end if;
203
  end process proc_regs;
204
 
205
  proc_next : process (R_REGS, CE_MSEC, IB_MREQ, MEM_DOUT, EI_ACK)
206
    variable r : regs_type := regs_init;
207
    variable n : regs_type := regs_init;
208 8 wfjm
    variable ibhold : slbit := '0';
209 2 wfjm
    variable icrip  : slbit := '0';
210
    variable idout  : slv16 := (others=>'0');
211 8 wfjm
    variable ibrem  : slbit := '0';
212
    variable ibreq  : slbit := '0';
213 2 wfjm
    variable ibrd   : slbit := '0';
214
    variable ibw0   : slbit := '0';
215
    variable ibw1   : slbit := '0';
216
    variable ibwrem : slbit := '0';
217
    variable ilam   : slbit := '0';
218
    variable iscval : slbit := '0';
219
    variable iscid : slv3 := (others=>'0');
220
    variable iei_req : slbit := '0';
221
 
222
    variable imem_we0 : slbit := '0';
223
    variable imem_we1 : slbit := '0';
224
    variable imem_addr : slv4 := (others=>'0');
225
    variable imem_din : slv16 := (others=>'0');
226
  begin
227
 
228
    r := R_REGS;
229
    n := R_REGS;
230
 
231 8 wfjm
    ibhold := '0';
232 2 wfjm
    icrip  := '0';
233
    idout  := (others=>'0');
234
    ibrem  := IB_MREQ.racc or r.maint;
235 8 wfjm
    ibreq  := IB_MREQ.re or IB_MREQ.we;
236
    ibrd   := IB_MREQ.re;
237 2 wfjm
    ibw0   := IB_MREQ.we and IB_MREQ.be0;
238
    ibw1   := IB_MREQ.we and IB_MREQ.be1;
239
    ibwrem := IB_MREQ.we and ibrem;
240
    ilam   := '0';
241
    iscval := '0';
242
    iscid  := (others=>'0');
243
    iei_req := '0';
244
 
245
    imem_we0  := '0';
246
    imem_we1  := '0';
247
    imem_addr := '0' & IB_MREQ.addr(3 downto 1);
248
    imem_din  := IB_MREQ.din;
249
 
250
    -- ibus address decoder
251 8 wfjm
    n.ibsel := '0';
252
    if IB_MREQ.aval = '1' and
253 2 wfjm
       IB_MREQ.addr(12 downto 4)=ibaddr_rk11(12 downto 4) then
254 8 wfjm
      n.ibsel := '1';
255 2 wfjm
    end if;
256
 
257
    -- internal state machine (for control reset)
258
    case r.state is
259
      when s_idle =>
260
        null;
261
 
262
      when s_init =>
263 8 wfjm
        ibhold := r.ibsel;              -- hold ibus when controller busy
264 2 wfjm
        icrip  := '1';
265
        n.icnt := unsigned(r.icnt) + 1;
266
        if unsigned(r.icnt) = 7 then
267
          n.state := s_idle;
268
        end if;
269
 
270
      when others => null;
271
    end case;
272
 
273
 
274
    -- ibus transactions
275 8 wfjm
 
276
    if r.ibsel='1' and ibhold='0' then  -- selected and not holding
277 2 wfjm
      idout := MEM_DOUT;
278
      imem_we0 := ibw0;
279
      imem_we1 := ibw1;
280
 
281
      case IB_MREQ.addr(3 downto 1) is
282
 
283
        when ibaddr_rkds =>              -- RKDS -- drive status register ----
284
          if ibrem = '0' then
285
            imem_addr := '1' & r.drsel;  -- loc read ds data: drsel as addr.
286
          else
287
            imem_addr := '1' & r.rid;    -- rem read ds data: rid as addr.
288
          end if;
289
          idout(rkds_ibf_id) := r.id;
290
          if ibrem = '0' then            -- loc ? simulate drive sector monitor
291
            if r.sc = MEM_DOUT(rkds_ibf_sc) then
292
              idout(rkds_ibf_scsa) := '1';
293
            else
294
              idout(rkds_ibf_scsa) := '0';
295
            end if;
296
            idout(rkds_ibf_sc) := r.sc;
297
          end if;
298
 
299
          if r.sbusy(conv_integer(unsigned(imem_addr(2 downto 0))))='1' then
300
            idout(rkds_ibf_adry) := '0';             -- clear drive access rdy
301
          end if;
302
 
303
          if ibwrem = '1' then            -- rem write ? than update ds data
304
            imem_addr := '1' & IB_MREQ.din(rkds_ibf_id); -- use id field as addr
305
          else                          -- loc write ?
306
            imem_we0 := '0';              -- suppress we, is read-only
307
            imem_we1 := '0';
308
          end if;
309
 
310
        when ibaddr_rker =>             -- RKER -- error register ------------
311
          idout(4 downto 2) := (others=>'0');  -- unassigned bits
312
          idout(rker_ibf_cse) := r.cse; -- use state bits (cleared at go !) 
313
          idout(rker_ibf_wce) := r.wce;
314
 
315
          if ibwrem = '1' then          -- rem write ?
316
            if unsigned(IB_MREQ.din(rker_ibf_he)) /= 0 then -- hard errors set ?
317
              n.he := '1';
318
            else
319
              n.he := '0';
320
            end if;
321
            n.cse := IB_MREQ.din(rker_ibf_cse); -- mirror cse bit
322
            n.wce := IB_MREQ.din(rker_ibf_wce); -- mirror wce bit
323
          else                          -- loc write ?
324
            imem_we0 := '0';              -- suppress we, is read-only
325
            imem_we1 := '0';
326
          end if;
327
 
328
        when ibaddr_rkcs =>             -- RKCS -- control status register ---
329
          idout(rkcs_ibf_err) := r.he or r.cse or r.wce;
330
          idout(rkcs_ibf_he)  := r.he;
331
          idout(rkcs_ibf_scp) := r.scp;
332
          idout(rkcs_ibf_rdy) := r.rdy;
333
          idout(rkcs_ibf_go)  := not r.rdy;
334
 
335
          if ibw1 = '1' then
336
            n.maint := IB_MREQ.din(rkcs_ibf_maint); -- mirror maint bit
337
          end if;
338
 
339
          if ibw0 = '1' then
340
            n.ide   := IB_MREQ.din(rkcs_ibf_ide);   -- mirror ide bit
341
            if n.ide = '0' then                     -- if IE 0 or set to 0
342
              n.fireq := '0';                         -- cancel all pending
343
              n.sireq := (others=>'0');               -- interrupt requests
344
            end if;
345
 
346
            if IB_MREQ.din(rkcs_ibf_go) = '1' then    -- GO=1 ?
347
              if r.rdy = '1' then                       -- ready and GO ?
348
                n.scp := '0';                             -- go clears scp !
349
                n.rdy := '0';                             -- mark busy
350
                n.cse := '0';                             -- clear soft errors
351
                n.wce := '0';
352
                n.fireq := '0';                           -- cancel pend. int
353
 
354
                if unsigned(IB_MREQ.din(rkcs_ibf_func))=0 then -- control reset?
355
                  n.creset := '1';                        -- handle locally
356
                else
357
                  ilam  := '1';                           -- issue lam
358
                end if;
359
 
360
                if unsigned(IB_MREQ.din(rkcs_ibf_func))=4 or   -- if seek
361
                   unsigned(IB_MREQ.din(rkcs_ibf_func))=6 then -- or drive reset
362
                  n.sbusy(conv_integer(unsigned(r.drsel))) := '1'; -- set busy
363
                end if;
364
 
365
              end if;
366
            else                                      -- GO=0
367
              if r.ide = '0' and                        -- if ide now 0
368
                 IB_MREQ.din(rkcs_ibf_ide)='1' and      -- and is set to 1
369
                 r.rdy='1' then                         -- and controller ready
370
                n.fireq := '1';                           -- issue interrupt
371
              end if;
372
            end if;
373
          end if;
374
 
375
        when ibaddr_rkda =>             -- RKDA -- disk address register -----
376
          if ibrem = '0' then           -- loc access ?
377
            if r.rdy = '0' then           -- controller busy ?
378
              imem_we0 := '0';              -- suppress write
379
              imem_we1 := '0';
380
            end if;
381
          end if;
382
          if imem_we1 = '1' then
383
            n.drsel := IB_MREQ.din(rkda_ibf_drsel); -- mirror drsel bits
384
          end if;
385
 
386
        when ibaddr_rkmr =>             -- RKMR -- maintenance register ------
387
          idout := (others=>'0');
388
          idout(rkmr_ibf_rid)    := r.rid;
389
          idout(rkmr_ibf_crdone) := r.crdone;
390
          idout(rkmr_ibf_sdone)  := r.sbusy;
391
          if ibwrem = '1' then          -- rem write ?
392
            n.rid := IB_MREQ.din(rkmr_ibf_rid);
393
 
394
            if r.ide='1' and IB_MREQ.din(rkmr_ibf_sbclr)='0' then
395
              n.sireq := r.sireq or (IB_MREQ.din(rkmr_ibf_sdone) and r.sbusy);
396
            end if;
397
            n.sbusy := r.sbusy and not IB_MREQ.din(rkmr_ibf_sdone);
398
 
399
            if IB_MREQ.din(rkmr_ibf_fdone) = '1' then -- func completed
400
              n.rdy    := '1';
401
              n.crdone := '0';
402
              if r.ide = '1' then
403
                n.fireq  := '1';
404
              end if;
405
            end if;
406
            if IB_MREQ.din(rkmr_ibf_creset) = '1' then -- control reset
407
              n.creset := '1';
408
            end if;
409
          end if;
410
 
411
        when others =>                  -- all other regs
412
          null;
413
 
414
      end case;
415
 
416
    end if;
417
 
418
    iscval := '1';
419
       if r.sireq(7) = '1' then  iscid := "111";
420
    elsif r.sireq(6) = '1' then  iscid := "110";
421
    elsif r.sireq(5) = '1' then  iscid := "101";
422
    elsif r.sireq(4) = '1' then  iscid := "100";
423
    elsif r.sireq(3) = '1' then  iscid := "011";
424
    elsif r.sireq(2) = '1' then  iscid := "010";
425
    elsif r.sireq(1) = '1' then  iscid := "001";
426
    elsif r.sireq(0) = '1' then  iscid := "000";
427
    else
428
      iscval := '0';
429
    end if;
430
 
431
    if r.ide = '1' then
432
      if r.fireq='1' or iscval='1' then
433
        iei_req := '1';
434
      end if;
435
    end if;
436
 
437
    if EI_ACK = '1' then                -- interrupt executed
438
      if r.fireq = '1' then
439
        n.scp   := '0';                   -- clear scp flag, is command end
440
        n.fireq := '0';
441
      elsif iscval = '1' then             -- was a seek done
442
        n.scp := '1';                     -- signal seek complete interrupt
443
        n.id := iscid;                        -- load id
444
        n.sireq(conv_integer(unsigned(iscid))) := '0';  -- reset sireq bit
445
      end if;
446
    end if;
447
 
448
    if icrip = '1' then                 -- control reset in progress ?
449
      imem_addr := '0' & r.icnt;          -- use icnt as addr
450
      imem_din  := (others=>'0');         -- force data to zero
451
      imem_we0  := '1';                   -- enable writes
452
      imem_we1  := '1';
453
    end if;
454
 
455
    if CE_MSEC = '1' then               -- advance sector counter every msec
456
      if unsigned(r.sc) = 8#13# then      -- sector counter (count to 8#13#)
457
        n.sc := (others=>'0');
458
      else
459
        n.sc := unsigned(r.sc) + 1;
460
      end if;
461
    end if;
462
 
463
    N_REGS <= n;
464
 
465
    MEM_0_WE <= imem_we0;
466
    MEM_1_WE <= imem_we1;
467
    MEM_ADDR <= imem_addr;
468
    MEM_DIN  <= imem_din;
469
 
470
    IB_SRES.dout <= idout;
471 8 wfjm
    IB_SRES.ack  <= r.ibsel and ibreq;
472
    IB_SRES.busy <= ibhold  and ibreq;
473 2 wfjm
 
474 8 wfjm
    RB_LAM <= ilam;
475
    EI_REQ <= iei_req;
476 2 wfjm
 
477
  end process proc_next;
478
 
479
 
480
end syn;

powered by: WebSVN 2.1.0

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