How to link const vars not referenced in source code, without modifying PRM file?

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

How to link const vars not referenced in source code, without modifying PRM file?

1,547 Views
FordFairlane
Contributor I

* Codewarrior 6.1 for microcontrollers

* S08AW60

* PRM file:  
SEGMENTS Z_RAM  =  READ_WRITE   0x0070 TO 0x00FF; RAM_A  =  READ_WRITE   0x0100 TO 0x025F; RAM_B  =  READ_WRITE   0x0260 TO 0x086F; ROM_A  =  READ_ONLY    0x1A00 TO 0x21FF; ROM_B  =  READ_ONLY    0x2200 TO 0xFFAF; ROM_C  =  READ_ONLY    0xFFC0 TO 0xFFCB; END PLACEMENT NVRAM           INTO  RAM_A; NVROM           INTO  ROM_A; DEFAULT_RAM     INTO  RAM_B; _PRESTART, ... DEFAULT_ROM     INTO  ROM_B; ...END

 

*C Source code:

unsigned char RAMVar1 @"NVRAM";unsigned char ROMVar1 @"NVROM"=0;unsigned char RAMVar2 @"NVRAM";unsigned char ROMVar2 @"NVROM"=245;...unsigned char RAMVar200 @"NVRAM";unsigned char ROMVar200 @"NVROM"=27;void InitNonVolatileVars(void){ unsigned char *pRAM; unsigned char *pROM; unsigned char n; n=__SEG_SIZE_NVRAM; pRAM=__SEG_START_NVRAM; pROM=__SEG_START_NVROM+LastCopyAddress(); do{*pRAM++=*pROM++;}while(--n);}void MyFunc(void)   { RAMVar1=RAMVar2;  ... }void SynchroRAM2ROM(void){...}

 

* Problem: ROMVars are not linked because they are not referenced in source code.

* Undesired solution: modify PRM file like this:

ENTRIES   ROMVar1   ROMVar2   ...   ROMVar200END

 

* Desired solution: modify source code like this:

unsigned char RAMVar1 @"NVRAM";__root unsigned char ROMVar1 @"NVROM"=0;unsigned char RAMVar2 @"NVRAM";__root unsigned char ROMVar2 @"NVROM"=245;...

 

I use "__root" for Atmel ATmega compiler, but I'd like the same code to run in Freescale's AW60:

#define __root __AlwaysLinkFreescale

How to do it?, is there a reserved word to tell the compiler and linker not to remove non referenced const vars?.

 

 

Thanks in advance

Labels (1)
Tags (1)
0 Kudos
3 Replies

643 Views
stanish
NXP Employee
NXP Employee

Hello FordFairlane,

 

I assume you don't want to use PRM file solution "ENTRIES" due to fact you would add all the ROMVars defined in it, right?

What about disable Smart Linking for the module that defines ROMVars only e.g.:

 

.PRM:

-------

ENTRIES

 main.c.o:*

END

 

 

or you can separate all the ROMVar definitions in separate module e.g. "ROMVars.C" & "ROMVars.h" and then you can avoid Smart Linking for the ROMVars only.

 

.PRM:

-------

ENTRIES

 ROMVars.c.o:*

END

 

 

Stanish

 

643 Views
FordFairlane
Contributor I

Thank you stanish, your solution is better than mine, but this is not what I'm looking for. I have a lot of non volatile variables defined in a lot of C files, I'd like not to modify all of them because it takes too much time and I'd like to use the same source code for Freescale and Atmel.

 

Thank you

0 Kudos

643 Views
Lundin
Senior Contributor IV
If you want the code to be portable, use ENTRIES and not some obscure __root syntax in the source itself. Also, don't use @ as it is equally obsucre and equally non-portable. You can't even port it to another Freescale compiler. The more you can stuff in the .prm file, the better.

Regarding modifying variables... any IDE has find & replace. If that isn't good enough, how hard is it for a programmer to write a text parser program on a Windows compiler? 1 hour of work at most.