我正在开发 MCU(STM32F4)。在当前系统中,所有的中断处理程序都在链接文件中声明为弱符号,如果我们想使用一个,我们只需在 C 中声明一个同名的函数,并在链接时替换弱符号。
我正在尝试将我的系统转换为 C++,我设想一个系统,其中实例化某种中断类型将在模块中声明相应的 C 函数。
考虑到成员函数禁止使用 extern "C",我不知道如何实现这一点。
任何想法或替代方案?我的目标是尝试静态检查一些东西并尝试在该领域使用一些现代 C++。
这是C中的当前情况。我有一个包含这个东西的程序集文件:
g_pfnVectors:
.word _estack
.word Reset_Handler
(...)
.word SysTick_Handler
(...)
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
(...)
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
在我的 C 代码中,我有:
main() {
(...)
SysTick_Config(SystemCoreClock / cncMemory.parameters.clockFrequency);
while (1);
}
void SysTick_Handler(void) {
cncMemory.tick++;
}
我设想这样的事情:
int main() {
MCU<mySystickHandler, ...> mcu;
mcu.start();
}
static void mySystickHandler(void) {
cncMemory.tick++;
}
或接近的东西(可能没有仍然全局功能,但我尝试将问题分开)。