Add Tercel PHY reset synchronization
[microwatt.git] / crhelpers.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3
4 library work;
5 use work.common.all;
6
7 package crhelpers is
8 subtype crnum_t is integer range 0 to 7;
9 subtype crmask_t is std_ulogic_vector(7 downto 0);
10
11 function fxm_to_num(fxm: crmask_t) return crnum_t;
12 function num_to_fxm(num: crnum_t) return crmask_t;
13 end package crhelpers;
14
15 package body crhelpers is
16
17 function fxm_to_num(fxm: crmask_t) return crnum_t is
18 begin
19 -- If multiple fields are set (undefined), match existing
20 -- hardware by returning the first one.
21 for i in 0 to 7 loop
22 -- Big endian bit numbering
23 if fxm(7-i) = '1' then
24 return i;
25 end if;
26 end loop;
27
28 -- If no fields are set (undefined), also match existing
29 -- hardware by returning cr7.
30 return 7;
31 end;
32
33 function num_to_fxm(num: crnum_t) return crmask_t is
34 begin
35 case num is
36 when 0 =>
37 return "10000000";
38 when 1 =>
39 return "01000000";
40 when 2 =>
41 return "00100000";
42 when 3 =>
43 return "00010000";
44 when 4 =>
45 return "00001000";
46 when 5 =>
47 return "00000100";
48 when 6 =>
49 return "00000010";
50 when 7 =>
51 return "00000001";
52 when others =>
53 return "00000000";
54 end case;
55 end;
56
57 end package body crhelpers;