Const Variables

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

Const Variables

4,738 Views
Andrew
Contributor I
Hi,
I'm trying to allocate const variables in ROM on my HCS08GT32. I've tried with "-Cc" option, but it doesn't work: the variables remain in the RAM. What's the best way to allocate variables in ROM?
Thanks
Andrew
Labels (1)
0 Kudos
11 Replies

897 Views
Ricardo_RauppV
Contributor I

Crasy cat

a) Just 10 minutes ago I did something wich worked!!!

I think it has something to do with your help...that is:

In the begining I declared a const array ( I call tables) in a cpp file and so extern it in its such .h file.

Well, this was not enough to work fine..

So I tried to include the h file in the cpp file, although I thought it should not be needed..

BUT for my surprise, now everything is OK..there is..my tables (const arrays) are in ROM !!!!!

Is it what you mean?

 

b) By the way..could help me or direct me to a post about:

I have many functions wich are states of state machine processor, so they are accessed only by pointers.

CW simply put all functions in NOT USED section.

The ENTRIES usage in PRM file will be very hard taks, due to a state machine based application has many many states/functions.

Imagine if for each new one I need to copy it into prm file?

 

 

0 Kudos

897 Views
CompilerGuru
NXP Employee
NXP Employee

Usages by pointer (by name) are still usages. As long a function is referred to anywhere it should get linked. The only case linking would not happen automatically is if the numerical address is used to call functions (or to refer to objects in general),

e.g. Calls like ((void(*)())0xF000)()

wont cause a function located at 0xF000 to be linked.

But with this setup, the hard part is to make sure the numbers are all correct, and not to list the function in the prm.

In case all addresses are offsets into a global table (function pointer array) then listing the name of that table in the prm ENTRIES is all that is needed.

 

 

Daniel

 

0 Kudos

897 Views
Ricardo_RauppV
Contributor I

Hi guys

I´m facing this problem right now using a QE128 in CW6.0 pro (C++).

I have used "const" (when in C) to put anything in ROM, like

uint8 const init_table[]={1,2,3,4};

For my surpise ( I´ve used CW for many years...) my current design (the first in C++), wich has about 10 tables like the above, simply allocates some (major..) tables in RAM (.bss in map file).

I tried:

-Cc option = not work

 __far = not work

I don´t use any SEGMENT pragma in my application, there is, the ordinary const keyword

should be enough to put such tables in ROM, right?

I spent the weekend on it, but I lost ....

Some tip for me?

Thanks in adavnce !!

 Ricardo Raupp

 

 

0 Kudos

897 Views
CrasyCat
Specialist III

Hello

 

I did a short test in C++ and got my constant table in .rodata without any trouble.

There is one thing that you need to know when it goes around constants and C++.

 

In C++, constants, which are defined in a module, but are not declared previously, are supposed to be static. An external declaration must precede the constant definition

CrasyCat

0 Kudos

897 Views
Ricardo_RauppV
Contributor I

CrasyCat

I´m in troubles again...

Although I included the h file into my app file (this solved my problem earlier) it is not working now...

What do you mean by :

- module defined x previously declaration?

- would be a external declaration just as:

external str_a_t  str_a;//  in another cpp file (i.e. main.cpp)?

Thanks

 

 

0 Kudos

897 Views
CarlFST60L
Senior Contributor II

To solve the 'defined previously' you have to define the same segment in the header file i.e. if you use MY_SECTION in the c file, use MY SECTION in the header file.

0 Kudos

897 Views
Ricardo_RauppV
Contributor I

CarlFST60L

In fact the "defined previously" error was solved by adding the segment specification in the h file, as you suggested.

Very thanks for your help.

 

Ricardo Raupp

0 Kudos

897 Views
CrasyCat
Specialist III

Hello

Are you using CodeWarrior compiler?

Normally you just have to define your constant as constants using const keyword.

Example:

const int version= 0x34;

Be careful, if you want to define a constant table of pointer to int, you have to define it as

  int *const       tab2[] = {0x01, 0x02, 0x03, 0x04};

I hope this helps.

CrasyCat

0 Kudos

897 Views
Andrew
Contributor I
Yes,
I'm using CW 5.0. I've defined my variables as follow:
 
const unsigned int step[16]={1,1,1,1,1,1,1,3,5,9,11,16,20,29,45,60};
 
I've set the "-Cc" option but it doesn't still work!
 
Otherwise,
if I write:
 
const Struct_a MikeyMouse = {1,2.3}
 
MikeyMouse goes to ROM!
 
What's happen?
 

 
0 Kudos

897 Views
CrasyCat
Specialist III

Hello

Hum.

canst unsigned into step[16]={1,1,1,1,1,1,1,3,5,9,11,16,20,29,45,60}; should go to ROAM.

Do you have a pragma DATA_SEG in front of it?

an you try to add #pragma DATA_SEG DEFAULT prior to constant definition.

Is it working better?

-cc will not help as it is ignore in ELF DWARF file format. It is a legacy option for an older release of the tools.

CrasyCat

0 Kudos

897 Views
Andrew
Contributor I
Well,
I'm sorry but I was wrong. I was looking for an incorrect pattern of value: the data are interger so the correct pattern was 0001, 0001, ...... while I was looking for 01,01,...
Is not necessary use the option "-Cc" nor use #pragma directive: is it sufficient use the "const" modifier.
Thanks
Added p/n to subject.
Message Edited by NLFSJ on 2009-08-11 09:42 AM
0 Kudos