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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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