To solve the far function pointer issue I have developed a set of macros
shown below:

/*
 * far.h by Robert Kavaler 1/31/2010
 *
 * The MSPGCC MSP430X compiler currently does not handle pointers to
functions
 * correctly. The compiler treats all pointers as 16 bits, but pointers
 * to functions should be 20 bits. As a workaround to handle pointers to
 * functions, a set of wrapper macros was developed.
 * The macro _FAR is merely shorthand for the far attribute.
 * The macro _FARDEF(t, x, p) creates a wrapper function
 * x_inlowmem for the function x. It also acts as the formal declaration of
 * the actual function. t is the type and p a list of parameter for
 * the C declaration of the wrapper function. The wrapper function itself
 * is merely a branch to the actual function. The wrapper function always
 * lives in the lower 64K address space so it can be accessed/referenced
with
 * a 16 bit pointer.
 * The macro _FARREF(x) is used to reference the wrapped
 * function in C. It is basically the 16 bit address reference of the
 * branch instruction that branches to the 20 bit function x.
 * The macro _FARDEFH(t, x, p) creates a definition for
 * both the far function and the wrapper function for use in header files.
 * Example:
 *      _FARDEFH(void, complicatedStuff, (char *s, int *y));
 *      _FARDEF(void, complicatedStuff, (char *s, int *y)) { function code }
 *      void (*func)(char *, int *y) = _FARREF(complicatedStuff);
 */

#ifdef MSP430X5

#define _FAR                    __attribute__ ((far))
#define _FARREF(x)              x ## _inlowmem
#define _FARDEF(t, x, p)        t x ## _inlowmem p; \
                                asm("   .text\n" #x "_inlowmem: bra     #"
#x\
                                       
"\n\t.section\t.fartext,\"ax\",@progbit\
s");\
                                _FAR t x p
#define _FARDEFH(t, x, p)       _FAR t x p; t x ## _inlowmem p

#else

#define _FAR
#define _FARREF(x)              x
#define _FARDEF(t, x, p)        t x p
#define _FARDEFH(t, x, p)       t x p

#endif

-- 
View this message in context: 
http://old.nabble.com/MSP430X-with-MSPGCC-and-MSP430F543XA-tp30405079p30422419.html
Sent from the MSP430 gcc - Users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to