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=8or data'length=64report"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
assertxor to_unsigned(data'length, 32)= '1'
report"Data Width must be 2^N"severity failure;
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')returnintegerisvariable n :natural;beginfor i in u'rangeloopif u(i)= s then n := n +1;endif;endloop;return n;endfunction;assert count_bits( to_unsigned(data'length, 32))=1report"Data Width must be 2^N"severity failure;