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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 13 wfjm
-- $Id: ibdr_pc11.vhd 427 2011-11-19 21:04:11Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2009-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_pc11 - syn
16
-- Description:    ibus dev(rem): PC11
17
--
18
-- Dependencies:   -
19
-- Test bench:     xxdp: zpcae0
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    26   97    0   57 s  6.0
26
-- 2009-06-28   230 10.1.03 K39  xc3s1000-4    25   92    0   54 s  4.9
27 2 wfjm
--
28
-- Revision History: 
29
-- Date         Rev Version  Comment
30 13 wfjm
-- 2011-11-18   427   1.2.2  now numeric_std clean
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-06-28   230   1.0    prdy now inits to '1'; setting err bit in csr now
35
--                           causes interrupt, if enabled; validated with zpcae0
36
-- 2009-06-01   221   0.9    Initial version (untested)
37
------------------------------------------------------------------------------
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41 13 wfjm
use ieee.numeric_std.all;
42 2 wfjm
 
43
use work.slvtypes.all;
44
use work.iblib.all;
45
 
46
-- ----------------------------------------------------------------------------
47
entity ibdr_pc11 is                     -- ibus dev(rem): PC11
48
                                        -- fixed address: 177550
49
  port (
50
    CLK : in slbit;                     -- clock
51
    RESET : in slbit;                   -- system reset
52
    BRESET : in slbit;                  -- ibus reset
53 8 wfjm
    RB_LAM : out slbit;                 -- remote attention
54 2 wfjm
    IB_MREQ : in ib_mreq_type;          -- ibus request
55
    IB_SRES : out ib_sres_type;         -- ibus response
56
    EI_REQ_PTR : out slbit;             -- interrupt request, reader
57
    EI_REQ_PTP : out slbit;             -- interrupt request, punch
58
    EI_ACK_PTR : in slbit;              -- interrupt acknowledge, reader
59
    EI_ACK_PTP : in slbit               -- interrupt acknowledge, punch
60
  );
61
end ibdr_pc11;
62
 
63
architecture syn of ibdr_pc11 is
64
 
