Task controlling issue!

Hi all,

I am using the task(read_register),From the bench i am calling parallel from multiple places.And the task is not the automatic type.To avoid the conflict between the two calls i added semaphores to control the access.

Issue : I am observing in my simulations that when task is called parallel one of the address got the key and other is waiting for the key.meanwhile after the first address read again called with another address that got the key instead of getting key to the holding address.Here after done read with new address the address which is holding for key it came out from the task and it is misbehaving.

Ex : File1(seq in UVM) : ------------------------------------ File2(Scoreboard in UVM) :

  @(int)          ---------------------------------------          @(int)
   top.read_reg(10);  ------------------------------------          top.read_reg(20);
   $display("Vamshi") --------------------------------------        top.read_reg(30);

//It is in the Top module 
task read_reg(addr,rd_data);
int addr_inp;
$display("before sema addr is %0h",addr);
sema.get(1);
addr_inp =addr;
$display("after sema addr is %0h",addr_inp);

@(posedge clk);
force x.y.addr = addr_inp
..
..
..
sema.put(1);
$display("read done for addr is %0h,data is %0h",addr,rd_data);
endtask

log print from the task :

10ns before sema addr 10
10ns after sema addr 10
10ns before sema addr 20
50ns read done for addr 10 data is 30000
50ns before sema addr 30
50ns after sema addr 30
90ns read done for addr 30 data is 559959
90ns Vamshi → Here it shouldn’t print this message due to it doesn’t got key still

How to avoid this type situation please anybody can help on this.

Thanks,
Vamshi Krishna B

In reply to vamshikrishnaboosam:

You need to declare the task as automatic. Otherwise the arguments to the task get overwritten when called in parallel.

I*In reply to dave_59:*

Hi Dave,

Thanks for the response i am using some forces inside the task(It is static type) and i am assigning the arguments further in task.If am not wrong I cnnt declare it has automatic.

Thanks,
Vamshi

In reply to vamshikrishnaboosam:
You can declare addr_inp as a static variable inside your automatic task. I assume you are using the semaphores to ensure that there is only one active force at a time, so you only need one instance of addr_inp.

you can declare static queue and push_back before getting semaphore and pop_front after getting semaphore