MSP430 Function pointers
Hi,
Not sure if this is a bug or if my code is incorrect. I am using Crossworks 2.2 for MSP430.
I have bee having problems with the following code:
static void InvokeBSL(void)
{
typedef void (* functionpointer)(void);
const functionpointer bsloader = (functionpointer)0x1000;
USB_disconnect();
USB_disable();
// enter BSL
bsloader();
}
I believ that the call to bsloader should cause a call to 0x001000, but this does not seem to work.
Looking at the code in the disassembler it resolves to:
static void InvokeBSL(void)
0b12 PUSH.W R11
--- main.c -- 295 ------------------------------------------
{
typedef void (* functionpointer)(void);
const functionpointer bsloader = (functionpointer)0x1000;
3b400010 MOV.W #0x1000, R11
--- main.c -- 299 ------------------------------------------
USB_disconnect();
b013d0a4 CALLA #0x0a4d0 <_USB_disconnect>
USB_disable();
b01306a3 CALLA #0x0a306 <_USB_disable>
--- main.c -- 302 ------------------------------------------
// enter BSL
bsloader();
0f4b MOV.W R11, R15
6f13 CALLA @R15
3b41 POP.W R11
1001 RETA
The CALLA @R15 generates a call to the address specified by the contents of address 0x1000.
I have checked this in the TI CCS compiler and it generates CALLA R15, and works as I would expect.
Can anyone advise on if this is actually a bug in the compiler and provide a work around please.
Regards
Roy.
-
> Can anyone advise on if this is actually a bug in the compiler and provide a work around please.
It is not a bug. Generation for >64k of code requires pointers to be thunked (that is, the function pointer does not hold the address of the function, it holds the address of where you will find the address of the function). Doing it this way means that function pointers stay in 16 bits and can be passed through a void * without problem, or cast to an int and back again, without problem.
Please sign in to leave a comment.
Comments
1 comment