IAR平台FreeOS移植接口函数处理--weak属性用法

来源:互联网 发布:淘宝打包员是蹲着做吗 编辑:程序博客网 时间:2024/05/19 14:51

进行FreeOS移植的时候会遇到函数定向问题


在文件FreeRTOSConfig.h中定义如下,就不用更改system_stm32f4xx.c里面的中断函数名,

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSISstandard names. */#define vPortSVCHandler SVC_Handler#define xPortPendSVHandler PendSV_Handler#define xPortSysTickHandler SysTick_Handler

但存在两个函数定义,编译会出问题,这个时候就需要做相应的处理,可以注释掉
SVC_Handler 
PendSV_Handler
SysTick_Handler

几个函数,但可能在ST标准库里其他地方会用到这几个函数,下面提供了一个新的方法可以借鉴,在函数前加上 --weak 修饰,编译就不会报错

__weak void SVC_Handler(void){}/**  * @brief  This function handles Debug Monitor exception.  * @param  None  * @retval None  */void DebugMon_Handler(void){}/**  * @brief  This function handles PendSVC exception.  * @param  None  * @retval None  */__weak  void PendSV_Handler(void){}/**  * @brief  This function handles SysTick Handler.  * @param  None  * @retval None  */__weak void SysTick_Handler(void){}


/*gcc reference里提到:


A function with this attribute has its name emitted as a weak
symbol instead of a global name. This is primarily for the naming
of library routines that can be overridden by user code.

weak symbol

Having two or more global symbols of the same name will not cause a conflict as long as all but one of them are declared as being weak symbols. The linker ignores the definitions of the weak symbols and uses the normal global symbol definition to resolve all references, but the weak symbols will be used if the normal global symbol is not available. A weak symbol can be used to name functions and data that can be overridden by user code. A weak symbol is also referred to as a weak alias, or simply weak.


通过上面的例子(FreeOS9.0里面的IAR Demo程序),weak的作用可见一斑。

*/

0 0