使用宏会出错,但显式放入宏文本确实有效

问题描述 投票:0回答:1

我正在使用开源的pulp_platform_common_cells,它已为Xilinx FPGA 实现,我想对其进行转换,以便它也可以在Quartus 中运行。在 Vivado 中,该项目综合得很好,但在 Quartus 中,我的stream_throttle.sv 文件出现以下错误:

  • stream_throttle.sv(90) 文本附近的 Verilog HDL 语法错误:“(”;期望“endmodule”
  • stream_throttle.sv(90) 文本附近的 Verilog HDL 语法错误:“)”;期待“;”
  • stream_throttle.sv(90) 处的 Verilog HDL 声明错误:标识符“credit_d”已在当前范围内声明
  • stream_throttle.sv(90) 文本附近的 Verilog HDL 语法错误:“'0”;期待一个标识符

此错误发生在

FF(credit_q, credit_d, '0, clk_i, rst_ni)
部分,其中`FF是宏。
如果我把宏的内容放在那里,一切都会很好地合成。这个宏可能有什么问题?

错误发生在代码末尾附近。我用注释标记了哪些有效,哪些无效。为了简单起见,我将其抱怨的宏放在顶部。

`define FF (__q, __d, __reset_value, __clk , __arst_n ) \
  always_ff @(posedge (__clk) or negedge (__arst_n)) begin                           \
    if (!__arst_n) begin                                                             \
      __q <= (__reset_value);                                                        \
    end else begin                                                                   \
      __q <= (__d);                                                                  \
    end                                                                              \
  end

/// Throttles a ready valid handshaked bus. The maximum number of outstanding transfers have to
/// be set as a compile-time parameter, whereas the number of outstanding transfers can be set
/// during runtime. This module assumes either in-order processing of the requests or
/// indistinguishability of the request/responses.

module stream_throttle (clk_i, rst_ni, req_valid_i, req_valid_o, req_ready_i, req_ready_o, rsp_valid_i, rsp_ready_i, credit_i);

    /// The maximum amount of allowable outstanding requests
    parameter MaxNumPending = 1,
    /// The width of the credit counter (*DO NOT OVERWRITE*)
    CntWidth = cf_math_pkg::idx_width(MaxNumPending);
    /// The type of the credit counter (*DO NOT OVERWRITE*)
    typedef logic [cf_math_pkg::idx_width(MaxNumPending)-1:0] credit_t;

    /// Clock
    input  logic clk_i;
    /// Asynchronous reset, active low
    input  logic rst_ni;

    /// Request valid in
    input  logic    req_valid_i;
    /// Request valid out
    output logic    req_valid_o;
    /// Request ready in
    input  logic    req_ready_i;
    /// Request ready out
    output logic    req_ready_o;

    /// Response valid in
    input  logic    rsp_valid_i;
    /// Response ready in
    input  logic    rsp_ready_i;

    /// Amount of credit (number of outstanding transfers)
    input  credit_t credit_i;

    // we use a credit counter to keep track of how many transfers are pending at any point in
    // time. Valid is passed-through if there is credit.
    credit_t credit_d;
    credit_t credit_q;

    // we have credit available
    logic credit_available;

    // implement the counter. If credit is available let the valid pass, else block it. Increment
    // the counter once a request happens, decrement once a response arrives. Assumes in-order
    // responses.
    always_comb begin : proc_credit_counter

        // default: keep state
        credit_d = credit_q;

        // on valid outgoing request: count up
        if (req_ready_o & req_valid_o) begin
            credit_d = credit_d + 'd1;
        end

        // on valid response: count down
        if (rsp_valid_i & rsp_ready_i) begin
            credit_d = credit_d - 'd1;
        end
    end

    // credit is available
    assign credit_available = credit_q <= (credit_i - 'd1);

    // a request id passed on as valid if the input is valid and we have credit.
    assign req_valid_o = req_valid_i & credit_available;

    // a request id passed on as ready if the input is ready and we have credit.
    assign req_ready_o = req_ready_i & credit_available;
    // state
    `FF(credit_q, credit_d, '0, clk_i, rst_ni) // THIS DOES NOT WORK
    // always_ff @(posedge (clk_i) or negedge (rst_ni)) begin // THIS DOES WORK                          
    //     if (!rst_ni) begin                                                             
    //     credit_q <= ('0);                                                        
    //     end else begin                                                                   
    //     credit_q <= (credit_d);                                                                  
    //     end                                                                              
    // end

endmodule : stream_throttle
verilog system-verilog quartus
1个回答
0
投票

改变:

`define FF (__q, __d, __reset_value, __clk , __arst_n ) \

至:

`define FF(__q, __d, __reset_value, __clk , __arst_n ) \
© www.soinside.com 2019 - 2024. All rights reserved.