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