有没有办法在使用std_logic_vectors时缩短其他时间



我正在编写一个模块,想知道是否有办法缩短我在使用 when-else 时必须编写的所有行,而获取值的对象是std_logic_vector。我在代码中创建了 2 种类型,一种用于输出状态,另一种是前者的数组(我有 6 个模块,总共有 18 种不同的输出配置(

type    output_state is
(
red_indicator,
green_indicator,
open_drain_indicator,
reset_indicator,
);
type    output_status_array is array (5 downto 0) of output_state;

现在在下一个代码括号中,我插入了值以通过某种逻辑output_status_array

output_status_array(0) <= red_indicator when (sampled_data(0) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(0) < MIN_POWER_LEVEL) else green_indicator; -- todo : need to implement convert to integer before <>
output_status_array(1) <= red_indicator when (sampled_data(1) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(1) < MIN_POWER_LEVEL) else green_indicator;
output_status_array(2) <= red_indicator when (sampled_data(2) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(2) < MIN_POWER_LEVEL) else green_indicator;
output_status_array(3) <= red_indicator when (sampled_data(3) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(3) < MIN_POWER_LEVEL) else green_indicator;
output_status_array(4) <= red_indicator when (sampled_data(4) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(4) < MIN_POWER_LEVEL) else green_indicator;
output_status_array(5) <= red_indicator when (sampled_data(5) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(5) < MIN_POWER_LEVEL) else green_indicator;

每个给定模块我有 3 个输出,我可以编写一个非常冗长而乏味的代码,指示输出需要哪些值,但我想知道合成器在编译代码后是否执行一些"按位"操作。

red_led_out             <=  '1' when output_status_array = red_indicator else '0';
green_led_out           <=  '1' when output_status_array = green_indicator else '0';
open_drain_out          <=  '1' when output_status_array = open_drain_indicator else '0'; 

red_led_out,green_led_outopen_drain_out都是std_logic_vectors,我想知道例如,是否唯一会在red_led_out中获得"1"的位将是设置为red_indicator的status_array中的相应位?很抱歉解释冗长,但我想非常清楚地说明我写的内容。

如果没有完整的代码清单,很难确切地知道你在做什么。也许您可以考虑使用生成循环:

status_gen : for i in 0 to 5 generate
output_status_array(i) <= red_indicator when (sampled_data(i) > MAX_POWER_LEVEL) else open_drain_indicator when (sampled_data(i) < MIN_POWER_LEVEL) else green_indicator;
end generate;

最新更新