0

all,i need help.i encounter question about array data transaction.Please help me! code is following. packet is data class,and there is three queue,R,G,B,and in module "test",arith function 's return_data is no data. why? question:though "into-arith" function,output tr_out is no data.

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);   //

    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

1 Answer 1

2

I couldn't event get this to compile in Questa, there are many syntax errors.

The three main problems are

  1. The declaration of the function is an error. You must use a typedef when returning an aggregate type (in your case an unpacked array of packet#())
  2. the assignment tr_out[4] = into_arith(in_tr); is illegal. You are trying to assign a unpacked array of 4 elements to the 5th element of an array, which doesn't even exist.
  3. The return tr_tmp[4]; is also illegal. You are trying to return the non-existent 5th element of an array as the return value for a function that requires a 4-element array.

See all my corrections below:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.