【发布时间】:2016-02-16 03:04:42
【问题描述】:
处理复杂的范围选择逻辑。
选择信号的组合太多,选择和连接的范围太多。
我正在寻找一种更好的方法来使其具有可读性,并使用从预定义的常量和动态输入生成的有意义的变量。
一个简化的例子如下,不确定是否可以合成。
library ieee;
use ieee.std_logic_1164.all;
entity fum is
end entity;
architecture foo of fum is
signal sel: std_logic_vector (1 downto 0);
signal selected_range: std_logic_vector (5 downto 0);
signal counter: std_logic_vector (7 downto 0);
constant BASE_ADDR_LOW: integer := 2;
constant RANGE1_BITS : integer := 2;
-- this is simplified
-- dozens of constants involved, and their values can be configured before compiling.
begin
some_process:
process (sel, counter)
variable range0_high : integer := BASE_ADDR_LOW;
variable range1_low : integer := 0;
variable range1_high : integer := 0;
begin
if (sel = "00") then
-- this is simpilfied as well
-- dozens of inputs as sel involved, for 50+ combinations via nested if and case
range0_high := BASE_ADDR_LOW+1; -- 3
range1_low := range0_high+2; -- 5
range1_high := range1_low+RANGE1_BITS-1; -- 6
-- the following elsif will not work as the range1 has 0 bit.
-- not sure if there is a better way to do this
-- elsif (sel = "01" ) then
-- range0_high := BASE_ADDR_LOW+1; -- 5
-- range1_low := range0_high+2; -- N/A
-- range1_high := range1_low+RANGE1_BITS; --N/A
else
range0_high := BASE_ADDR_LOW; -- 2
range1_low := range0_high+2; -- 4
range1_high := range1_low+RANGE1_BITS; --6
end if;
-- using variables in range
selected_ranges <= counter(range1_high downto range1_low) & counter(range0_high downto 0);
end process;
end architecture;
如果某些字段可能是 0 位,有没有办法制作可合成的代码?
-- e.g. range0_high = 5, range1_* not in use
-- selected_ranges <= *nothing &* counter(5 downto 0);
【问题讨论】:
-
挥手没有用。
-
如果您正在处理未知的大量条件,您可以编写一个程序来表达组合并以表格形式查看它们,显示哪个贡献的输入和索引进入哪个输出。它将告诉您如何记录它以及如何实现它以匹配。综合实际上一次只关心一个输出位。
标签: vhdl