65 13 wfjm
  constant ibaddr_pc11 : slv16 := slv(to_unsigned(8#177550#,16));
66 2 wfjm
 
67
  constant ibaddr_rcsr : slv2 := "00";  -- rcsr address offset
68
  constant ibaddr_rbuf : slv2 := "01";  -- rbuf address offset
69
  constant ibaddr_pcsr : slv2 := "10";  -- pcsr address offset
70
  constant ibaddr_pbuf : slv2 := "11";  -- pbuf address offset
71
 
72
  constant rcsr_ibf_rerr :  integer := 15;
73
  constant rcsr_ibf_rbusy : integer := 11;
74
  constant rcsr_ibf_rdone : integer :=  7;
75
  constant rcsr_ibf_rie :   integer :=  6;
76
  constant rcsr_ibf_renb :  integer :=  0;
77
 
78
  constant pcsr_ibf_perr :  integer := 15;
79
  constant pcsr_ibf_prdy :  integer :=  7;
80
  constant pcsr_ibf_pie :   integer :=  6;
81
 
82
  constant pbuf_ibf_pval :  integer :=  8;
83
  constant pbuf_ibf_rbusy : integer :=  9;
84
 
85
  type regs_type is record              -- state registers
86 8 wfjm
    ibsel : slbit;                      -- ibus select
87 2 wfjm
    rerr : slbit;                       -- rcsr: reader error
88
    rbusy : slbit;                      -- rcsr: reader busy
89
    rdone : slbit;                      -- rcsr: reader done
90
    rie : slbit;                        -- rcsr: reader interrupt enable
91
    rbuf : slv8;                        -- rbuf:
92
    rintreq : slbit;                    -- ptr interrupt request
93
    perr : slbit;                       -- pcsr: punch error
94
    prdy : slbit;                       -- pcsr: punch ready
95
    pie : slbit;                        -- pcsr: punch interrupt enable
96
    pbuf : slv8;                        -- pbuf:
97
    pintreq : slbit;                    -- ptp interrupt request
98
  end record regs_type;
99
 
100
  constant regs_init : regs_type := (
101 8 wfjm
    '0',                                -- ibsel
102 2 wfjm
    '1',                                -- rerr (init=1!)
103
    '0','0','0',                        -- rbusy,rdone,rie
104
    (others=>'0'),                      -- rbuf
105
    '0',                                -- rintreq
106
    '1',                                -- perr (init=1!)
107
    '1',                                -- prdy (init=1!)
108
    '0',                                -- pie
109
    (others=>'0'),                      -- pbuf
110
    '0'                                 -- pintreq
111
  );
112
 
113
  signal R_REGS : regs_type := regs_init;
114
  signal N_REGS : regs_type := regs_init;
115
 
116
begin
117
 
118
  proc_regs: process (CLK)
119
  begin
120 13 wfjm
    if rising_edge(CLK) then
121 2 wfjm
      if BRESET = '1' then              -- BRESET is 1 for system and ibus reset
122
        R_REGS <= regs_init;            --
123
        if RESET = '0' then               -- if RESET=0 we do just an ibus reset
124
          R_REGS.rerr <= N_REGS.rerr;       -- don't reset RERR flag
125
          R_REGS.perr <= N_REGS.perr;       -- don't reset PERR flag
126
        end if;
127 8 wfjm
      else
128 2 wfjm
        R_REGS <= N_REGS;
129
      end if;
130
    end if;
131
  end process proc_regs;
132
 
133
  proc_next : process (R_REGS, IB_MREQ, EI_ACK_PTR, EI_ACK_PTP)
134
    variable r : regs_type := regs_init;
135
    variable n : regs_type := regs_init;
136
    variable idout : slv16 := (others=>'0');
137 8 wfjm
    variable ibreq : slbit := '0';
138 2 wfjm
    variable ibrd : slbit := '0';
139
    variable ibw0 : slbit := '0';
140
    variable ibw1 : slbit := '0';
141
    variable ilam : slbit := '0';
142
  begin
143
 
144
    r := R_REGS;
145
    n := R_REGS;
146
 
147 8 wfjm
    idout := (others=>'0');
148
    ibreq := IB_MREQ.re or IB_MREQ.we;
149
    ibrd  := IB_MREQ.re;
150
    ibw0  := IB_MREQ.we and IB_MREQ.be0;
151
    ibw1  := IB_MREQ.we and IB_MREQ.be1;
152
    ilam  := '0';
153 2 wfjm
 
154
    -- ibus address decoder
155 8 wfjm
    n.ibsel := '0';
156
    if IB_MREQ.aval='1' and
157 2 wfjm
       IB_MREQ.addr(12 downto 3)=ibaddr_pc11(12 downto 3) then
158 8 wfjm
      n.ibsel := '1';
159 2 wfjm
    end if;
160
 
161
    -- ibus transactions
162 8 wfjm
    if r.ibsel = '1' then
163 2 wfjm
      case IB_MREQ.addr(2 downto 1) is
164
 
165
        when ibaddr_rcsr =>             -- RCSR -- reader control status -----
166
 
167
          idout(rcsr_ibf_rerr)  := r.rerr;
168
          idout(rcsr_ibf_rbusy) := r.rbusy;
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-- set IE to 1
176
                if r.rie = '0' and                     -- IE 0->1 transition
177
                   IB_MREQ.din(rcsr_ibf_renb)='0' and  -- when RENB not set
178
                   (r.rerr='1' or r.rdone='1') then    -- but err or done set
179
                  n.rintreq := '1';                      -- request interrupt
180
                end if;
181
              else                                   -- set IE to 0
182
                n.rintreq := '0';                      -- cancel interrupts
183
              end if;
184
              if IB_MREQ.din(rcsr_ibf_renb) = '1' then -- set RENB
185
                if r.rerr = '0' then                   -- if not in error state
186
                  n.rbusy := '1';                        -- set busy
187
                  n.rdone := '0';                        -- clear done
188
                  n.rbuf  := (others=>'0');              -- clear buffer
189
                  n.rintreq := '0';                      -- cancel interrupt
190
                  ilam    := '1';                        -- rri lam
191
                else                                   -- if in error state
192
                  if r.rie = '1' then                    -- if interrupts on
193
                    n.rintreq := '1';                      -- request interrupt
194
                  end if;
195
                end if;
196
              end if;
197
            end if;
198
 
199
          else                          -- rri ---------------------
200
            if ibw1 = '1' then
201
              n.rerr := IB_MREQ.din(rcsr_ibf_rerr);  -- set ERR bit
202
              if IB_MREQ.din(rcsr_ibf_rerr)='1'      -- if 0->1 transition
203
                 and r.rerr='0' then
204
                n.rbusy := '0';                        -- clear busy
205
                n.rdone := '0';                        -- clear done
206
                if r.rie = '1' then                    -- if interrupts on
207
                  n.rintreq := '1';                      -- request interrupt
208
                end if;
209
              end if;
210
            end if;
211
          end if;
212
 
213
        when ibaddr_rbuf =>             -- RBUF -- reader data buffer --------
214
 
215
          idout(r.rbuf'range)   := r.rbuf;
216
 
217
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
218
            if true then                  -- !! PC11 is unusual !!
219
              n.rdone := '0';             -- any read or write will clear done
220
              n.rbuf  := (others=>'0');   -- and the reader buffer 
221
              n.rintreq := '0';           -- also interrupt is canceled
222
            end if;
223
 
224
          else                          -- rri ---------------------
225
            if ibw0 = '1' then
226
              n.rbuf := IB_MREQ.din(n.rbuf'range);
227
              n.rbusy := '0';
228
              n.rdone := '1';
229
              if r.rie = '1' then
230
                n.rintreq := '1';
231
              end if;
232
            end if;
233
          end if;
234
 
235
        when ibaddr_pcsr =>             -- PCSR -- punch control status ------
236
 
237
          idout(pcsr_ibf_perr)  := r.perr;
238
          idout(pcsr_ibf_prdy)  := r.prdy;
239
          idout(pcsr_ibf_pie)   := r.pie;
240
 
241
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
242
            if ibw0 = '1' then
243
              n.pie   := IB_MREQ.din(pcsr_ibf_pie);
244
              if IB_MREQ.din(pcsr_ibf_pie) = '1' then-- set IE to 1
245
                if r.pie='0' and                       -- IE 0->1 transition
246
                  (r.perr='1' or r.prdy='1') then      -- but err or done set
247
                  n.pintreq := '1';               -- request interrupt
248
                end if;
249
              else                                   -- set IE to 0
250
                n.pintreq := '0';                      -- cancel interrupts
251
              end if;
252
            end if;
253
 
254
          else                          -- rri ---------------------
255
            if ibw1 = '1' then
256
              n.perr := IB_MREQ.din(pcsr_ibf_perr);  -- set ERR bit
257
              if IB_MREQ.din(pcsr_ibf_perr)='1'      -- if 0->1 transition
258
                 and r.perr='0' then
259
                n.prdy := '1';                         -- set ready
260
                if r.pie = '1' then                    -- if interrupts on
261
                  n.pintreq := '1';                      -- request interrupt
262
                end if;
263
              end if;
264
            end if;
265
          end if;
266
 
267
        when ibaddr_pbuf =>             -- PBUF -- punch data buffer ---------
268
 
269
          if IB_MREQ.racc = '0' then    -- cpu ---------------------
270
            if ibw0 = '1' then
271
              if r.perr = '0' then        -- if not in error state
272
                n.pbuf := IB_MREQ.din(n.pbuf'range);
273
                n.prdy := '0';              -- clear ready
274
                n.pintreq := '0';           -- cancel interrupts
275
                ilam := '1';                -- rri lam
276
              else                        -- if in error state
277
                if r.pie = '1' then         -- if interrupts on
278
                  n.pintreq := '1';           -- request interrupt
279
                end if;
280
              end if;
281
            end if;
282
 
283
          else                          -- rri ---------------------
284
            idout(r.pbuf'range) := r.pbuf;
285
            idout(pbuf_ibf_pval)  := not r.prdy;
286
            idout(pbuf_ibf_rbusy) := r.rbusy;
287
            if ibrd = '1' then
288
              n.prdy := '1';
289
              if r.pie = '1' then
290
                n.pintreq := '1';
291
              end if;
292
            end if;
293
          end if;
294
 
295
        when others => null;
296
      end case;
297
 
298
    end if;
299
 
300
    -- other state changes
301
    if EI_ACK_PTR = '1' then
302
      n.rintreq := '0';
303
    end if;
304
    if EI_ACK_PTP = '1' then
305
      n.pintreq := '0';
306
    end if;
307
 
308
    N_REGS <= n;
309
 
310
    IB_SRES.dout <= idout;
311 8 wfjm
    IB_SRES.ack  <= r.ibsel and ibreq;
312 2 wfjm
    IB_SRES.busy <= '0';
313
 
314 8 wfjm
    RB_LAM     <= ilam;
315 2 wfjm
    EI_REQ_PTR <= r.rintreq;
316
    EI_REQ_PTP <= r.pintreq;
317
 
318
  end process proc_next;
319
 
320
 
321
end syn;

powered by: WebSVN 2.1.0

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