w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
rbd_timer.vhd
Go to the documentation of this file.
1-- $Id: rbd_timer.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2010-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: rbd_timer - syn
7-- Description: rbus dev: usec precision timer
8--
9-- Dependencies: -
10--
11-- Test bench: -
12--
13-- Target Devices: generic
14-- Tool versions: xst 12.1-14.7; viv 2014.4-2015.4; ghdl 0.29-0.33
15--
16-- Synthesized (xst):
17-- Date Rev ise Target flop lutl lutm slic t peri
18-- 2010-12-29 351 12.1 M53d xc3s1000-4 19 63 - 34 s 7.6
19--
20-- Revision History:
21-- Date Rev Version Comment
22-- 2014-08-15 583 4.0 rb_mreq addr now 16 bit
23-- 2011-11-19 427 1.0.1 now numeric_std clean
24-- 2010-12-29 351 1.0 Initial version
25------------------------------------------------------------------------------
26--
27-- rbus registers:
28--
29-- Addr Bits Name r/w/f Function
30-- 0 time r/w/- Timer register
31-- w: if > 0 timer is running
32--
33
34library ieee;
35use ieee.std_logic_1164.all;
36use ieee.numeric_std.all;
37
38use work.slvtypes.all;
39use work.rblib.all;
40
41entity rbd_timer is -- rbus dev: usec precision timer
42 generic (
43 RB_ADDR : slv16 := (others=>'0'));
44 port (
45 CLK : in slbit; -- clock
46 CE_USEC : in slbit; -- usec pulse
47 RESET : in slbit; -- reset
48 RB_MREQ : in rb_mreq_type; -- rbus: request
49 RB_SRES : out rb_sres_type; -- rbus: response
50 DONE : out slbit; -- 1 cycle pulse when expired
51 BUSY : out slbit -- timer running
52 );
53end entity rbd_timer;
54
55
56architecture syn of rbd_timer is
57
58 type regs_type is record -- state registers
59 rbsel : slbit; -- rbus select
60 timer : slv16; -- timer value
61 timer_act : slbit; -- timer active flag
62 timer_end : slbit; -- timer done flag
63 end record regs_type;
64
65 constant regs_init : regs_type := (
66 '0', -- rbsel
67 (others=>'0'), -- timer
68 '0','0' -- timer_act,timer_end
69 );
70
73
74begin
75
76 proc_regs: process (CLK)
77 begin
78 if rising_edge(CLK) then
79 if RESET = '1' then
81 else
82 R_REGS <= N_REGS;
83 end if;
84 end if;
85 end process proc_regs;
86
87 proc_next : process (R_REGS, CE_USEC, RB_MREQ)
88 variable r : regs_type := regs_init;
89 variable n : regs_type := regs_init;
90 variable irb_ack : slbit := '0';
91 variable irb_dout : slv16 := (others=>'0');
92 begin
93
94 r := R_REGS;
95 n := R_REGS;
96
97 irb_ack := '0';
98 irb_dout := (others=>'0');
99
100 -- rbus address decoder
101 n.rbsel := '0';
102 if RB_MREQ.aval='1' and RB_MREQ.addr=RB_ADDR then
103 n.rbsel := '1';
104 end if;
105
106 -- rbus transactions
107 if r.rbsel = '1' then
108 irb_ack := RB_MREQ.re or RB_MREQ.we;
109
110 if RB_MREQ.we = '1' then
111 n.timer := RB_MREQ.din;
112 n.timer_act := '1';
113 end if;
114 if RB_MREQ.re = '1' then
115 irb_dout := r.timer;
116 end if;
117 end if;
118
119 -- timer logic
120 -- count down when active and 'on-the-usec'
121 n.timer_end := '0'; -- ensure end is 1 cycle pulse
122 if CE_USEC = '1' then -- if at usec
123 if r.timer_act = '1' then -- if timer active
124 if unsigned(r.timer) = 0 then -- if timer at end
125 n.timer_act := '0'; -- mark unactive
126 n.timer_end := '1'; -- send end marker
127 else -- else: timer not at end
128 n.timer := slv(unsigned(r.timer) - 1); -- decrement
129 end if;
130 end if;
131 end if;
132
133 N_REGS <= n;
134
135 RB_SRES.dout <= irb_dout;
136 RB_SRES.ack <= irb_ack;
137 RB_SRES.err <= '0';
138 RB_SRES.busy <= '0';
139
140 DONE <= r.timer_end;
141 BUSY <= r.timer_act;
142
143 end process proc_next;
144
145end syn;
regs_type := regs_init N_REGS
Definition: rbd_timer.vhd:72
regs_type := regs_init R_REGS
Definition: rbd_timer.vhd:71
regs_type :=( '0',( others => '0'), '0', '0') regs_init
Definition: rbd_timer.vhd:65
in RESET slbit
Definition: rbd_timer.vhd:47
in CE_USEC slbit
Definition: rbd_timer.vhd:46
out BUSY slbit
Definition: rbd_timer.vhd:52
out DONE slbit
Definition: rbd_timer.vhd:50
in CLK slbit
Definition: rbd_timer.vhd:45
in RB_MREQ rb_mreq_type
Definition: rbd_timer.vhd:48
RB_ADDR slv16 :=( others => '0')
Definition: rbd_timer.vhd:43
out RB_SRES rb_sres_type
Definition: rbd_timer.vhd:49
Definition: rblib.vhd:32
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector slv
Definition: slvtypes.vhd:31