how to allocate and declare const string messages

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

how to allocate and declare const string messages

17,871 Views
admin
Specialist II

i need help,

i'm working on a project using microcontroler freescale MC9S12DT512  S12X familly

 

i need to put into the PAGE FE a big table of messages.

so inside my project i declare my table like it :

 

#pragma CONST_SEG   MYCONSTANTS 

 

#define mess_1_FRANCAIS   "HELLO WORLD"

#define mess_1_FRANCAIS   "I NEED HELP"

#define mess_1_FRANCAIS   "FOR MY PROGRAMM"

#define mess_1_FRANCAIS   "THANK YOU"

 

 char* __far const texte_menu_FRANCAIS[] = {
 
    mess_1_FRANCAIS,
    mess_2_FRANCAIS,
    mess_3_FRANCAIS,
    mess_4_FRANCAIS

}

 

#pragma CONST_SEG DEFAULT

 

So my constant table of messages was created and i put it inside a segment named MYCONSTANTS 

then i allocate this segment into the PAGE FE,

to do it i modify the PRM file of my project lije it :

 

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
    _PRESTART,
    STARTUP,
    ROM_VAR,
    NON_BANKED,
    COPY                               INTO    ROM_C000;
    DEFAULT_ROM             INTO    PAGE_E0, PAGE_E1, PAGE_E2, PAGE_E3, PAGE_E4, PAGE_E5, PAGE_E6, PAGE_E7,
                                                          PAGE_E8, PAGE_E9, PAGE_EA, PAGE_EB, PAGE_EC, PAGE_ED, PAGE_EE, PAGE_EF,
                                                          PAGE_F0, PAGE_F1, PAGE_F2, PAGE_F3, PAGE_F4, PAGE_F5, PAGE_F6, PAGE_F7,
                                                          PAGE_F8, PAGE_F9, PAGE_FA, PAGE_FB, PAGE_FC ;
    DEFAULT_RAM              INTO   RAM;
    DEFAULT_EEPROM      INTO   EEPROM1, EEPROM2;
    
    MYCONSTANTS, STRINGS        INTO PAGE_FE;
END

 

now, after compilation i obtain this in the MAP FILE :

 

- VARIABLES:
     STRING..20                                            FE89E1       1       1             2   .rodata1   
     STRING.NG120.FRANCAIS.21           FE89E2       F      15             2   .rodata1   
     STRING.V2.19.22                                 FE89F1       6       6              2   .rodata1   
     STRING.NIVEAU.23                              FE89F7       7       7              2   .rodata1   

     texte_menu_FRANCAIS                     FE8010     88E    2190       2   MYCONSTANTS

 

so we can see the const messages was inside the PAGE FE.

 

now i run my project with a debugger and i scope the  texte_menu_FRANCAIS  :

but when i expand my table texte_menu_français i can see the adress of each message

message 1 located at  0x7F89E1

message 2 located at  0x7F89E2

message 3 located at  0x7F89F1

message 4 located at  0x7F89F7

 

SO LOOK the begining of the address is not correct i obtain 0x7F for all messages instead of 0xFE

normally i must have oxFE because my map file indicate that messages are in the page FE.

 

SO i don't understand ????

 

to finish i have a function to access to messages with a classical pointer like it :

 

