Search code examples
macrosverilogsystem-verilog

SystemVerilog macro through task


How to send macros as parameters through a task?

In the testbench:

`define CPU1 tb.top.dual_processor_db_wrapper_i.dual_processor_db_i.cpu1.inst
`define CPU2 tb.top.dual_processor2_db_wrapper_i.dual_processor2_db_i.cpu2.inst

initial begin
    fork
        cpu_init(`CPU1);
        cpu_init(`CPU2);
    join
    // Other stuff with `CPU1 and `CPU2
    
    `CPU1.write_data(addr, 4, data, resp); // Works
end

task cpu_init(cpu);
    cpu.por_srstb_reset(1'b1); // Does not work
    // Other init stuff
endtask

Error when compiling:

ERROR: [VRFC 10-2991] 'por_srstb_reset' is not declared under prefix 'cpu'

The type of the `CPUs is unknown (to me). Perhaps Xilinx has a type for it, since it references their MPSoC VIP?

I assume por_srstb_reset and write_data are tasks or functions from Xilinx MPSoC VIP, but I'm not sure.

Xilinx documentation is very sparse


Solution

  • I general, it is possible to pass a macro as an argument to a task. However, it is not possible to pass a hierarchical reference as an argument to a task (it is illegal).

    Operations on hierarchical references are very limited, in general.

    Your task declaration is equivalent to the following:

    task cpu_init (input logic cpu);
    

    The cpu variable is a 1-bit type. So, the following is legal:

    `define CPU1 1'b1
    cpu_init(`CPU1);
    

    The type of the argument must match between the declaration and the task call.