1 ------------------------------------------------------------------------------- 2 -- File : ArbiterPkg.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2013-05-01 5 -- Last update: 2017-02-23 6 ------------------------------------------------------------------------------- 7 -- Description: Arbiter Package File 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 ------------------------------------------------------------------------------- 19 use ieee.std_logic_1164.
all;
22 --use work.TextUtilPkg.all; 26 --! @ingroup base_general 32 lastSelected :
in slv;
33 nextSelected :
inout slv;
37 end package ArbiterPkg;
41 -- Priority encoder with index p having top priority 42 -- followed by p-1, p-2, etc., rolling over to the highest index when 0 reached 43 -- Returns highest priority index with value '1', encoded as unsigned slv. 46 variable rotatedV :
(v'
range);
47 variable ret :
(bitSize
(v'
length-
1)-
1 downto 0) :=
(others => '
0'
);
48 variable bestReqU :
(ret'
length downto 0);
50 -- print("priorityEncode(" & str(v) & ", " & str(p) & ")"); 51 -- Rotate input by n to give n top priority 52 rotatedV := rotate_right
((v
), p
);
54 -- Find lowest index with value of '1' 57 if (rotatedV
(i
) = '
1'
) then 62 -- Convert integer to unsigned 63 bestReqU := to_unsigned
(bestReq, bestReqU'
length);
65 -- Add p to rotated select and mod by length to undo the rotation 66 ret := resize
((bestReqU+p
) mod v'
length, ret'
length);
69 end function priorityEncode;
74 lastSelected :
in slv;
75 nextSelected :
inout slv;
79 -- print("arbitrate(" & str(req'length));-- & ", " & str(lastSelected'length) & ", " str(nextSelected'length) & ", " & ")"); 82 nextSelected := priorityEncode
(req, to_integer
((lastSelected
)+
1) mod req'
length);
83 ack := decode
(slv(nextSelected
))(req'
range);
85 nextSelected := lastSelected;
86 ack
(ack'
range) :=
(others => '
0'
);
88 end procedure arbitrate;
90 end package body ArbiterPkg;
arbitratereq,lastSelected,nextSelected,valid,ack,