__far and s12 global address

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

__far and s12 global address

1,053 Views
zff
Contributor II

Dear NXPers,

I create a project on MC9S12G** with BANKED model.

There is a structual type variable  EMS_infoMapS, its address in page is 0x8000, global address is 0x04000, logic address is ox18000(page=1).The following picture is S12 memory map.

memory map.PNG

The following code is about the address of EMS_infoMapS,

#pragma CONST_SEG DEFAULT
extern EMS_CTRLMAP_TYPE * __far EMS_infoMapSP; 

#pragma CONST_SEG MAP1_ROM
volatile const EMS_CTRLMAP_TYPE EMS_infoMapS=
{

...

}

PLACEMENT

...

MAP1_ROM 
INTO PAGE_01;

...

END

And .map file show address allocation results.

MODULE: -- Map.c.o --
- PROCEDURES:
- VARIABLES:
EMS_infoMapSP 1674 3 3 47 .data
EMS_infoMapS 18000 2EA4 11940 2 MAP1_ROM

Then, I do the following operation,

void ADC_GetAnagValue1(void)
{
DisableInterrupts;
ADC_tClntUW = IntpoCur_u16((uint16 * __far) &ADC_tClntUW_CUR,ADC_tClntRsUW);
EnableInterrupts;
}

const uint16 *__far MAPAddr_u16;

uint16 IntpoCur_u16(const uint16 * __far MAPAddr,uint16 X)
{

MAPAddr_u16_reverse = MAPAddr;

...

}

I debug, and find MAPAddr is wrong.

地址错误.PNG

I dont konw why MAPAddr is but 0x801200 not 0x401200, it is a wrong result.

How can i get ADC_tClntUW_CUR's true global address?

Looking forward to your reply.

Thanks.

Labels (1)
5 Replies

942 Views
zff
Contributor II

I had the same problem with operating system migration.Once the program starts manipulating the BANKED page data, the address is wrong, causing the program to runaway!

So, it is a critical problem for me, which has being stalled me.

0 Kudos

942 Views
kef2
Senior Contributor IV

1. First of all which how big flash is in your device? PPAGE=1 is available only on 256k device. On 128k device the least PPAGE is 8, G64 - 0xC and so on

2

#pragma CONST_SEG MAP1_ROM
volatile const EMS_CTRLMAP_TYPE EMS_infoMapS=
{

...

}

Allocating data outside of CPU native 64k address space, you need to tell compiler how that data should be accessed, you need to specify either __FAR_SEG or __PPAGE_SEG

#pragma CONST_SEG __FAR_SEG MAP1_ROM

__FAR_SEG will probably trigger C3803 warning, but it is OK. __PPAGE_SEG will limit your data usage from nonbanked functions only.

3. It is not clear how Mapaddr or ADC is related to EMS_InfoMap

4.

  • I had the same problem with operating system migration.Once the program starts manipulating the BANKED page data, the address is wrong, causing the program to runaway!

What do you mean here? How you can manipulate const data in paged memory? Are you reprogramming it? Do you mean manipulating PPAGE register directly? Well, you can't do it while executing paged routine.

942 Views
zff
Contributor II

Dear Karpicz,

Thanks for your technical support. As for your questions, the following is my answers.

1. The size of Flash of my device is 240kB, I am sure it support PPAGE=0x01~0x0F.

2. I read AN3784 Understanding the Memory Scheme in the S12(X) Architecture yesterday the first time, I find I know too little about keywords __far and  __RPAGE_SEG/ __EPAGE_SEG/ __PPAGE_SEG/ __GPAGE_SEG. Your suggstion '#pragma CONST_SEG __FAR_SEG MAP1_ROM' is totally right. I am sorry I make such a low-end mistake and cost you a lot of time.

3. ADC map is s part of EMS_InfoMap, and they are in the same page. EMS_InfoMap is at 0x004000(global address), ADC map is at 0x004012(global address). They are related by pointer. I think the detail for this answer is not important now, because part2 is the most important.

4. I give you a too ambiguous https://community.nxp.com/?keyword=description about operating system migration, making you too confused.This question is far more complex, I feel difficult to describe it clearly now. After solving other problems, I'll come back to the issue of OS transplantation. If I still can't transplant effectively, I'll describe my question more clearly.

I'll try your approach, and if there's any further confusion, I'll keep asking questions below this post.

Thank you very much for your help.

Today is Mother's Day. I wish your mother good health and your family happiness(Chinese style blessing).

0 Kudos

942 Views
kef2
Senior Contributor IV

Hi,

2. Actually you have two ways to tell compiler your data has special, not 16bit address. Keyword like __far in data declaration or round your declaration with proper pragmas. If your data is shared among C files, you need to use the same __far or pragmas in header file so that compiler sees your data declared the same in all C files.

  • Today is Mother's Day. I wish your mother good health and your family happiness(Chinese style blessing).

Thanks, but Mother's Day was actually week ago in my country.

Regards,

Edward

943 Views
zff
Contributor II

Thanks for your suggetions.

I'm trying the solutions you provide. If I make critical progress, I will tell you.

Best regards,

FU

0 Kudos