我使用FreeRTOS v9处理STM32F4-Discovery。我有2个任务,任务1用于闪烁LED,任务2用于使用LwIP进行etherenet连接。
任务1
void test_print(void)
{
TickType_t wake_time,tamp1,tamp2;
const uint32_t period = 100;
char buff[32];
wake_time = xTaskGetTickCount();
while(1)
{
USART_puts("aaaaaaaaaaa\n ");
GPIO_SetBits(GPIOD,GPIO_Pin_13);
delay_dw(500); //This is just my own function delay
GPIO_ResetBits(GPIOD,GPIO_Pin_13);
delay_dw(500);
}
}
任务2
void echo_tcp()
{
int c1,c2;
char clock[32],tmp[32];
tamp = 0;
while(1)
{
if(ETH_CheckFrameReceived())
{
cycle_start();
c1 = getCycles();
LwIP_Pkt_Handle();
c2 = getCycles();
cycle_stop();
tamp+= c2 - c1;
GPIO_SetBits(GPIOD,GPIO_Pin_12);
delay_dw(2000);
GPIO_ResetBits(GPIOD,GPIO_Pin_12);
delay_dw(2000);
}
else
{
GPIO_ResetBits(GPIOD,GPIO_Pin_12);
LwIP_Periodic_Handle(LocalTime);
}
}
}
我使用定时器功能进行中断。在这种情况下,中断的目的是向我展示当我在一起运行2个任务时给出一些连接负载时每1秒任务2的周期。
这是我的中断配置
void TIM2_Config(){
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_PCLK1Config(RCC_HCLK_Div16);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 42000-1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 200-1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_Cmd(TIM2,ENABLE);
}
void TIM_IT_Enable(){
TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE);
}
void NVIC_Config(){
NVIC_InitTypeDef NVIC_InitStrurture;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStrurture.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStrurture.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStrurture.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStrurture.NVIC_IRQChannelCmd =ENABLE;
NVIC_Init(&NVIC_InitStrurture);
}
int nInterrupt=0,counter;
char buffer[32];
char buf_temp[32];
void TIM2_IRQHandler(){
if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET){
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
nInterrupt++;
//USART_puts("Interrupt!!\n");
sprintf(buf_temp,"%d\n",temp); //tamp is int variable
USART_puts(buf_temp); //BUG IN HERE
temp = 0;
}
}
当我编译它并将其上传到我的STM32F4-Discovery时,所有任务都没有运行,但是当我在TIM2_IRQHandler()函数上命令(禁用)usart函数时,所有任务都运行良好。如果我这样做,我就无法看到我的任务循环。有人帮忙吗?
抱歉英文不好
问候,拉玛