Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Allowed values for generic parameters

Status
Not open for further replies.

ireon

Junior Member level 2
Joined
Mar 28, 2013
Messages
21
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,455
Hello I wrote a VHDL code where my entity accepts generic parameters. I added some limitations using RANGE function. Now I should add a limitation on data width, but only some value are allowed, in particular the data width parameter can only be 8, 16, 32, 64. Is there a function to do this?
 

you can use assertions in the code to catch illegal generics. I think all synth tools now stop synthesis on failed inline (outside a process) assertions:


Code VHDL - [expand]
1
2
3
assert data'length = 8 or data'length = 64
  report "Data width must be 8 or 64"
    severity failure;



If you need data width it to be a any of 2 (and can use VHDL 2008):


Code VHDL - [expand]
1
2
3
assert xor to_unsigned(data'length, 32) = '1' 
  report "Data Width must be 2^N"
    severity failure;

 

Power of two is also "(((not x) + 1) and (x) = x) and (x > 0)". doesn't "xor to_unsigned(7, 32)" return '1'?

You can also have a package with a selector function to map an enumerated type to an integer in a custom manner.
 

doesn't "xor to_unsigned(7, 32)" return '1'?

Yes it does - my mistake.
Might be easier just to have a count_bits function instead:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
function count_bits( u : unsigned; s : std_logic := '1') return integer is
  variable n : natural;
begin
  for i in u'range loop
    if u(i) = s then n := n + 1; 
    end if;
  end loop;
  return n;
end function;
 
assert count_bits( to_unsigned(data'length, 32) ) = 1
  report "Data Width must be 2^N"
    severity failure;

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top