Data integrity issue while writing and reading from mailbox with different write and read clocks

HI,
I am facing a problem while reading and writing from a mailbox w.r.t clocks of different frequencies. I am writing 32 bytes into mailbox mbx1, reading bytes from mbx1 using 1ns clock, assembling bytes into quad word (of 8 bytes) and writing the quadword into mailbox mbx2 using 8ns clock. When I read the quadword from mbx2, it is not same as the one written. I a giving the code and simulator output below:

 

module test;

logic clk, clkx8;

class qword;
  logic [63:0] wdata;
endclass

class reasm_driver;
  mailbox mbx1;
  mailbox mbx2;
  
  function new (mailbox mbx1);
   	mbx2 = new ();
	this.mbx1 = mbx1;
  endfunction
  
  task mbx_wr();
    static int cnt = 0; 
	static logic [15:0] cnt1 = 32;
	static logic [7:0] channel = 0;
    for (int i = 0; i < 32; i++) begin
	  mbx1.put(cnt); 
	  cnt++;
	end
  endtask
  
  task msg_drive_sec();
    logic [7:0] data_lcl;
	qword qword_inst;
	qword_inst = new();	
	 repeat (4) begin 
       for (int i = 0; i < 8; i++)begin
	      mbx1.get(data_lcl);
		  qword_inst.wdata [(8 * i + 8)-1 -: 8] = data_lcl;
          @(posedge clkx8); 
        end
       $display (" word written is %h  time is %g", qword_inst.wdata, $time );
     	mbx2.put (qword_inst); 
		
    end
  endtask
  
  task msg_drive_prim();
    qword qword_lcl;
	qword_lcl = new ();
    repeat (4) begin
	@(posedge clk);
      mbx2.get(qword_lcl);
      $display ("word read is = %h time = %g", qword_lcl.wdata, $time);
	end
  endtask
  
endclass

  reasm_driver rsm_drv_inst;
  mailbox mbx1;
 
  initial begin
    mbx1 = new();
	rsm_drv_inst = new (mbx1);
	fork
	  rsm_drv_inst.mbx_wr();
      rsm_drv_inst.msg_drive_prim();
      rsm_drv_inst.msg_drive_sec(); 	  
	join
  end
  
  initial begin
    clk = 1'b1;
	forever begin
	  # 4 clk = !clk;
	end
  end
  
  initial begin
    clkx8 = 1'b1;
	forever begin
	  # 0.5 clkx8 = !clkx8; 
	end
  end
  
endmodule


The simulator output is given below -

Chronologic VCS simulator copyright 1991-2019
Contains Synopsys proprietary information.
Compiler version P-2019.06-1; Runtime version P-2019.06-1; May 12 13:31 2020
word written is 0706050403020100 time is 16
word read is = 0706050403020108 time = 16
word written is 0f0e0d0c0b0a0908 time is 32
word read is = 0f0e0d0c0b0a0910 time = 32
word written is 1716151413121110 time is 48
word read is = 1716151413121118 time = 48
word written is 1f1e1d1c1b1a1918 time is 64
word read is = 1f1e1d1c1b1a1918 time = 64
Execution interrupted or reached maximum runtime.
Done

Can someone please help me to understand the issue. I need clocks (clk and clkx8 ) of different frequencies to convert quadword into byte and vice versa in my testbench.

thanks
-sunil

In reply to puranik.sunil@tcs.com:

Several issues:

  • Never use an untyped mailbox. It will lead to undesired consequences if you attempt to write and read different data types from the same mailbox.
  • When you are using class handles in any TLM scenario, you should always clone the item prior to sending it to prevent overwriting of the class data.

If you fix these issues, your test will work as expected.