文件系统的void SysTick_Handler(void) { g_timeMilliseconds++; } 和freertos里port.c的void xPortSysTickHandler( void ) { /* The SysTick runs at the lowest interrupt priority, so when this interrupt executes all interrupts must be unmasked. There is therefore no need to save and then restore the interrupt mask value as its value is already known - therefore the slightly faster vPortRaiseBASEPRI() function is used in place of portSET_INTERRUPT_MASK_FROM_ISR(). / //g_timeMilliseconds++; vPortRaiseBASEPRI(); { / Increment the RTOS tick. / if( xTaskIncrementTick() != pdFALSE ) { / A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; } } vPortClearBASEPRIFromISR(); }重复定义了怎么解决,给我具体的解决方法带代码
时间: 2024-03-11 09:48:43 浏览: 119
I2C.zip_LPC1114_SysTick_Delay.h_lpc1114 i2c
如果您遇到了重复定义的问题,可以使用如下方法解决:
1. 将 `g_timeMilliseconds` 定义为一个全局变量,然后在两个函数中都使用它,而不是在 `SysTick_Handler` 函数中直接对它进行操作。
例如,您可以在某个头文件中定义 `g_timeMilliseconds`:
```c
// 在头文件中定义全局变量
extern uint32_t g_timeMilliseconds;
```
然后在一个 C 文件中定义这个全局变量:
```c
#include "header.h"
uint32_t g_timeMilliseconds = 0;
```
然后在 `SysTick_Handler` 函数中,将其修改为:
```c
void SysTick_Handler(void) {
g_timeMilliseconds++;
}
```
在 `xPortSysTickHandler` 函数中,您可以通过 `g_timeMilliseconds` 全局变量来获取当前时间的值,而不需要在该函数中对其进行操作。例如:
```c
void xPortSysTickHandler( void ) {
/* Increment the RTOS tick. */
if( xTaskIncrementTick() != pdFALSE ) {
/* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
}
}
```
2. 如果您仍然想要在 `xPortSysTickHandler` 函数中对时间进行操作,您可以将其代码合并到 `SysTick_Handler` 函数中,而不需要在 `xPortSysTickHandler` 函数中重新定义。例如:
```c
void SysTick_Handler(void) {
g_timeMilliseconds++;
/* Increment the RTOS tick. */
if( xTaskIncrementTick() != pdFALSE ) {
/* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
}
}
```
然后在 `xPortSysTickHandler` 函数中,您可以删除对 `g_timeMilliseconds` 的操作,只保留对 RTOS tick 的操作:
```c
void xPortSysTickHandler( void ) {
/* Increment the RTOS tick. */
if( xTaskIncrementTick() != pdFALSE ) {
/* A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
}
}
```
阅读全文