i have a simple scheduler on the xgate, and an a simple 'instruction queue' which is filled via the isr. whenever a new 'command' from the s12x is issued, an xgate isr is called which copies the buffer into an queue. in addition, every 10ms an xgate isr is called (the simple scheduler) which looksup the queue and performs the commands. everything works as intended except the adress translation. '&function' gives the right logical adress of my xgate function, but i'd need the xgate adress. is there an easy way to share function pointers? i could construct the right xgate adress from the logical adress, but that would be somewhat messy in the code. i hope you understand what i mean
here the (non-functional) code:
Code:
typedef void (* fkt_ptr_char)(char);struct xgate_shared_data { fkt_ptr_char fkt; unsigned char data;};//XGATE function prototypesinterrupt void Copy_Command(int value); //copies command into an queueinterrupt void PIT1(int value); //runs queued commands, every 10msvoid CallMe(char value); //the function to be called//S12X function prototypesbool issue_XGATE_command(fkt_ptr_char fkt, char data); //calls Copy_Command, fkt_ptr is correct logical adress, but not xgate adress//call somewhere in the s12x codeissue_XGATE_command( &__X_CallMe, 0x1);
Message Edited by benni on 2007-02-1212:56 PM
Message Edited by benni on 2007-02-1212:56 PM
void CallMe(char value); //the function to be called
//call somewhere in the s12x codeissue_XGATE_command( &__X_CallMe, 0x1);
...the function 'CallMe' is at XGATE adress E000, Global FE000 and Logical FE1000
...didnt help either, it always used adress FE1000. maybe im not getting how to use far at all...
Note that CallMe is in RAM and "logical" FE1000 is RPAGE based address! You could translate it to XGATE address but better try to avoid passing pointers between cores.
Hi kef, thanks for your reply!
kef wrote:In you first message you wrote that you have CallMe XGATE funcionCode:void CallMe(char value); //the function to be called
butCode://call somewhere in the s12x codeissue_XGATE_command( &__X_CallMe, 0x1);
Why are you referencing different function? Please don't cheat
//call somewhere in the s12x codeissue_XGATE_command( &CallMe, 0x1);
kef wrote:BTW, you wrote:...the function 'CallMe' is at XGATE adress E000, Global FE000 and Logical FE1000and later:...didnt help either, it always used adress FE1000. maybe im not getting how to use far at all...
Note that CallMe is in RAM and "logical" FE1000 is RPAGE based address! You could translate it to XGATE address but better try to avoid passing pointers between cores.
Yes i know. I could do it 'by hand' as the Logical Mapping for the XGATE is fixed, but as Steve explained, converting a gloabal adress to XGATE adress is much simpler. So i'd prefer that, as it would assure more readable code. But i can't get the global adress of the function, only the logical one .
I sure could do all the funktion calling stuff on the xgate via table lookup, but that would mean i'd have to assure consistency in various places, the table, the command (which would be the table index) and still would need a data pointer for the argument list. So giving a function pointer makes all this much simpler, you'd never have to worry about too big tables or an too small index-datatype.
The concept of function pointer passing is working pretty well, the code is slim and the space you need is constant instead of linear increasing, like in the table based approach. integration of a new XGATE function is only the function itself and the call of issue_XGATE_command();, no new command (index) is needed and no table entry. i like that
And it does work as intended, only the way i'm translating the function pointers is somwhat ugly.
header.h #include #ifdef __XGATE__ typedef void (*XGATEFunPtr)(void); #elif defined(__HC12__) typedef int XGATEFunPtr; // just using any 16 bit type for the HCS12X side #else #error.... #endif extern const XGATEFunPtr g_HaveFun; hc12.c: #include "header.h" ....= g_HaveFun; xgate.cxgate: #include "header.h" void funny_xgate(void) { } const XGATEFunPtr g_HaveFun= funny_xgate;
Hey Steve,
thanks for your reply.
I thought of an table approach too, but that would mean to keep the table up to date, and maintain some sort of enumerated index for the command for the right call, so i think the function call would be a much cleaner design.
For the global adress...well i must admit that i just cant get it. the far seems just to be ignored.
the function 'CallMe' is at XGATE adress E000, Global FE000 and Logical FE1000 (because its the only funktion in this section so far).
i declared the function as:
extern void __X_CallMe(char);
__X_CallMe to bool issue_XGATE_command(fkt_ptr_char fkt, char data);
typedef void (* fkt_ptr_char)(char); intotypedef void (* far fkt_ptr_char)(char); but no luck
extern void far __X_CallMe(char);
Message Edited by benni on 2007-02-1205:13 PM
Alban changed for code not to look ugly , press "SRC" button in editor
Message Edited by Alban on 2007-02-12 05:20 PM