SURF  1.0
Arbiter.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Arbiter.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-04-30
5 -- Last update: 2013-09-25
6 -------------------------------------------------------------------------------
7 -- Description: Example Arbiter Module
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.StdRtlPkg.all;
24 use work.ArbiterPkg.all;
25 
26 --! @see entity
27  --! @ingroup base_general
28 entity Arbiter is
29  generic (
30  TPD_G : time := 1 ns;
31  RST_POLARITY_G : sl := '1'; -- '1' for active high rst, '0' for active low
32  RST_ASYNC_G : boolean := false; -- Reset is asynchronous
33  REQ_SIZE_G : positive := 16);
34  port (
35  clk : in sl;
36  rst : in sl := not RST_POLARITY_G; -- Optional reset
37 
38  req : in slv(REQ_SIZE_G-1 downto 0);
39  selected : out slv(bitSize(REQ_SIZE_G-1)-1 downto 0);
40  valid : out sl;
41  ack : out slv(REQ_SIZE_G-1 downto 0));
42 end entity Arbiter;
43 
44 architecture rtl of Arbiter is
45 
46  constant SELECTED_SIZE_C : integer := bitSize(REQ_SIZE_G-1);
47 
48  type RegType is record
49  lastSelected : slv(SELECTED_SIZE_C-1 downto 0);
50  valid : sl;
51  ack : slv(REQ_SIZE_G-1 downto 0);
52  end record RegType;
53 
54  constant REG_RESET_C : RegType :=
55  (lastSelected => (others => '0'), valid => '0', ack => (others => '0'));
56 
57  signal r : RegType := REG_RESET_C;
58  signal rin : RegType;
59 
60 begin
61 
62  comb : process (r, req, rst) is
63  variable v : RegType;
64  begin
65  v := r;
66 
67  if (req(conv_integer(r.lastSelected)) = '0' or r.valid = '0') then
68  arbitrate(req, r.lastSelected, v.lastSelected, v.valid, v.ack);
69  end if;
70 
71  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
72  v := REG_RESET_C;
73  end if;
74 
75  rin <= v;
76  ack <= r.ack;
77  valid <= r.valid;
78  selected <= slv(r.lastSelected);
79 
80  end process comb;
81 
82  seq : process (clk, rst) is
83  begin
84  if (rising_edge(clk)) then
85  r <= rin after TPD_G;
86  end if;
87  if (RST_ASYNC_G and rst = RST_POLARITY_G) then
88  r <= REG_RESET_C after TPD_G;
89  end if;
90  end process seq;
91 
92 end architecture rtl;
in rstsl :=not RST_POLARITY_G
Definition: Arbiter.vhd:36
RST_POLARITY_Gsl := '1'
Definition: Arbiter.vhd:31
std_logic sl
Definition: StdRtlPkg.vhd:28
TPD_Gtime := 1 ns
Definition: Arbiter.vhd:30
REQ_SIZE_Gpositive := 16
Definition: Arbiter.vhd:33
out selectedslv( bitSize( REQ_SIZE_G- 1)- 1 downto 0)
Definition: Arbiter.vhd:39
_library_ ieeeieee
out ackslv( REQ_SIZE_G- 1 downto 0)
Definition: Arbiter.vhd:41
in clksl
Definition: Arbiter.vhd:35
RST_ASYNC_Gboolean := false
Definition: Arbiter.vhd:32
out validsl
Definition: Arbiter.vhd:40
in reqslv( REQ_SIZE_G- 1 downto 0)
Definition: Arbiter.vhd:38
std_logic_vector slv
Definition: StdRtlPkg.vhd:29