Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Is my code good?

Reply
Thread Tools

Is my code good?

 
 
bxbxb3
Guest
Posts: n/a
 
      02-25-2005
Hi,
I have a doubt whether the following coding style is a good one or not.

process(clock)
begin
if(clock'event and clock='1') then
case state is
when START_RD=>

when NEXT1=>

when FINAL=>
o_Frame_SaComapact1_Rt <= i_myMacAddress;
end case;
end if;
end process;


Two of the case statements have nothing to do in that state. Will this
infer a latch? Is it better to use a "if" statement instead?
Thanks in advance.

 
Reply With Quote
 
 
 
 
Paul Uiterlinden
Guest
Posts: n/a
 
      02-25-2005
bxbxb3 wrote:
> Hi,
> I have a doubt whether the following coding style is a good one or not.
>
> process(clock)
> begin
> if(clock'event and clock='1') then
> case state is
> when START_RD=>
>
> when NEXT1=>
>
> when FINAL=>
> o_Frame_SaComapact1_Rt <= i_myMacAddress;
> end case;
> end if;
> end process;
>
>
> Two of the case statements have nothing to do in that state. Will this
> infer a latch?


No, it will infer a flip-flop because that's what you describe in your
process ("if(clock'event and clock='1')").

> Is it better to use a "if" statement instead?


Depends whether this is the only decoding you do with 'state'. In
general, I do like to use case statements with enumeration types.

If the code is not going to be synthesized, I _never_ use a "when
others" choice. Reason: if you later expand (add members) to you
enumeration type and you forget to modify your case statement, the code
will fail already at compilation time, because case choices must be
complete.

For synthesis this is different: the state variable/signal will be
mapped to a vector, giving 2**n possible states. So here you _must_ use
a "when others" choice, to prevent hang-up situations if the state
vector ever gets one of those unused states.

Paul.
 
Reply With Quote
 
 
 
 
Peter Hermansson
Guest
Posts: n/a
 
      02-25-2005
> For synthesis this is different: the state variable/signal will be
> mapped to a vector, giving 2**n possible states. So here you _must_ use
> a "when others" choice, to prevent hang-up situations if the state
> vector ever gets one of those unused states.
>
> Paul.


Hi,

I am not convinced that synthesis programs generate fail-safe FSMs
only because of the "when others" clause. Please refer to the
application note "Designing Safe VHDL State Machines with Synplify".

/Peter
 
Reply With Quote
 
Eric Smith
Guest
Posts: n/a
 
      02-27-2005
Paul Uiterlinden <> writes:
> For synthesis this is different: the state variable/signal will be
> mapped to a vector, giving 2**n possible states. So here you _must_
> use a "when others" choice, to prevent hang-up situations if the state
> vector ever gets one of those unused states.


Note that VHDL semantics only define "when others" to affect the other
legal values of the type. For instance, if you have an enumeration with
three values, FOO, BAR, and BAZ, which will synthesize to a two bit
vector, a "when others" clause does not cover the fourth possible state
of the vector.

A synthesis tool may choose to expand the meaning to encompass the
illegal values, but the VHDL LRM does not guarantee this, so you have to
determine it for the specific synthesis tool.

Eric
 
Reply With Quote
 
Thomas Stanka
Guest
Posts: n/a
 
      02-28-2005
Eric Smith wrote:

> Paul Uiterlinden <> writes:
>> For synthesis this is different: the state variable/signal will be
>> mapped to a vector, giving 2**n possible states. So here you _must_
>> use a "when others" choice, to prevent hang-up situations if the state
>> vector ever gets one of those unused states.

>
> Note that VHDL semantics only define "when others" to affect the other
> legal values of the type. For instance, if you have an enumeration with
> three values, FOO, BAR, and BAZ, which will synthesize to a two bit
> vector, a "when others" clause does not cover the fourth possible state
> of the vector.


You should allways expand your enumerations to 2**n states (foo, bar, baz,
unused) to avoid this problem.
BTW when using synplify, you should replace each enumeration type with
constant declarations, if you like to have a determistic result, that
didn't mess up you equivalence check.

bye Thomas

--
Emailantworten bitte an thomas[at]obige_domain.
Usenet_10 ist für Viren und Spam reserviert
 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      02-28-2005
Peter Hermansson wrote:
>
> I am not convinced that synthesis programs generate fail-safe FSMs
> only because of the "when others" clause. Please refer to the
> application note "Designing Safe VHDL State Machines with Synplify".


Thanks for the pointer. Interesting stuff.

When I wrote my message, I had Synopsys design_compiler in mind. There
the "when others" does work.

Paul.
 
Reply With Quote
 
Eric Smith
Guest
Posts: n/a
 
      02-28-2005
I wrote:
> Note that VHDL semantics only define "when others" to affect the other
> legal values of the type. For instance, if you have an enumeration with
> three values, FOO, BAR, and BAZ, which will synthesize to a two bit
> vector, a "when others" clause does not cover the fourth possible state
> of the vector.


Thomas Stanka <> writes:
> You should allways expand your enumerations to 2**n states (foo, bar, baz,
> unused) to avoid this problem.


Agreed, this is the best approach to avoid dependence on characteristics
of a specific synthesizer. Then the "when others" clause can be used
with predictable results.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
Fire Code behind code AND Javascript code associated to a Button Click Event =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 4 02-11-2004 07:31 AM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM
Re: C# Equivalent of VB.Net Code -- One line of code, simple Ian ASP .Net 0 06-25-2003 01:14 PM
Re: C# Equivalent of VB.Net Code -- One line of code, simple Ron ASP .Net 1 06-24-2003 07:18 PM



Advertisments