MPC5xx: Declaration of non-volatile variable

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

MPC5xx: Declaration of non-volatile variable

4,940 Views
james-lee
NXP Employee
NXP Employee
Hello,

I would to declare non-volatile variable in CodeWarrior for MPC5xx. It means the variable keeps its previous value even after reset. In case of Infineon's TASKING compiler, she has used the noclear pragma for that. Does CodeWarrior compiler support the same function as that? If yes, please let me know which pragma section I could use.


Best regards,
James

Message Edited by CrasyCat on 2007-04-13 02:30 PM

Labels (1)
0 Kudos
4 Replies

392 Views
james-lee
NXP Employee
NXP Employee
Thank you so much! CrasyCat, Lundin,
0 Kudos

392 Views
CrasyCat
Specialist III
Hello
 
OK I get it.
For PowerPC you have to do as follows:
  - Define your variable in a user defined section.
    This is done as follows:
#pragma section data_type ".myIData" ".myUData" data_mode=far_abs code_mode=pc_rel
__declspec(section ".myIData")int MyVar[100];
  - Place .myIData and .myUData accordingly in your linker file.
    Variable will be placed in .myIData if it is defined with an initializer. It will be placed in .myUData if it is defined without initialization value.
 GROUP : {
  .data : {}
  .myIData: {}
  .sdata : {}
  .sbss : {}
  .sdata2 : {}
  .sbss2 : {}
  .bss : {}
  _myDataStart=.;
  .myUData: {}
  _myDataEnd=.;
  .PPC.EMB.sdata0 : {}
  .PPC.EMB.sbss0 : {}
 } > ram
  Label _myDataStart will be defined by the linker and will point to start address of the section myUData.
  - Do a local copy of the module __start.c (located in {Install}\PowerPC_EABI_Support\Runtime\Src
  - Update your __start.c module as follows:
    Add an external declaration for the symbol _myDataStart:
       extern char _myDataStart[];
     In the function __init_data skip the block if address is equal to _myDataStart.
     For uninitialized variable, modify the block starting with /*Initialized with zeros */ as follows:
 bii = _bss_init_info;
 while (1) {
  if (bii->addr == 0 && bii->size == 0) break;
  if (bii->addr == _myDataStart) break;
   __init_bss_section(bii->addr, bii->size);
   bii++;
 }
     For uninitialized variable, modify the block starting with /*Copy ROM to RAM */ as follows:
 dci = _rom_copy_info;
 while (1) {
  if (dci->rom == 0 && dci->addr == 0 && dci->size == 0) break;
  if (dci->addr == _myDataStart) break;
   __copy_rom_section(dci->addr, dci->rom, dci->size);
   dci++;
 }
This should do it.
 
CrasyCat
0 Kudos

392 Views
Lundin
Senior Contributor IV
Make a separate section in your .prm file, for example:

NO_INIT_RAM = NO_INIT 0x3FF0 TO 0x3FFF;

Then put your variable into that segment

#pragma DATA_SEG NO_INIT_RAM
static int x;
#pragma DATA_SEG_DEFAULT


And as mentioned, the volatile keyword has nothing to do with it.
0 Kudos

392 Views
CrasyCat
Specialist III
Hello

Keyword volatile in ANSI C does not tell the compiler not to initialize a variable.
It just informs the compiler it should not optimized access to the specified variable when generating code.
volatile attribute is normally used for variables, which values may change asynchronously to the normal execution flow (typically an I/O port, a variable modified by different tasks in a multi tasking or multi thread application, ...).

There is no easy way to achieve what you are trying to do here. Only solution is to fine tune the startup code manually.

I have done that once. I just have to retrieve the appropriate source code.
I will send you another post next week with an example how to achieve that.

CrasyCat
0 Kudos