S12X to XGATE address translation?

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

S12X to XGATE address translation?

6,157 Views
pittbull
Contributor III
Hi all,
I need to share some buffers between the S12X and the XGATE cores. Therefore, the S12X puts the address into a pointer. The XGATE reads the right (same) value from the pointer but that points to a different location than I expected. Can anyone tell me how to translate XGATE to S12X addresses and vice versa?

Thanks in advance,
pittbull
Labels (1)
0 Kudos
6 Replies

640 Views
Steve
NXP Employee
NXP Employee
If you are using CodeWarrior there is an application that does the calculation for you: hcs12xadrmap.exe. That is mostly useful for debugging purposes.
 
The easiest solution is to define the shared buffers at compile time and then allow both cores to use the buffer symbolically. The toolchain will automatically configure code to access the correct address.
For example on the CPU:
unsigned char buffer[20];
 
and on the XGATE:
extern unsigned char buffer[20];
 
Now both cores can access the data as buffer[index] and there is no need to translate pointers.
 
If you really have to pass dynamic pointers then you will have to translate the pointer value. If you are using internal RAM then it is simplest to use a global addressing (far) pointer because the lower 16bits of the address match the XGATE RAM address. For example global RAM at 0x0FC123 is XGATE address 0xC123.
0 Kudos

640 Views
pittbull
Contributor III
Hello Steve, thanks for your reply.

I tried to use __far* this way:

S12X
----
char mychar;
char *__far mypointer;
mychar = '0';
mypointer = &mychar

XGATE
-----
extern char *__far mypointer;
*mypointer ='X';

...but that didn't work. The XGATE wrote the 'X' somewhere in memory and mychar did not change. Also the compiler gave me a warning that mypointer has different sizes (3 bytes in S12X code and 2 bytes in XGATE code).

Now I use another approach:

S12X
----
char mychar;
unsigned long mypointer;
mychar = '0';
mypointer = (unsigned long)(void *__far)&mychar

XGATE
-----
extern unsigned long mypointer;
char *p = (char*)mypointer;
*p = 'X';

This works .... but it looks like an ugly workaround.
Can you tell me what's wrong with __far pointers? I think the XGATE compiler can not handle them because of the limited XGATE address range (64K).
0 Kudos

640 Views
Steve
NXP Employee
NXP Employee

Yes, that's right. Far pointers have no meaning for XGATE and though the code looks a bit ugly it's probably very efficient at assembly level.

If you can define the buffer in advance then there is no need to pass the pointer though and that's still the best solution. Alternatively, can you pass the pointer once and then use offsets to access the data after that?

0 Kudos

640 Views
pittbull
Contributor III
>>If you can define the buffer in advance then there is no need to pass
>>the pointer though and that's still the best solution. Alternatively,
>>can you pass the pointer once and then use offsets to access the data
>>after that?

No, I can't. It is a file system driver which manages a small buffer pool. When it delivers a buffer to the XGATE for reading/writing, it selects a new one for use by the application. Thus, both cores can run simultaeously most of the time without having to wait for each other. With the use of the XGATE, the driver runs 2.5 times faster the before!

Thanks again, you helped a lot !

Message Edited by pittbull on 02-21-200611:12 AM

0 Kudos

640 Views
Steve
NXP Employee
NXP Employee
Thanks for explaining the background - it's always good to know. :smileyhappy:
Glad you're seeing such an improvement.
0 Kudos

640 Views
pittbull
Contributor III
Hello again,

I coded some macros to make pointer sharing easier between XGATE and S12X.

---------------- cut here -------------------------
#define XGATE_SHARED_POINTER unsigned long
#define XGATE_SHARED_POINTER_INITIALIZE(value) (unsigned long)(void*__far)(value)
#ifdef __XGATE__
#define XGATE_SHARED_POINTER_ACCESS(type,pointer) ((type*)(pointer))
#else
#define XGATE_SHARED_POINTER_ACCESS(type,pointer) ((type*__far)(pointer))
#endif
---------------- cut here -------------------------

Use them as following:

// Two variables and a shared pointer
int x = 1234;
int y = 5678;
XGATE_SHARED_POINTER mypointer;
// Let it point to x
mypointer = XGATE_SHARED_POINTER_INITIALIZE(&x);
// Get the value of x and put into y either from XGATE or S12X
y = *XGATE_SHARED_POINTER_ACCESS(int, mypointer);

I hope this helps others who have a similar problem like me. Maybe the next hidef.h contains something like this.
0 Kudos