This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Jump to a hardware address in 28335

Hi,

I've a big trouble in my project that i want to jump a hardware address in Flash memory of 28335 (locate wherever in Flash memory).

This is format of my function:

void jump_to_hardware_adrr(Uint32 hard_addr)

{

}

value of hard_addr will get from PC via SCI. But i can't load hard_addr to XAR7 register or another register to execute LB *XAR7.

Thank you so much for your reply.

  • Phien,

    I would just use inline assembly unless you need the hard_addr to be variable.  For example, just suppose you wanted to branch to address 0x330000 (just a dummy address for my example).  I would do this in the C code:

    asm(" LB 0x330000");

    If you must have hard_addr be a variable (i.e., determined at runtime, not at compile time), then you can do it in C using a function pointer, like this:

    void jump_to_hardware_addr(Uint32 hard_addr)
    {
        void (*p)(void);                  // Declare a local function pointer
        p = (void (*)(void))hard_addr;    // Assign the pointer address
        (*p)();                           // Call the function
    }

    Regards,

    David

  • Hi David,

    Thank you very much. I've just found a different solution for this, i tested and maybe it okay. Do you think so?

    void jump_to_hard_addr(Uint32 hard_addr)		
    {												
    	asm(" POP XAR7");							
    	asm(" LB *XAR7");							
    }

    Thanks TI.

  • Phien,

    That looks like it should work.  I didn't test of course.

    If the only thing in the function is inline assembly, you really should just code the thing up in a .asm file in the first place.  That way there is no risk of the compiler optimizer doing anything weird, and you don't waste any code space with a return instruction or other stuff the compiler puts into a function as standard.  The below is the same thing you have, except it should be put in a .asm file, for example 'jump_to_hard_addr.asm' (but you can call the file whatever you want):

    ; C Function Prototype:
    ; void jump_to_hard_addr(Uint32)
    ;
         .text
         .global _jump_to_hard_addr

    _jump_to_hard_addr:
         POP   XAR7      ;get target address
         LB    *XAR7     ;never return

     

    - David