How to declare a variable which can kept intact from startup zerout?

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

How to declare a variable which can kept intact from startup zerout?

跳至解决方案
1,378 次查看
Pang
Contributor I
Hi everyone,
 
I need to define a variable for power outage monitoring. It is a global variable. but I do not want it to be zeroout thru startup code. Olny the XIRQ ISR can change its value. Therefore, when SYSTEM Reset is assert and system restartup, it will zerout this variable. If this variable is asserted, I am going to skip all the initialization and return to where it were previously.
 
 where  and how to such a varible?
 
Thanks a lot for any inputs.
 
Pang
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
684 次查看
CrasyCat
Specialist III
Hello
 
The linker allows you to specify memory area which should not be touched by the startup code.
 
So basically here you need to:
  1- Define the variable in a user defined data segment.
      For example:
      #pragma DATA_SEG KeepData
      int MyVar;
      #pragma DATA_SEG DEFAULT
  2- Make sure you are specifying the same section name in the variable declaration.
      For example:
      #pragma DATA_SEG KeepData
      extern int MyVar;
      #pragma DATA_SEG DEFAULT
  3- In your .prm file define a memory area with attribute NO_INIT instead of READ_WRITE.
      For Example:
     SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
        Z_RAM  = READ_WRITE 0x0050 TO 0x00FF;
        RAM_NOINIT    = NO_INIT 0x0100 TO 0x0101;
        RAM    = READ_WRITE 0x0102 TO 0x023F;
        ROM    = READ_ONLY  0xB000 TO 0xFDFF;
    END
  4- Place your section in the above defined memory area.
      For example:
      PLACEMENT
         DEFAULT_ROM                   INTO ROM;
         DEFAULT_RAM                   INTO RAM;
         KeepData                             INTO RAM_NOINIT;
         _DATA_ZEROPAGE, MY_ZEROPAGE   INTO Z_RAM;
END

That should do it.
CrasyCat

在原帖中查看解决方案

0 项奖励
回复
1 回复
685 次查看
CrasyCat
Specialist III
Hello
 
The linker allows you to specify memory area which should not be touched by the startup code.
 
So basically here you need to:
  1- Define the variable in a user defined data segment.
      For example:
      #pragma DATA_SEG KeepData
      int MyVar;
      #pragma DATA_SEG DEFAULT
  2- Make sure you are specifying the same section name in the variable declaration.
      For example:
      #pragma DATA_SEG KeepData
      extern int MyVar;
      #pragma DATA_SEG DEFAULT
  3- In your .prm file define a memory area with attribute NO_INIT instead of READ_WRITE.
      For Example:
     SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
        Z_RAM  = READ_WRITE 0x0050 TO 0x00FF;
        RAM_NOINIT    = NO_INIT 0x0100 TO 0x0101;
        RAM    = READ_WRITE 0x0102 TO 0x023F;
        ROM    = READ_ONLY  0xB000 TO 0xFDFF;
    END
  4- Place your section in the above defined memory area.
      For example:
      PLACEMENT
         DEFAULT_ROM                   INTO ROM;
         DEFAULT_RAM                   INTO RAM;
         KeepData                             INTO RAM_NOINIT;
         _DATA_ZEROPAGE, MY_ZEROPAGE   INTO Z_RAM;
END

That should do it.
CrasyCat
0 项奖励
回复