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,381件の閲覧回数
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 解決策
687件の閲覧回数
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 返信
688件の閲覧回数
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 件の賞賛
返信