请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号: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; }