In a Verilog testbench.v, there are commands that are used in a task.
task cmd_script;
begin
...
event check1_e;
event check2_e;
..
integer cmd_file;
integer cmd_char;
reg [31:0] head_data;
reg [31:0] tail_data;
cmd_file = fopen("data.txt");
cmd_char = $fgetc(cmd_file);
while(cmd_char != EOF) begin
...
$fscanf(cmd_file, "%s\n", cmd);
case (cmd)
TEST1 : begin
end
TEST2 : begin
$fscan(cmd_file, "%h %h\n", head_data, tail_data);
->check1_e = head_data;
end
...
end
Can I pass variable name as a string to an event, or can an event name can be manipulated?
2 Answers 2
You can create an associative array of events map strings to events
event check1_e;
event check2_e;
...
event emap[string] = '{"check1_e":check1_e, "check2_e":check2_e, ...};
Then use this code to trigger
string head_data;
head_data = "check1_e"
if (emap.exists(head_data))
->emap[head_data];
else
$error("%s event does not exist",head_data);
No, it is not possible to assign a value to an event
type in SystemVerilog that way.
The following is a syntax error:
->check1_e = head_data;
The following is proper usage of an event
:
->check1_e;
That syntax is used to trigger an event which can be detected elsewhere in the code by waiting for the event using syntax such as the following:
@(check1_e);
Events are used like a simple handshake, or communication between processes. They can not pass values.
Refer to IEEE Std 1800-2017, section 6.17 Event data type
Explore related questions
See similar questions with these tags.
head_data
had the value 32'h5C8A8B42. How do you want your attempted statement->check1_e = head_data;
to behave? See xyproblem.info \$\endgroup\$