bool (* funcP)();
funcP =&ProgFlash;
CopyString((byte*)funcP, (byte *)RAM_FUNCS_START, RAM_FUNCS_SIZE);
The address to progFlash() was in this case 0x40A9. The resulting part in the .lst file looks like:
226: funcP = &ProgFlash;
002a cc0000 [2] LDD #LOW_PAGE(ProgFlash)
002d 6c8c [2] STD 12,SP
002f c600 [1] LDAB #HIGH(ProgFlash)
0031 6b8b [2] STAB 11,SP
227:
228: CopyString((byte*)funcP, (byte *)RAM_FUNCS_START, RAM_FUNCS_SIZE);
0033 ec8c [3] LDD 12,SP
0035 160000 [4] JSR WriteEeprom:0x01a2
.
01a2 3b [2] PSHD
01a3 cc3fd0 [2] LDD #16336
01a6 3b [2] PSHD
01a7 c62b [1] LDAB #43
01a9 4a000000 [7] CALL CopyString,PAGE(CopyString)
The address to the function is stored relative to SP and then loaded back to D. But since two bytes are copied from SP + 12 the address A900 will finally be stored in D and pushed as argument to the CopyString function. LDD 11,SP would have been a better choice from my point of view.
Something is wrong in the C-code when trying to convert the functionpointer to a byte pointer but i can't figure out what. Can anyone help me??
//Bengt
int fPtrSize;
Fp FunctPtr;
FunctPtr = &Foo;
fPtrSize = sizeof(FuncPtr);
You can define alternate pointers to instruct the compiler that the function pointed to returns data and/or passes data.
At least this has worked for me using Codewarrior for HCS(X)12 and Codewarrior for Coldfire.
Dennis