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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [rtl/] [vlib/] [rbus/] [rbd_timer.vhd] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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