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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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