__IO what is

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

__IO what is

2,949 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by blasiis on Wed May 26 00:39:25 MST 2010
LPCXpresso with LPC1758
Sorry for my simply question, but I need to undestand the difference from

__IO uint32_t tx_head;

and

uint32_t tx_head

I have tested in ram and ther'isnt difference !!
0 项奖励
回复
3 回复数

1,369 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by blasiis on Wed May 26 02:21:52 MST 2010

Quote: nerd62
Hi blasiis,

__IO is a preprocessor symbol which is defined to "volatile" (as rkiryanov wrote this). The "volatile" attribute tells the optimizer not to optimize too much. The content of the register may be changed by an other process from what the optimizer does not know about - so the content of the register has to be read everytime when there are made decisions which depend on the true content. When the optimizer does not know about the "volatile" attribute he may have the idea to copy the content of the IO-register into a general purpose register and make further decisions with the content of this general purpose register. This may work in one case - when you make small changes at your code it suddenly won't work. This leads e. g. to polling loops which suddenly don't terminate. I have spent a lot of time to debug such (homebrewed) errors in my last project.

Have much fun with your LPC, nerd62 ;-)


Therefor for  safety reasons it is best to put it in structure or similar
0 项奖励
回复

1,369 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nerd62 on Wed May 26 01:23:37 MST 2010
Hi blasiis,

__IO is a preprocessor symbol which is defined to "volatile" (as rkiryanov wrote this). The "volatile" attribute tells the optimizer not to optimize too much. The content of the register may be changed by an other process from what the optimizer does not know about - so the content of the register has to be read everytime when there are made decisions which depend on the true content. When the optimizer does not know about the "volatile" attribute he may have the idea to copy the content of the IO-register into a general purpose register and make further decisions with the content of this general purpose register. This may work in one case - when you make small changes at your code it suddenly won't work. This leads e. g. to polling loops which suddenly don't terminate. I have spent a lot of time to debug such (homebrewed) errors in my last project.

Have much fun with your LPC, nerd62 ;-)
0 项奖励
回复

1,369 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rkiryanov on Wed May 26 01:05:12 MST 2010

Quote: blasiis



__IO = volatile
__I = volatile const
0 项奖励
回复