uint8 Find_String(uint8 lign, uint16 mes)
{
  uint8 txt,curseur;

  const char* __far ptr;

 


     ptr = texte_menu_FRANCAIS[mes];
      
     txt = 1;
    while(txt)        

   {
         txt = *ptr++;

  } 

 

so with my pointer i try to access to each letter of my messages but it doesn't work.

 

please could someone, an expert can help me i don't know what can i do now, i'm working on this proble since 3 days ..

 

fabrice

Labels (1)
Tags (1)
0 Kudos
Reply
8 Replies

17,309 Views
kef
Specialist I

fab48,

 

MC9S12DT512  is not from S12X family, though your PRM looks like you are working with MC9S12XDT512, not with MC9S12DT512.

 

You should not place default STRINGS into banked segment (PAGE_FE), unless you are using large memory model. Else other non far strings won't be accessible properly.

 

char* __far const texte_menu_FRANCAIS[]  is an array of const far pointers to non-far strings. Array of pointers is usually small and could be non-far for better size and speed performance. I guess you need either far or non-far array of pointers to far strings:

const char __far * __far const texte_menu_FRANCAIS[];

 

But the problem is how to initialize this array with far strings. I don't know how to tell compiler to allocate "HELLO WORLD" initializer in non default STRINGS segment. You could replace defines with far strings

 

#pragma CONST_SEG __FAR_SEG MYCONSTANTS

const __far char mess_1_FRANCAIS[]   "HELLO WORLD"; // now string should be allocated in MECONSTANTS

 

If you have up to 16k of strings, then why don't you allocate them in nonbanked segment 4000-7fff ? It would be much faster to access such strings.

0 Kudos
Reply

17,309 Views
admin
Specialist II

it's a mistake my processor is a X? LIKE S12X

 

currently i try to migrate my project from

MC9S12XDG128

TO

MC9S12XDT512

 

now i have more memory i can put all languages in the same software.

 

JUST A QUESTION :

when i add the modifier FAR to my segment (see my first post) like crazycat said me :

#pragma CONST_SEG FAR MYCONSTANTS

 

the software work but the compiler cry me a warning :


Warning : C3803: Illegal segment attribute FAR supported for CODE segments only. Use DPAGE/EPAGE/GPAGE/RPAGE/PPAGE for DATA/CONST/STRING
segments

 

the memory model of my project is banked;

what i must do ?

I HAVE READ THE DOCUMENT ABOUT IT on freescale knowledge base but it's not very clear for me

if someone can tell me what to do witha  little explanation

thank

 

fabrice

0 Kudos
Reply

17,309 Views
kef
Specialist I

#pragma CONST_SEG __GPAGE_SEG MYCONSTANTS

 

You should restore placement of defaultt near strings to ROM_C000 or to ROM_4000.

 

    STRINGS INTO ROM_C000;

    MYCONSTANTS       INTO PAGE_FE;
 

Then:

 

#pragma CONST_SEG __GPAGE_SEG MYCONSTANTS

 

static const char __far mess_1_FRANCAIS[]=   "HELLO WORLD";
static const char __far mess_2_FRANCAIS[]=   "I NEED HELP";
static const char __far mess_3_FRANCAIS[]=   "FOR MY PROGRAMM";
static const char __far mess_4_FRANCAIS[]=   "THANK YOU";

 

const char __far * const __far texte_menu_FRANCAIS[] = {
    mess_1_FRANCAIS,
    mess_2_FRANCAIS,
    mess_3_FRANCAIS,
    mess_4_FRANCAIS
};

 

#pragma CONST_SEG DEFAULT

 

To optimize access times you can move quite small texte_menu_FRANCAIS to nonbanked ROM, kepping tons of strings in MYCONSTANTS segment:

 

#pragma CONST_SEG __GPAGE_SEG MYCONSTANTS

 

static const char __far mess_1_FRANCAIS[]=   "HELLO WORLD";
static const char __far mess_2_FRANCAIS[]=   "I NEED HELP";
static const char __far mess_3_FRANCAIS[]=   "FOR MY PROGRAMM";
static const char __far mess_4_FRANCAIS[]=   "THANK YOU";

 

#pragma CONST_SEG DEFAULT

 

const char * const __far texte_menu_FRANCAIS[] = {  // strings in MYCONSTSEG,

                                                                                        // but texte_menu_FRANCAIS in near seg
    mess_1_FRANCAIS,
    mess_2_FRANCAIS,
    mess_3_FRANCAIS,
    mess_4_FRANCAIS
};

 

Or even better allocate MYCONSTSEG in ROM_4000 and use fast and small nonbanked data accesses.

 

0 Kudos
Reply

17,309 Views
kef
Specialist I

Please disregard suggestion to give each far string the name. I forgot about STRING_SEG.

 

#pragma CONST_SEG __GPAGE_SEG MYCONSTANTS

#pragma STRING_SEG __GPAGE_SEG MYCONSTANTS

  

#define mess_1_FRANCAIS   "HELLO WORLD"
#define mess_2_FRANCAIS   "I NEED HELP"
#define mess_3_FRANCAIS   "FOR MY PROGRAMM"
#define mess_4_FRANCAIS   "THANK YOU"

 

const char __far * const __far texte_menu_FRANCAIS[] = {
    mess_1_FRANCAIS,
    mess_2_FRANCAIS,
    mess_3_FRANCAIS,
    mess_4_FRANCAIS
};

 

#pragma STRING_SEG DEFAULT

#pragma CONST_SEG DEFAULT

0 Kudos
Reply

17,309 Views
admin
Specialist II

Kef, 

thank you for your help and the time you spend to help me.

can i ask you an other thing :

 

you seems to know very well all this near far gpage an relocatable problems,

i came from MICROCHIP world my society decide to work with frescale micro, as i said it's von-neuman architecture to compare with harvard of microchip, it's the reason why i'm so embarassed.

did you know where i can find a very good description with all keyword of this, like an application note for example or a tuturial or some other document well explained because the datasheet i have are difficult to understand.

 

perhaps you have a link for example ?

for me asking help for you is a good solution because what you said is right and works on my proket but i can't ask you each time i would like to know by mysefls if i can so if you know whre i can have information about all this banked unbanked, memrory model, far near etccc.

it will be better and necessary for me to study this.

 

once more KEF i don't know who you are and where you come from (probaly AMERICA) but receive my best thnk's for the help and the time you give me.

 

fabrice (from FRANCE)

0 Kudos
Reply

17,309 Views
kef
Specialist I

I don't know book to recommend. 

 

CPU12X reference manual is important reading. You should read at least everything about available addressing modes (Chapter 3). Further, Appendix A Instruction Reference or Chapter 5 Instruction Glossary may tell you which addressing takes less code space and which takes less CPU cycless (see Access Deails - more letters means more CPU cycles).

http://cache.freescale.com/files/microcontrollers/doc/ref_manual/S12XCPUV2.pdf

 

You need of course to understand memory map of particular MCU.

The rest can be found in CW online help or in <CW install folder>\Help\PDF (which are more recent then CW help) and in <CW install folder>\Release Notes.

 

0 Kudos
Reply

17,309 Views
CrasyCat
Specialist III

Hello

 

The problem lies with definition of the table texte_menu_FRANCAIS. You need to inform the compiler that the table is allocated in a banked memory area.

You need to change your pragma as

 

#pragma CONST_SEG  FAR MYCONSTANTS

 

address for texte_menu_FRANCAIS[0] shown 0x7F89E1, which is the global address encoding for logical address 0xFE89E1.

 

So your addresses are all correct.

 

CrasyCat

0 Kudos
Reply

17,309 Views
admin
Specialist II

it's WONDERFULL

 

MR CRAZYCAT you can't imagine the power of the help you just give me

i don't know how to tell you how i'm happy of your very necessary help

 

without you i probably don't find the solution

 

crazycat, receive my best thank's from a french programmer who lost a lot of hair with this problem.

 

crazy cat you are a god, guru of code.

 

fabrice

0 Kudos
Reply