Passing parameters to a task

Hi,

I have a task as part of the class

task (file);

readfile (file, queue);

foreach(queue[i])
mem_array[i] = queue.pop_front();

endtask

The objective is to preload the data from the file to a memory array (behavioral memory
in ram library).
The problem is, the data in the file could be 1 or 2 or 4 bytes and memory array can be
of any width 1 or 2 or 4 bytes. So, I would like to pass ‘width’ as part of the task
argument so that I can split the data read from the file in chunks of the parameter ‘width’.
Now, how do I pass a parameter value to a task?

PS: I do not want to parametrize the class in the task is present, i just need to do it to the task).

Babu,

You didn’t describe how the data in queue is organized, but assuming it’s just a queue of bytes, you can use the streaming operator in one statement rather than needed to use a foreach loop.

mem_array = {>>{queue}};

If it is more complicated than that, you need to provide more info about how the data is organized and how the method readfile() works. An example of what the file and resulting memory array looks like would be great too.

This is what Im looking for.

My input file contains elements of any width say 2 bytes or 4 bytes wide.

i.e it could look like

D0D1
D2D3
.
.
.
DnDn-1

or

D3D2D1D0
D7D6D5D4
.
.
.

I should pass this file to a task say

task (filename, memory_width);

readfile(filename, queue).

→ The readfile task loads the queue with file contents.

From the queue, based on the memory width, i should
assign the byte lanes accordingly to the memory.

That is,

If the memory width is 2 bytes (bit [15:0] mem [8191:0])

I should assign D1 to [15:8] mem[0] and D0 to [7:0] mem[0].

If the width is 4, i should assign like

D3 to [31:24] mem[0]. D2 to [23:16] mem[0] D1 to [15:0] mem[0] and D0 to [7:0] mem[0].

Ideally, i would like to use a single task for this.

In reply to Babu Raghunathan:

Assuming that your queue is declared as

bit [7:0] queue[$];

and that readfile(file,queue) returns data ordered as

D0
D1
D2
D3

Then your code would be

mem = {>>{queue}}; // streams queue into mem, in order, left justified
foreach(mem[i]) mem[i] = {<<byte{mem[i]}}; // reverses bytes in each word.

Hi Dave, actually it is more than that, I got it working
by using dynamic arrays which does not need any parameter to
size.

Thanks,
Babu