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 40

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

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

powered by: WebSVN 2.1.0

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