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.

[参考译文] CC2650:将函数复制到 RAM 并使用函数指针调用它

Guru**** 1127450 points
Other Parts Discussed in Thread: CC2650
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/1336978/cc2650-copy-function-to-ram-and-call-it-with-function-pointer

器件型号:CC2650

您好!

根据 CC2650 Launchpad (Cortex M3)、我尝试将函数复制到 RAM 中、然后 使用如下所示的函数指针来调用它:

它强制系统重新启动,并且应该遇到错误。

您能帮我解决吗? 提前感谢!

uint8_t ram_func(uint8_t data_in)
{
  data_in++;
  return data_in;
}
/*---------------------------------------------------------------*/
int main() {
    typedef uint8_t (*func_ptr)(uint8_t);
    uint8_t func_buffer[256];
    memset(func_buffer, 0, 256);
    // Copy the machine code of func into func_buffer
    memcpy(&func_buffer, (uint8_t*)ram_func, 255);

    // Create a function pointer and cast the buffer address to it
    func_ptr fp = (func_ptr)func_buffer;

    // Call the function through the function pointer
    uint8_t data_out = fp(3);

    printf("Result = %d\n", data_out);
    return 0;
}