需要解决VHDL常数中的“三元运算符”

时间:2019-04-26 19:24:05

标签: vhdl verilog

我有一些Verilog代码,如下所示:

@app.route('/uploads/<filename>')
def uploaded_file(filename):
    path = UPLOAD_FOLDER + "/" + filename
    #once you upload the file you get cleaned up visualisations
    file_one = open(path)
    file_two = open(path,'w')
    #cleaning up csv
    for row in file_one:
        row = row.strip()
        row = row[1:-1]
        row = row.replace('""','"')
        file_two.write(row+'\n')
    file_two.close()
    file_one.close()
    discovery= pd.read_csv(path)
    discovery_clean= discovery.iloc[1:] # remove top row
    cols = list(discovery_clean.columns[4:])
    discovery_clean[cols] =covery_clean[cols].apply(pd.to_numeric,errors='coerce')
    #create visualisation

我想要在语法上有效的VHDL,它执行相同的操作:

module bus_fifo #(
    parameter DEPTH_WIDTH = 0,
    parameter DATA_WIDTH = 0
) (
    input  wire                    clk,
    input  wire                    rst,

    input  wire [DATA_WIDTH-1:0]       wr_data_i,
    input  wire                wr_en_i,

    output wire [DATA_WIDTH-1:0]       rd_data_o,
    input  wire                        rd_en_i,

    output wire                full_o,
    output wire                        empty_o
);

localparam DW = (DATA_WIDTH  == 10) ? 4 : DATA_WIDTH;
localparam AW = DEPTH_WIDTH>>2;

endmodule

我遇到的问题是VHDL不支持三元运算符,并生成和错误消息。我想知道是否有VHDL解决方案可以做与我在Verilog中所做的类似的事情?

3 个答案:

答案 0 :(得分:2)

我通常使用一个函数(名为“ If Then Else” = ite)来解决VHDL中缺少三元运算符的问题。

function ite(b: boolean; x, y: integer) return integer is begin
    if (b) then
        return x;
    else
        return y;
    end if;
end function ite;

这种用法:

constant foo : integer := ite(SOME_INTEGER = 42, 1337, 4711);

您可以为不同的返回类型重载此函数。请注意,当用于初始化常量时,布尔表达式在求值时必须为常量。
一个更现实的例子,我经常使用的食谱:

entity foo is
  generic (
    DEBUG_LVL : integer := 0
  )
...
attribute MARK_DEBUG : string;
...
signal my_signal : std_logic;
attribute MARK_DEBUG of my_signal : signal is ite(DEBUG_LVL >= 1, "TRUE", "FALSE");

最后一个例子当然需要带有签名的“ ite function”

function ite(b: boolean; x, y: string) return string;

答案 1 :(得分:1)

VHDL 2019添加了初始值的条件赋值:

constant DW : integer := 4 when (DATA_WIDTH = 10) else DATA_WIDTH;

预计到2029年,供应商的支持(尤其是Xilinx)。

答案 2 :(得分:0)

您可以创建一个函数并在泛型的评估中调用该函数。