WARP Project Forums - Wireless Open-Access Research Platform

You are not logged in.

#1 2017-Feb-09 09:08:01

marco
Member
Registered: 2016-Nov-06
Posts: 21

inline, static and volatile functions and variables

Hi,

I often see functions and variables declared as "inline", "volatile" and "static". Even though I know the meaning of such keywords, sometimes I find myself confused about their usage in 802.11 reference design. Please, can you give me an idea about their meaning and their usage in the context of 802.11 reference design c code?
Thank you.

Offline

 

#2 2017-Feb-09 13:23:44

chunter
Administrator
From: Mango Communications
Registered: 2006-Aug-24
Posts: 1212

Re: inline, static and volatile functions and variables

Here is the general intent:

- We use "inline" for functions that are small and time-sensitive in the hopes that we encourage the compiler to copy the function wherever it is called rather than suffer the latency hit of a context switch into the function. All of that said, "inline" is really just a suggestion to the compiler and it probably gets ignored when optimized for size. In the next release of the design, we are increasing the amount of BRAM available to CPU_LOW so we should be able to get away with optimizing for speed rather than size. More details available here.

- We use "static" for a couple of purposes. When applied to a global variable, the "static" keyword has the effect of scoping the variable to that particular file so it can't be externed. We do that just for protection against externs from other files that can be confusing to debug. When used within a function, it ensures that the variable holds its value from the previous time the function was called.

- "volatile" is very useful to keep the compiler from trying to optimize away operations on registers to peripherals running in the FPGA fabric. It ensures that it doesn't try to short-circuit the execution of a read operation simply because it believes the values to be unchanged (i.e. it isn't aware of the fact the value might be changed by the underlying hardware)

Offline

 

#3 2017-Feb-10 16:41:25

marco
Member
Registered: 2016-Nov-06
Posts: 21

Re: inline, static and volatile functions and variables

Thank you. Very informative answer.

Offline

 

Board footer