3.5 __farfunc Keyword
The IAR __farfunc
keyword places the qualified function within program memory,
and when used with the definition of a function pointer, the pointer is made 24 bits
wide so that it can access functions anywhere in the range 0x0-FFFFFF.
Suggested Replacement
The keyword can be removed.
When using MPLAB XC8, the -mrelax
option automatically handles
placement and indirect calls for functions located anywhere in program memory.
Function pointers are always 16-bit wide, but on devices with more than 128 KB of
program memory, they point into a trampoline table placed in near flash. The
trampoline table entries then jump to the actual function using a
jmp
instruction.
Caveats
int main(void)
{
((int(*)(void)) 0x20000)(); /* will not work */
}
might
fail. Instead, do the
following:int main(void)
{
extern int foo(void); /* Force creation of a symbol, with address set at link time */
foo();
}
and
associate an address with the symbol using the xc8-cc
driver option
-Wl,-defsym,foo=0x40000
, for example.Examples
__farfunc void incMode(void);
to MPLAB XC8 code similar
to:void incMode(void);
Further Information
See the Function Pointers section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on how functions are handled.