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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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