2014-02-21 60 views
0

所有,我需要help.i遇到有關數組數據transaction.Please幫助我!代碼如下: 數據包是數據類,並且有三個隊列,R,G,B,並且在模塊「test」中,arith函數的return_data不是數據。爲什麼? 問題:雖然「進入arith」函數,輸出tr_out是沒有數據。如何編寫關於返回數據的函數

class packet # (int bit_depth =16);//packet class 

    bit [bit_depth-1:0] R[$]; 
    bit [bit_depth-1:0] G[$]; 
    bit [bit_depth-1:0] B[$]; 

endclass 

//包是數據類

module test #(active_num=1920); // 

    packet in_tr [4]; 

    initial begin 
     foreach(in_tr[i]) begin 
      in_tr[i] = new(); 
     end 
     foreach(in_tr[j]) begin 
      for(int i=0;i<1920;i++) begin 
       in_tr[j].R.push_back(i); 
      end 
     end 
     process_in_tr; 
    end 

    task process_in_tr(); 
     packet tr_out[4]; 

     foreach(tr_out[i])begin 
      tr_out[i] = new(); 
     end 

     tr_out[4] = into_arith(in_tr); 

     foreach(tr_out[j]) begin 
      foreach(tr_out[j].R[i]) begin 
       $display("%h",tr_out[j].R[i]); 
      end 
     end 
    endtask 


    function packet[4] into_arith(ref packet in_tr[4]); 
     packet tr_tmp[4]; 

     foreach(tr_tmp[i]) begin 
      tr_tmp[i] = new(); 
     end 

     for(int m=0;m<4;m++) begin 
      foreach(in_tr[m].R[i]) begin 
       tr_tmp[m].R.push_back(in_tr[m].R[i]); 
       tr_tmp[m].G.push_back(in_tr[m].G[i]); 
       tr_tmp[m].B.push_back(in_tr[m].B[i]); 
      end 
     end 

     return tr_tmp[4]; 
    endfunction 

endmodule 

回答

2

我無法事件得到這個編譯奎斯塔,有很多語法錯誤。

的三個主要問題是

  1. 函數的聲明是錯誤的。你必須在返回一個聚合類型時使用typedef(在你的情況下是一個解包數組#())
  2. 賦值tr_out[4] = into_arith(in_tr);是非法的。您試圖將一個4個元素的解壓數組分配給數組的第5個元素,該元素甚至不存在。
  3. return tr_tmp[4];也是非法的。您試圖返回數組中不存在的第5個元素作爲需要4元素數組的函數的返回值。

見下面我所有的更正:

class packet # (int bit_depth =16);//packet class 
    bit [bit_depth-1:0] R[$]; 
    bit [bit_depth-1:0] G[$]; 
    bit [bit_depth-1:0] B[$]; 
endclass 

//packet is data class 

module test #(active_num=1920); // 

    typedef packet#() packet4_t[4]; 

    packet4_t in_tr; 

    initial begin 
     foreach(in_tr[j]) begin 
      in_tr[j] = new(); 
      for(int i=0;i<1920;i++) 
      in_tr[j].R.push_back(i); 
     end 
     process_in_tr; 
    end 

    task process_in_tr(); 
     packet4_t tr_out; 

     tr_out = into_arith(in_tr); 

     foreach(tr_out[j]) begin 
      foreach(tr_out[j].R[i]) begin 
       $display("%h",tr_out[j].R[i]); 
      end 
     end 
    endtask 

    function automatic packet4_t into_arith(ref packet4_t in_tr); 
     packet4_t tr_tmp; 

     foreach(tr_tmp[i]) begin 
      tr_tmp[i] = new(); 

      tr_tmp[m].R = in_tr[m].R; 
      tr_tmp[m].G = in_tr[m].G; 
      tr_tmp[m].B = in_tr[m].B; 
      /* assigments above are the same as the foreach loop below 
     foreach(in_tr[m].R[i]) begin 
      tr_tmp[m].R.push_back(in_tr[m].R[i]); 
      tr_tmp[m].G.push_back(in_tr[m].G[i]); 
      tr_tmp[m].B.push_back(in_tr[m].B[i]); 
      end */ 
     end 

     return tr_tmp; 
    endfunction 

endmodule 
+0

嗨dave_59,我解決這個問題! – crazylk