UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer micrenda
Observer
7,087 Views
Registered: ‎07-04-2014

Static var inside a function

Hello,

 

I need your help about the scope of a static ver (a memory) inside a function.

 

 

I have two modules:

 

module moduleWriter(input clock, input reset, input enabled);
module moduleReader(input clock, input reset, input enabled, output var[7:0] value);

 

 

 

Both of them uses a function which has a static variable inside:

 

function [7:0] memoryFunc(var opWrite, var[31:0] address, var[7:0] value = 0);

    static var [7:0] ram [0:1023]; 

    if (opWrite)
    begin
        ram[address] = value;
        return value;
    end
    else
        return ram[address];

endfunction

 

The ram variable wants to be a buffer written from several section of code.

In the attached example I aspect to have in output leds the value 30, but I get always 0. It seems the value rams is iniziled every time I called memryFunc.

 

Do you have an idea about what is wrong? I am using SystemVerilog and Vivado 2015.4, simulating a VC707 board.

Attached you can find a self consistent example.

 

Thank you

Michele Renda

Tags (1)
0 Kudos
2 Replies
Observer micrenda
Observer
7,075 Views
Registered: ‎07-04-2014

Re: Static var inside a function

I think I found the possible cause:

SystemVerilog has static and automatic tasks and functions. Vivado synthesis treats all tasks and functions as automatic.

http://www.xilinx.com/support/answers/51533.html

 

Anyone has a suggestion how can I workaround this? The other solution that comes to my mind is to pass the memory by ref, but Vivado System Verilog dialect does not support this too.

0 Kudos
Observer micrenda
Observer
7,053 Views
Registered: ‎07-04-2014

Re: Static var inside a function [SOLVED]

With the help of someone a bit more expert I found the right way to implement what I wanted. I post here the results to help other people with the same problem.

 

Regards