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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
1,125 Views
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
Labels (1)
Tags (1)
0 Kudos
1 Solution
431 Views
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

View solution in original post

0 Kudos
1 Reply
432 Views
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 Kudos