I have written a LIB with the following decleration:
idata u_char clock_occ; idata void (*f_ce)(u_char stat); I use it in the LIB in the way as: clock_occ = 1; f_ce(TRUE); so far, no problem, I compile it -> ok: I add the LIB to my project and use it like: extern idata u_char clock_occ; extern idata void (*f_ce)(u_char stat); void SetChipEnable (u_char stat) { ... } void main (void) { clock_occ=0; f_ce = (void *)SetChipEnable; }
Do the warnings refer to "f_ce" or to "_f_ce"? Is "_f_ce" in your linker list file of your library? P.S. It is better to declare:
extern idata void (code*f_ce)(u_char stat);
Thanks, the "code" doesn't change the message, but your are right I have use that. I get the message "_F_CE" unre.... The linkerlist of the LIB is: _f_ce. . . . . . . . . . . . . . . PUBLIC IDATA PTR 0000H 2 ... uhr_occ. . . . . . . . . . . . . . . . PUBLIC IDATA U_CHAR 0002H 1 wbr Norbert
I do not see the error, but maybe you want to take a different approach. Right now, even if you could get your code to link, you would still need to add an overlay directive. To create the overlay directive properly, you would need to know which library functions used this call back pointer. This defeats the implementation encapsulation that you were probably trying to achieve by using a library. My suggestion is to use:
//in library extern void f_ce(u_char stat); //in calling code void f_ce(u_char stat) { .... //use function pointers here if dynamic call backs are needed }
Thanks. I have made this solution: In my "lib"
defTyp idata void (code*f_ce_on)(); defTyp idata void (code*f_ce_off)(); void InitClockLib (u_char *p_ce_on, u_char *p_ce_off) { f_ce_on = p_ce_on; f_ce_off = p_ce_off; }
MCO = 1; f_ce_on();
void SetChipEnableOn (void) { P2 = 0xFF; } void SetChipEnableOff (void) { P2 = 0; }
InitClockLib ( (u_char*) &SetChipEnableOn, (u_char*) &SetChipEnableOff);
Read ! (SetChipEnableOn, SetUhrChipEnableOff), Write ! (SetChipEnableOn, SetUhrChipEnableOff)