Hi,
Do you know where I could have an example of a working example of a synthesizable mutex, please?
Or a synthesizable way to efficiently wait for an update WITHOUT a clock (arbitrary requirement) while avoiding to be stuck in an infinite loop ?
A latch is not my solution either because I would update the mutex value from different places which is forbidden.
“Cannot write to a variable ‘y’ that is also driven by an always_comb/always_latch/always_ff procedural block”
I am a beginner and I force myself into practical exercises above my skills to improve.
`define MAX_FINISH 30
package mutex;
int lock = 0;
int id = 0;
endpackage
module mutx(input int identifier,input logic need_it,output logic agreement);
int a = 0;
int has_lock = 0;
always
if (need_it == 1)
begin
$display("enter %d lock:%d agreement:%d",identifier,mutex::lock,agreement);
if (agreement == 1)
begin
a = 0;
$display("ee");
end
else
begin
while(mutex::lock != 0)
begin
#1;
a++;
$display("stuck");
end
$display("lock should be 1. %d lock:%d agreement:%d",identifier,mutex::lock,agreement);
mutex::lock = 1;
mutex::id = identifier;
agreement = 1;
end
end
else begin
#1;
mutex::lock = 0;
mutex::id = 0;
agreement = 0;
$display("done"); // I am stuck here. A synthsizable wait could be efficient.
end
endmodule
module one();
logic a = 0;
int id = 1;
logic agree;
int count = 0;
mutx hu(id,a,agree);
initial
begin
#1 a = 0;
#7 a = 1;
#7 a = 0;
#7 a = 1;
#2 a = 0;
end
always
begin
#1 $display("#1 agree is %d, lock is %d by %d at %t",agree, mutex::lock, mutex::id, $time);
count++;
if (count > `MAX_FINISH) $finish;
end
endmodule