w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
ibd_kw11p.vhd
Go to the documentation of this file.
1-- $Id: ibd_kw11p.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2018-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: ibd_kw11p - syn
7-- Description: ibus dev(loc): KW11-P (programmable line clock)
8--
9-- Dependencies: -
10-- Test bench: -
11-- Target Devices: generic
12-- Tool versions: ise 14.7; viv 2017.2-2018.2; ghdl 0.34
13--
14-- Synthesized (xst):
15-- Date Rev ise Target flop lutl lutm slic t peri
16-- 2018-09-09 1043 14.7 131013 xc6slx16-2 61 110 0 42 s 6.2
17--
18-- Revision History:
19-- Date Rev Version Comment
20-- 2019-04-24 1138 1.1 add csr.ir; add rem controllable options for
21-- RATE=11: sysclk, 1 Mhz, extevt, none
22-- 2018-09-09 1043 1.0 Initial version
23------------------------------------------------------------------------------
24
25library ieee;
26use ieee.std_logic_1164.all;
27use ieee.numeric_std.all;
28
29use work.slvtypes.all;
30use work.iblib.all;
31
32-- ----------------------------------------------------------------------------
33entity ibd_kw11p is -- ibus dev(loc): KW11-P (line clock)
34 -- fixed address: 172540
35 port (
36 CLK : in slbit; -- clock
37 CE_USEC : in slbit; -- usec pulse
38 CE_MSEC : in slbit; -- msec pulse
39 RESET : in slbit; -- system reset
40 BRESET : in slbit; -- ibus reset
41 EXTEVT : in slbit; -- external event for RATE="11"
42 CPUSUSP : in slbit; -- cpu suspended
43 IB_MREQ : in ib_mreq_type; -- ibus request
44 IB_SRES : out ib_sres_type; -- ibus response
45 EI_REQ : out slbit; -- interrupt request
46 EI_ACK : in slbit -- interrupt acknowledge
47 );
48end ibd_kw11p;
49
50architecture syn of ibd_kw11p is
51
52 constant ibaddr_kw11p : slv16 := slv(to_unsigned(8#172540#,16));
53
54 constant ibaddr_csr : slv2 := "00"; -- csr address offset
55 constant ibaddr_csb : slv2 := "01"; -- csb address offset
56 constant ibaddr_ctr : slv2 := "10"; -- ctr address offset
57
58 constant csr_ibf_err : integer := 15;
59 constant csr_ibf_ir : integer := 10;
60 subtype csr_ibf_erate is integer range 9 downto 8;
61 constant csr_ibf_done : integer := 7;
62 constant csr_ibf_ie : integer := 6;
63 constant csr_ibf_fix : integer := 5;
64 constant csr_ibf_updn : integer := 4;
65 constant csr_ibf_mode : integer := 3;
66 subtype csr_ibf_rate is integer range 2 downto 1;
67 constant csr_ibf_run : integer := 0;
68
69 constant rate_100k : slv2 := "00";
70 constant rate_10k : slv2 := "01";
71 constant rate_line : slv2 := "10";
72 constant rate_ext : slv2 := "11";
73
74 constant erate_sclk : slv2 := "00";
75 constant erate_usec : slv2 := "01";
76 constant erate_ext : slv2 := "10";
77 constant erate_noop : slv2 := "11";
78
79 constant dwidth : natural := 4; -- decade divider
80 constant ddivide : natural := 10;
81 constant lwidth : natural := 5; -- msec -> 50 Hz divider
82 constant ldivide : natural := 20;
83
84 constant ctrzero : slv16 := (others=>'0');
85
86 type regs_type is record -- state registers
87 ibsel : slbit; -- ibus select
88 erate : slv2; -- ext rate mode
89 err : slbit; -- re-interrupt error
90 done : slbit; -- counter wrap occured
91 ie : slbit; -- interrupt enable
92 updn : slbit; -- 0=count-down; 1=count-up
93 mode : slbit; -- 0=single; 1=repeated interrupt
94 rate : slv2; -- 00=100kHz;01=10kHz;10=line;11=event
95 run : slbit; -- enable counter
96 csb : slv16; -- interval count
97 ctr : slv16; -- clock counter
98 intreq : slbit; -- interrupt request
99 lcnt : slv(lwidth-1 downto 0); -- line clock divider
100 d1cnt : slv(dwidth-1 downto 0); -- usec -> 100 kHz divider
101 d2cnt : slv(dwidth-1 downto 0); -- 100->10 kHz divider
102 evt100k : slbit; -- evt flag: 100 kHz
103 evt10k : slbit; -- evt flag: 10 kHz
104 evtline : slbit; -- evt flag: line clock
105 evtext : slbit; -- evt flag: external event
106 evtfix : slbit; -- evt flag: csr FIX
107 evtload : slbit; -- evt flag: load from csb
108 end record regs_type;
109
110 constant regs_init : regs_type := (
111 '0', -- ibsel
112 "00", -- erate
113 '0','0','0','0','0', -- err,done,ie,updn,mode
114 "00",'0', -- rate,run
115 (others=>'0'), -- csb
116 (others=>'0'), -- ctr
117 '0', -- intreq
118 (others=>'0'), -- lcnt
119 (others=>'0'), -- d1cnt
120 (others=>'0'), -- d2cnt
121 '0','0','0','0', -- evt100k,evt10k,evtline,evyevt
122 '0','0' -- evtfix,evtload
123 );
124
127
128begin
129
130 proc_regs: process (CLK)
131 begin
132 if rising_edge(CLK) then
133 if BRESET = '1' then -- BRESET is 1 for system and ibus reset
134 R_REGS <= regs_init;
135 if RESET = '0' then -- if RESET=0 we do just an ibus reset
136 R_REGS.erate <= N_REGS.erate; -- keep ERATE field
137 R_REGS.lcnt <= N_REGS.lcnt; -- don't clear clock dividers
138 R_REGS.d1cnt <= N_REGS.d1cnt; -- "
139 R_REGS.d2cnt <= N_REGS.d2cnt; -- "
140 end if;
141 else
142 R_REGS <= N_REGS;
143 end if;
144 end if;
145 end process proc_regs;
146
147 proc_next : process (R_REGS, IB_MREQ, CE_USEC, CE_MSEC,
149 variable r : regs_type := regs_init;
150 variable n : regs_type := regs_init;
151 variable idout : slv16 := (others=>'0');
152 variable ibreq : slbit := '0';
153 variable ibrd : slbit := '0';
154 variable ibwr : slbit := '0';
155 variable ievt : slbit := '0';
156 begin
157
158 r := R_REGS;
159 n := R_REGS;
160
161 idout := (others=>'0');
162 ibreq := IB_MREQ.re or IB_MREQ.we;
163 ibrd := IB_MREQ.re;
164 ibwr := IB_MREQ.we;
165
166 ievt := '0';
167
168 n.evtext := '0';
169 case r.erate is
170 when erate_sclk => n.evtext := '1';
171 when erate_usec => n.evtext := CE_USEC;
172 when erate_ext => n.evtext := EXTEVT;
173 when erate_noop => n.evtext := '0';
174 when others => null;
175 end case;
176 n.evt100k := '0'; -- one shot
177 n.evt10k := '0'; -- one shot
178 n.evtline := '0'; -- one shot
179 n.evtfix := '0'; -- one shot
180 n.evtload := '0'; -- one shot
181
182 -- ibus address decoder
183 n.ibsel := '0';
184 if IB_MREQ.aval='1' and
185 IB_MREQ.addr(12 downto 3)=ibaddr_kw11p(12 downto 3) and -- is in 17254*
186 IB_MREQ.addr(2 downto 1) /= "11" then -- is not *****6
187 n.ibsel := '1';
188 end if;
189
190 -- ibus transactions
191 if r.ibsel='1' then
192 case IB_MREQ.addr(2 downto 1) is
193 when ibaddr_csr => -- CSR -- control and status ---------
194 idout(csr_ibf_err) := r.err;
195 idout(csr_ibf_done) := r.done;
196 idout(csr_ibf_ie) := r.ie;
197 idout(csr_ibf_updn) := r.updn;
198 idout(csr_ibf_mode) := r.mode;
199 idout(csr_ibf_rate) := r.rate;
200 idout(csr_ibf_run) := r.run;
201 if ibrd='1' then
202 n.err := '0'; -- err is read and clear
203 n.done := '0'; -- done is read and clear
204 end if;
205
206 if IB_MREQ.racc = '0' then -- cpu ---------------------
207 if ibwr = '1' then
208 n.evtfix := IB_MREQ.din(csr_ibf_fix);
209 n.ie := IB_MREQ.din(csr_ibf_ie);
210 n.updn := IB_MREQ.din(csr_ibf_updn);
211 n.mode := IB_MREQ.din(csr_ibf_mode);
212 n.rate := IB_MREQ.din(csr_ibf_rate);
213 n.run := IB_MREQ.din(csr_ibf_run);
214 if IB_MREQ.din(csr_ibf_ie)='0' then
215 n.intreq := '0';
216 end if;
217 end if;
218
219 else -- rri ---------------------
220 idout(csr_ibf_ir) := r.intreq;
221 idout(csr_ibf_erate) := r.erate;
222 if ibwr = '1' then
223 n.erate := IB_MREQ.din(csr_ibf_erate);
224 end if;
225 end if;
226
227 when ibaddr_csb => -- CSB -- count set buffer -----------
228 idout := (others=>'0'); -- csb is not readable, return zero !
229 if IB_MREQ.racc = '0' then -- cpu ---------------------
230 if ibwr = '1' then
231 n.csb := IB_MREQ.din;
232 n.evtload := '1';
233 end if;
234 end if;
235
236 when ibaddr_ctr => -- CTR -- counter --------------------
237 idout := r.ctr;
238
239 when others => null;
240 end case;
241 end if;
242
243 -- other state changes
244 -- clock dividers
245 if CPUSUSP='0' then -- advance if not suspended
246 if CE_MSEC='1' then -- on msec
247 n.lcnt := slv(unsigned(r.lcnt) + 1);
248 if unsigned(r.lcnt) = ldivide-1 then
249 n.lcnt := (others=>'0');
250 n.evtline := '1';
251 end if;
252 end if;
253
254 if CE_USEC='1' then -- on usec
255 n.d1cnt := slv(unsigned(r.d1cnt) + 1);
256 if unsigned(r.d1cnt) = ddivide-1 then
257 n.d1cnt := (others=>'0');
258 n.evt100k := '1';
259 n.d2cnt := slv(unsigned(r.d2cnt) + 1);
260 if unsigned(r.d2cnt) = ddivide-1 then
261 n.d2cnt := (others=>'0');
262 n.evt10k := '1';
263 end if;
264 end if;
265 end if;
266 end if;
267
268 -- counter logic
269 -- select source
270 if r.run='1' then
271 case r.rate is
272 when rate_100k => ievt := r.evt100k;
273 when rate_10k => ievt := r.evt10k;
274 when rate_line => ievt := r.evtline;
275 when rate_ext => ievt := r.evtext;
276 when others => null;
277 end case;
278 else
279 ievt := r.evtfix;
280 end if;
281
282 -- load or action
283 if r.evtload='1' then -- load
284 n.ctr := r.csb;
285
286 else -- action
287 if ievt='1' then -- count event ?
288 if r.updn='0' then -- count-down
289 n.ctr := slv(unsigned(r.ctr) - 1);
290 else -- count-up
291 n.ctr := slv(unsigned(r.ctr) + 1);
292 end if;
293
294 if n.ctr=ctrzero then -- zero reached ?
295 n.done := '1'; -- set done
296 if r.done='1' then -- already done
297 n.err := '1'; -- set error
298 end if;
299
300 if r.ie = '1' then -- interrupt enabled ?
301 n.intreq := '1';
302 end if;
303
304 if r.mode='1' then -- mode: repeat
305 n.ctr := r.csb;
306 else -- mode: single shot
307 n.csb := ctrzero;
308 n.run := '0';
309 end if;
310
311 end if;
312
313 end if; -- if ievt='1'
314 end if; -- if r.evtload='1'
315
316 if EI_ACK = '1' then
317 n.intreq := '0';
318 end if;
319
320 N_REGS <= n;
321
322 IB_SRES.dout <= idout;
323 IB_SRES.ack <= r.ibsel and ibreq;
324 IB_SRES.busy <= '0';
325
326 EI_REQ <= r.intreq;
327
328 end process proc_next;
329
330end syn;
integer range 9 downto 8 csr_ibf_erate
Definition: ibd_kw11p.vhd:60
integer := 6 csr_ibf_ie
Definition: ibd_kw11p.vhd:62
integer := 15 csr_ibf_err
Definition: ibd_kw11p.vhd:58
natural := 5 lwidth
Definition: ibd_kw11p.vhd:81
slv2 := "10" erate_ext
Definition: ibd_kw11p.vhd:76
integer range 2 downto 1 csr_ibf_rate
Definition: ibd_kw11p.vhd:66
slv2 := "11" erate_noop
Definition: ibd_kw11p.vhd:77
integer := 5 csr_ibf_fix
Definition: ibd_kw11p.vhd:63
regs_type := regs_init N_REGS
Definition: ibd_kw11p.vhd:126
natural := 20 ldivide
Definition: ibd_kw11p.vhd:82
integer := 7 csr_ibf_done
Definition: ibd_kw11p.vhd:61
natural := 4 dwidth
Definition: ibd_kw11p.vhd:79
slv2 := "00" erate_sclk
Definition: ibd_kw11p.vhd:74
slv2 := "00" rate_100k
Definition: ibd_kw11p.vhd:69
integer := 10 csr_ibf_ir
Definition: ibd_kw11p.vhd:59
slv2 := "01" erate_usec
Definition: ibd_kw11p.vhd:75
slv2 := "01" rate_10k
Definition: ibd_kw11p.vhd:70
slv2 := "00" ibaddr_csr
Definition: ibd_kw11p.vhd:54
integer := 4 csr_ibf_updn
Definition: ibd_kw11p.vhd:64
regs_type := regs_init R_REGS
Definition: ibd_kw11p.vhd:125
slv2 := "10" ibaddr_ctr
Definition: ibd_kw11p.vhd:56
slv2 := "10" rate_line
Definition: ibd_kw11p.vhd:71
slv2 := "01" ibaddr_csb
Definition: ibd_kw11p.vhd:55
slv16 := slv( to_unsigned( 8#172540#, 16) ) ibaddr_kw11p
Definition: ibd_kw11p.vhd:52
slv2 := "11" rate_ext
Definition: ibd_kw11p.vhd:72
slv16 :=( others => '0') ctrzero
Definition: ibd_kw11p.vhd:84
natural := 10 ddivide
Definition: ibd_kw11p.vhd:80
integer := 3 csr_ibf_mode
Definition: ibd_kw11p.vhd:65
integer := 0 csr_ibf_run
Definition: ibd_kw11p.vhd:67
regs_type :=( '0', "00", '0', '0', '0', '0', '0', "00", '0',( others => '0'),( others => '0'), '0',( others => '0'),( others => '0'),( others => '0'), '0', '0', '0', '0', '0', '0') regs_init
Definition: ibd_kw11p.vhd:110
out EI_REQ slbit
Definition: ibd_kw11p.vhd:45
in RESET slbit
Definition: ibd_kw11p.vhd:39
in CE_USEC slbit
Definition: ibd_kw11p.vhd:37
in EXTEVT slbit
Definition: ibd_kw11p.vhd:41
in BRESET slbit
Definition: ibd_kw11p.vhd:40
in CLK slbit
Definition: ibd_kw11p.vhd:36
in IB_MREQ ib_mreq_type
Definition: ibd_kw11p.vhd:43
in CPUSUSP slbit
Definition: ibd_kw11p.vhd:42
out IB_SRES ib_sres_type
Definition: ibd_kw11p.vhd:44
in EI_ACK slbit
Definition: ibd_kw11p.vhd:47
in CE_MSEC slbit
Definition: ibd_kw11p.vhd:38
Definition: iblib.vhd:33
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 1 downto 0) slv2
Definition: slvtypes.vhd:34
std_logic_vector slv
Definition: slvtypes.vhd:31