How to initialize memory.

C

Chih-Hsu Yen

Guest
Hello,
If one memory "reg [9:0] stack[127:0]" is used, then how to write an
easy reading and synthesizable code to initialize this memory? I want the
code like the followings, but it seems that the task can not have memory
declaration inside it.

always@ ( posedge clk )
begin
if ( reset )
begin
initial_fifo( stack);
end
end

task initial_fifo;
output [9:0] stack[127:0];
begin
stack[0]<= 10'd0;
stack[1]<=10'd1;
stack[2]<=10'd2;
.
.
.
stack[127]<=10'd127;
end
endtask
 
You don't need to pass any parameters to the task. Just use the global
memory definition.
 
<michaelst@gmail.com>
???????:1140427593.538808.126570@g44g2000cwa.googlegroups.com...
You don't need to pass any parameters to the task. Just use the global
memory definition.

Thank you very much. However, after linting the code, it caused an error,
nonblocking and blocking problem, because it considers initial_fifo task is
a blocking assignment, even the nonblocking assignments are used in the
tast. If I want to keep all statements in non-blocking assignment, what can
I do?

always@ ( posedge clk )
begin
if ( reset )
initial_fifo;
else
stack <= data_in;
end

task initial_fifo;
output [9:0] stack[127:0];
begin
stack[0]<= 10'd0;
stack[1]<=10'd1;
stack[2]<=10'd2;
.
.
.
stack[127]<=10'd127;
end
endtask
 
always@ ( posedge clk )
begin
if ( reset )
begin
initial_fifo;
end
else begin
... the work with the fifo ....
end
end

task initial_fifo;
begin
stack[0]<= 10'd0;
stack[1]<=10'd1;
stack[2]<=10'd2;
.
.
.
stack[127]<=10'd127;
end
endtask
 

Welcome to EDABoard.com

Sponsor

Back
Top