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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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