shaiko
Advanced Member level 5
- Joined
- Aug 20, 2011
- Messages
- 2,644
- Helped
- 303
- Reputation
- 608
- Reaction score
- 297
- Trophy points
- 1,363
- Activity points
- 18,302
The warning points to the following line in which I use a string generic inside a generate statement:Comparison (=) of different length arrays is always false!
synchronous_or_asynchronous : if STRING_CONFIGURATION_1 = "asynchronous" generate
...
Yes,I guess you get the warning when STRING_CONFIGURATION_1 is set to "synchronous"?
STRING_CONFIGURATION_1 : string := "asynchronous" ;
if STRING_CONFIGURATION_1 = "asynchronous" generate
...
end generate ;
if STRING_CONFIGURATION_1 = "synchronous" generate
...
end generate ;
It will probably work as you want, but you should only get the warning when the generic is different from the compare string.So,
the logic will be generated when "STRING_CONFIGURATION_1" is either "asynchronous" or "synchronous" - regardless of the character length mismatch between the words?
synchronous_or_asynchronous : if STRING_CONFIGURATION_1(1 to 4) = "asyn" generate
If that is the case I'd use the provided strings as well. No need to duplicate things with all the drawbacks this duplication would entail. I think I would however try to make the string comparisons (configuration token comparisons) as robust as possible. So either use a vhdl language construct that does this out of the box, or use a small function that does this for you.Presumed the vendor IP already uses string generics for many configuration parameters and you want to set these parameters pepending on entity generics. Why shouldn't you use the same parameters for other related configuration purposes in your design instead of creating numerical alias parameters?
As you already suggested, if the provided IP is already using strings then it's probably better (read: less painful maintenance) to use those strings as well.Of course you can go the opposite way, define an enumeration type, define a string array type of this enumeration, define constant strings to supply the vendor IP generics. Quite elegant but also rather verbose.
Mmmh, re-reading that bit. If the alternative was painful enough (prone to mistakes, annoying maintenance) I think it just might be worth it too.Of course you can go the opposite way, define an enumeration type, define a string array type of this enumeration, define constant strings to supply the vendor IP generics. Quite elegant but also rather verbose.
SYNCHRONOUS : boolean := true;
if SYNCHRONOUS = false generate
... asynchronous version of code
end generate;
if SYNCHRONOUS = true generate
... synchronous version of code
end generate;
Question: why use a string as a configuration item? Or more generally put: why use a specific type of your choice in a language as a configuration item (where you have to do comparisons) when this specific type of your choice has poor comparison operators?
I mean: strings can be done in your favorite HDL, but as you noticed the string compare operation can be done but is not super user friendly for this sort of thing.
Why not use an enumeration, or parameter or whatever you VHDL people use? And if you absolutely must strings, then maybe use a function that abstracts away the dirty business.
So sortof what std_match wrote, only this compare_config_string(str1, str2) function does something like:
- compare lengths of str1 and str2. Different length? ==> not the same string
- if same length, then compare the two strings like you used to, and return result
Or maybe you could hash the string and compare hashes.
Anyways, doesn't VHDL have a clean way of doing this?
In verilog I'd probably just use parameters as enumerations with meaningful names. But maybe VHDL has a nice way of doing this with strings? If not, maybe go with enumerated items of a type with known-to-work easy comparison operators?
clkrega => "clock0"/"clock1"/"none"
ramstyle => "m4k"/"m9k"/"mram"/"m144k"
--etc etc
its quite a neat way to wrap up human redible configuration when there are more than 2 options (true/false) and you dont need to define an enumerated type in a package. In adition, Quartus and Modelsim can then override them easily from the command line or setup. Enumerated types cant be set like this:
vsim my_design -GMY_GENERIC="This is a generic forced from the VSIM options"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?