Case choice must be a locally static expression

P

Peter

Hi,

I have searched the net for the above mentioned warning from Modelsim,
but I cant really understand whats the problem.

I have declared some constants in a package:

Constant MASKREG : unsigned(5 downto 0):= To_unsigned(0,6);
Constant CONTREG : unsigned(5 downto 0):= To_unsigned(1,6);
......

They are used in a procedure in another entity:

Procedure write_register is
Begin
case adr is
when MASKREG => mask := shreg(mask'range);
when CONTREG => cont := shreg(cont'range);
when DEADTIMEREG => deadtime := shreg(deadtime'range);
when FILTLOREG => filtlo := shreg(filtlo'range);
when FILTHIREG => filthi := shreg(filthi'range);
when MISCREG => misc := shreg(misc'range);
when others => null;
end case;
End procedure write_register;

Why is the case choice not considered locally static by Modelsim?

Thanks in advance.

/Peter
 
P

Peter

However, replacing then constant declaration with the code below,
makes the warning disappear:

Constant MASKREG : unsigned(5 downto 0):= "000000";
Constant CONTREG : unsigned(5 downto 0):= "000001";

So the problem seems to be the To_unsigned function?

/Peter
 
T

Tricky

Hi,

I have searched the net for the above mentioned warning from Modelsim,
but I cant really understand whats the problem.

I have declared some constants in a package:

Constant MASKREG        : unsigned(5 downto 0):= To_unsigned(0,6);
Constant CONTREG        : unsigned(5 downto 0):= To_unsigned(1,6);
.....

They are used in a procedure in another entity:

Procedure write_register is
Begin
   case adr is
     when MASKREG        =>  mask      := shreg(mask'range);
     when CONTREG         =>  cont        := shreg(cont'range);
     when DEADTIMEREG =>  deadtime := shreg(deadtime'range);
     when FILTLOREG       =>  filtlo         := shreg(filtlo'range);
     when FILTHIREG        =>  filthi         := shreg(filthi'range);
     when MISCREG         =>  misc        := shreg(misc'range);
     when others               =>  null;
   end case;
End procedure write_register;

Why is the case choice not considered locally static by Modelsim?

Thanks in advance.

/Peter

Ive seen exactly the same warning with std_logic_vector constants
declared in a package (and declared explicitly without a conversion
function). I can only guess that its scared you could go and change
the constant. But I dont get it.
 
H

HT-Lab

"Peter" wrote in message

Hi,

I have searched the net for the above mentioned warning from Modelsim,
but I cant really understand whats the problem.

I have declared some constants in a package:

Constant MASKREG : unsigned(5 downto 0):= To_unsigned(0,6);
Constant CONTREG : unsigned(5 downto 0):= To_unsigned(1,6);
.....

They are used in a procedure in another entity:

Procedure write_register is
Begin
case adr is
when MASKREG => mask := shreg(mask'range);
when CONTREG => cont := shreg(cont'range);
when DEADTIMEREG => deadtime := shreg(deadtime'range);
when FILTLOREG => filtlo := shreg(filtlo'range);
when FILTHIREG => filthi := shreg(filthi'range);
when MISCREG => misc := shreg(misc'range);
when others => null;
end case;
End procedure write_register;

Why is the case choice not considered locally static by Modelsim?

Thanks in advance.

What happens if you compile under VHDL2008? (you need Modelsim 10.0)

Hans
www.ht-lab.com

/Peter
 
T

Thomas Stanka

Ive seen exactly the same warning with std_logic_vector constants
declared in a package (and declared explicitly without a conversion
function). I can only guess that its scared you could go and change
the constant. But I dont get it.

You actually could change the constant. It is possible to change
package body.
The same constants declared in the architecture which contains the
case will avoid this error message.

Before vhdl2008 this is one of the most crucial limitations for
readablity in my opinion, that you are not allowed to use constants
from packages as case-choice. Luckyly Modelsim does just warn, but
uses the Constant.

bye Thomas
 
H

HT-Lab

"Thomas Stanka" wrote in message
You actually could change the constant. It is possible to change
package body.
The same constants declared in the architecture which contains the
case will avoid this error message.

Before vhdl2008 this is one of the most crucial limitations for
readablity in my opinion, that you are not allowed to use constants
from packages as case-choice. Luckyly Modelsim does just warn, but
uses the Constant.

With VHDL2008 you also no longer get the warning, I just created a quick
test case based on Peter's code and with Modelsim I get:

D:\Modelsim>vcom -2002 locally_static.vhd
Model Technology ModelSim DE vcom 10.0 Compiler 2010.12 Dec 4 2010
-- Compiling entity x
-- Compiling architecture rtl of x
** Warning: locally_static.vhd(18): Choice in CASE statement alternative
must be locally static.

D:\Modelsim>vcom -2008 locally_static.vhd
Model Technology ModelSim DE vcom 10.0 Compiler 2010.12 Dec 4 2010
-- Compiling entity x
-- Compiling architecture rtl of x

Simple testcase shown below,

Hans
www.ht-lab.com


library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity x is
end x;

architecture rtl of x is

constant maskreg : unsigned(5 downto 0):= to_unsigned(0,6);
signal shreg : unsigned(5 downto 0);

procedure write_register(adr:in unsigned(5 downto 0)) is
variable mask:unsigned(5 downto 0);
begin
case adr is
when maskreg => mask := shreg(mask'range); -- Line18
when others => null;
end case;
end procedure write_register;

begin
end rtl;
 
P

Peter

Before vhdl2008 this is one of the most crucial limitations for
readablity in my opinion, that you are not allowed to use constants
from packages as case-choice. Luckyly Modelsim does just warn, but
uses the Constant.

bye Thomas

But it seems as constants in a package are allowed in a case-choice,
as long as I dont use the "to_unsigned" function?

Constant MASKREG : unsigned(5 downto 0):= "000000"; --
Gives no warning
Constant MASKREG : unsigned(5 downto 0):= To_unsigned(0,6); --
Does

The package is compiled first. Why is the compiler unable to know the
value of the constant just because it was set by a function?

And I tried to move the declaration into the architecture where it is
used. It gives the same warning.

Thanks gentlemen for Your interest,

Peter
 
T

Thomas Rouam

But it seems as constants in a package are allowed in a case-choice,
as long as I dont use the "to_unsigned" function?

Constant MASKREG        : unsigned(5 downto 0):= "000000";         --
Gives no warning
Constant MASKREG        : unsigned(5 downto 0):= To_unsigned(0,6); --
Does

The package is compiled first. Why is the compiler unable to know the
value of the constant just because it was set by a function?

And I tried to move the declaration into the architecture where it is
used. It gives the same warning.

Thanks gentlemen for Your interest,

Peter

Hi Peter,

The simple use of a function defined in a package makes your constant
non locally static. On the other hand, it is globally static because
it can resolve the constant value without having to "run" the design.
Unfortunately for you, the case wants to be able to know the value
within the entity it is used which is not the case.

Regards,

Thomas
 
J

JimLewis

Hi Peter,
This was addressed in the VHDL-2008 revision. There were a
couple of changes to the language that now allow this to be
locally static.

Turn on the 2008 switch in modelsim. Double check that it works
in your synthesis tool (or tools if you are making an FPGA then
an ASIC) and you should be ok.

Best,
Jim
 
P

Peter

Hi Peter,
This was addressed in the VHDL-2008 revision.  There were a
couple of changes to the language that now allow this to be
locally static.

Turn on the 2008 switch in modelsim.  Double check that it works
in your synthesis tool (or tools if you are making an FPGA then
an ASIC) and you should be ok.

Best,
Jim


Thanks!

Regards,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top