Static variable not cleared at reset

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

Static variable not cleared at reset

853 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by celephicus on Wed May 30 19:49:22 MST 2012
Greetings,

We all know that variables declared static with no explicit initialization are implicitly set to zero by the start up code. Now, how do I declare a static variable that is NOT so initialized? I need this to keep state during a watchdog reset so that I can ascertain which thread blocked and caused the reset.

Hopefully this can be done without linker trickery.
0 项奖励
回复
3 回复数

826 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Thu May 31 00:59:36 MST 2012
Looking at a map file I noticed the section [I].uninit_RESERVED[/I] which brought me to this help page.

I think you could use this section attribute for what you want. All the linker script trickery was done for you.
0 项奖励
回复

826 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by celephicus on Wed May 30 20:44:47 MST 2012

Quote: fastmapper
I presume the static variable you are declaring is in RAM.  If that is the case, what would the value of an uninitialized variable be on the first reset after each power up?

Maybe you should consider something in non-volatile memory (e.g. flash) that you can initialize before the first reset and update as necessary for all subsequent resets.



The variable is cleared on a power on reset (which can be ascertained by reading SYSRSTSTAT). On other resets, the variable contains useful information which is read and stored elsewhere.
0 项奖励
回复

826 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fastmapper on Wed May 30 20:36:55 MST 2012
I presume the static variable you are declaring is in RAM.  If that is the case, what would the value of an uninitialized variable be on the first reset after each power up?

Maybe you should consider something in non-volatile memory (e.g. flash) that you can initialize before the first reset and update as necessary for all subsequent resets.
0 项奖励
回复