Problem with XGATE addressing

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

Problem with XGATE addressing

Jump to solution
1,505 Views
lowpy
Contributor I

I am trying to use XGATE to execute a section of code on XGATE in parallel with code on S12 in order to speed up the overal execution of a function on a MC9S12XDT512 micro. In doing this the XGATE and S12 code has to access a common data area and this is where I got problems.

 

I declared the common variables in the SHARED_DATA segment but depending on how I use them I encounter an error in the debuger that says: No memory at [mmmm'X:1], where mmmm is an address.

 

If I use something like this:

 

#pragma DATA_SEG SHARED_DATAvolatile unsigned long X[16];#pragma DATA_SEG DEFAULTinterrupt void SoftwareTrigger0_Handler(int dataptr) {/*do something with data in vector X.....*/}

 

 

all works just fine but if I try this for example:

 

 

#pragma DATA_SEG SHARED_DATAvolatile unsigned long X[16];volatile unsigned char *pX;#pragma DATA_SEG DEFAULTvoid S12_core_function(){  pX = &X[4];  /*generate SW trigger*/}interrupt void SoftwareTrigger0_Handler(int dataptr) {/*do something with data ad address pX.....*/}

 the debug stops and the Command windows says No memory at [mmmm'X:1], and mmmm is the address of X[4]. If I try to check the data in the X variable with the Show location option in right click menu the Memory window shows Logical addresses. If I try to see what is at the address pX is pointing at, using the same method the Memory window shows XGATE addresses where the address it is looking for is not used.

 

If someone knows what I'm doing wrong please give me at least a hint on how I could fix my code. I need to use the second method because XGATE code I'm implementing will not always start processing data from the same address and I need to control where it starts processing.

 

Thanks in advance.

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,116 Views
kef
Specialist I

You can't share pointers directly between CPU12X and XGATE. XGATE has access only to XGATE address space. What XGATE can access at 0'X-7FF'X in XGATE memory space, CPU12X can access at the same CPU addresses 0-7FF. But what XGATE sees at 800'X-7FFF'X (flash), CPU12X sees in global address space at 780800'G-787FFF'G. And RAM, that XGATE sees at 8000'X-FFFF'X, is available for CPU12X is global addresses F8000'G-FFFFF'G. As you may see, addesses and pointers are not the same for both cores. Lower 16bits of CPU12X global address is the same as XGATE address, but on CPU12X you have to specify additionally global memory page.

 

So either use array indexes, which can be easily shared between cores, or see how you can share pointers with some effort - see CodeGuru's post here

https://community.freescale.com/message/51688#51688

 

You can search forums for more. It was discussed already several times

View solution in original post

0 Kudos
Reply
7 Replies
1,117 Views
kef
Specialist I

You can't share pointers directly between CPU12X and XGATE. XGATE has access only to XGATE address space. What XGATE can access at 0'X-7FF'X in XGATE memory space, CPU12X can access at the same CPU addresses 0-7FF. But what XGATE sees at 800'X-7FFF'X (flash), CPU12X sees in global address space at 780800'G-787FFF'G. And RAM, that XGATE sees at 8000'X-FFFF'X, is available for CPU12X is global addresses F8000'G-FFFFF'G. As you may see, addesses and pointers are not the same for both cores. Lower 16bits of CPU12X global address is the same as XGATE address, but on CPU12X you have to specify additionally global memory page.

 

So either use array indexes, which can be easily shared between cores, or see how you can share pointers with some effort - see CodeGuru's post here

https://community.freescale.com/message/51688#51688

 

You can search forums for more. It was discussed already several times

0 Kudos
Reply
1,116 Views
lowpy
Contributor I

Thanks for your reply. I was very helpful. I didn't manage to get the __far pointer solution to work yet but the offset-method works.

0 Kudos
Reply
1,116 Views
lowpy
Contributor I

I ran into another problem regarding this subject. The array that I'm using both on S12X and XGATE is declared as a local variable in a S12X function so each time this function is called the array will start at a different address. My problem is caused by the alignment.

 

The code looks something like this:

void FunctionX(){   unsigned long X[16];   pX = X;   /*Software request to XGATE*/}

 where pX is a unsigned long  * declared in the common area of S12X and XGATE. When running the code in the debugger some of the xgate calls work just fine but at a point I get an exception when trying to access a certain address which is not 2 bytes aligned as XGATE needs.

 

X is always located in the RAM secion (0x2000 - 0x3FFF) declared inthe prm as 2 bytes aligned for XGATE access but for some reason sometimes it starts at an uneven address. Is there a method of forcing variable X to be aligned ?

0 Kudos
Reply
1,116 Views
kef
Specialist I

I think it is not possible to force local S12X variables on the stack to be always aligned. Instead I would replace native access to long X[]-array elemnt with 4 byte accesses. XGATE can't access misaligned words, but no problem to access bytes.

 

I hope you are waiting in FuntionX and not exit until XGATE takes all the data you pass to it. Exiting from FunctionX would destroy X[]-array.

0 Kudos
Reply
1,116 Views
lowpy
Contributor I

I will try to use your suggestion but I would still like a sollution for a full word access because accessing the data byte by byte will be slower. So any ideas are welcomed.

 

FunctionX as I wrote it here is just an example. I am also doing other things in this function and I wait for XGATE to finish because the function needs the data processed by XGATE.

0 Kudos
Reply
1,116 Views
kef
Specialist I

What about static array then? Both, file scope X and function sccope static X will be aligned, provided you didn't remove ALIGN stuf from RAM segment definition in your PRM file.

 

void FunctionX()
{
   static unsigned long X[16];

 

or

 

unsigned long X[16];
void FunctionX()
{

 

In both cases X should be aligned.

0 Kudos
Reply
1,116 Views
lowpy
Contributor I

Yes, that solved the problem. Thanks again for your help.

0 Kudos
Reply