void task1_task(void *p_arg)
{
volatile OS_SEM_CTR sem_ctrl1;
OS_ERR err;
u8 task1_str[]="First task Running!";
while(1)
{
printf("\r\n任务1:\r\n");
LCD_Fill(0,110,239,319,CYAN);
sem_ctrl1=OSSemPend(&SEM1,0, OS_OPT_PEND_BLOCKING,0,&err); //请求信号量
memcpy(share_resource,task1_str,sizeof(task1_str)); //向共享资源区拷贝数据
delay_ms(300);
printf("%s\r\n",share_resource); //串口输出共享资源区数据
sem_ctrl1=OSSemPost(&SEM1,OS_OPT_POST_1,&err);//发送信号量
LED0 = ~LED0;
OSTimeDlyHMSM(0,0,0,400,OS_OPT_TIME_PERIODIC,&err); //延时1s
}
}
//任务2的任务函数
void task2_task(void *p_arg)
{
volatile OS_SEM_CTR sem_ctrl2;
OS_ERR err;
u8 task2_str[]="Second task Running!";
while(1)
{
printf("\r\n任务2:\r\n");
LCD_Fill(0,110,239,319,BROWN);
sem_ctrl2=OSSemPend(&SEM1,0, OS_OPT_PEND_BLOCKING,0,&err);//请求信号量
memcpy(share_resource,task2_str,sizeof(task2_str)); //向共享资源区拷贝数据
delay_ms(300);
printf("%s\r\n",share_resource); //串口输出共享资源区数据
sem_ctrl2=OSSemPost(&SEM1,OS_OPT_POST_1,&err); //发送信号量
LED1 = ~LED1;
OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err); //延时1s
}
}
void task3_task(void *p_arg)
{
volatile OS_SEM_CTR sem_ctrl2;
OS_ERR err;
u8 task3_str[]="thd task Running!";
while(1)
{
printf("\r\n任务3:\r\n");
LCD_Fill(0,110,239,319,BROWN);
sem_ctrl2=OSSemPend(&SEM1,0, OS_OPT_PEND_BLOCKING,0,&err);//请求信号量
memcpy(share_resource,task3_str,sizeof(task3_str)); //向共享资源区拷贝数据
printf("%s\r\n",share_resource); //串口输出共享资源区数据
sem_ctrl2=OSSemPost(&SEM1,OS_OPT_POST_1,&err); //发送信号量
LED1 = ~LED1;
OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_PERIODIC,&err); //延时1s
}
}
我就是在信号量共享资源的例程多加了个任务,就会进入hard fault中断,OS_OPT_POST_1改成OS_OPT_POST_ALL就行了
串口打印内容:
任务1:
任务2:
任务3:
First task Running!
Second task Running!
thd task Running!
任务1:
First task Running!
任务3:
thW task Running!
任务1:
任务2:
任务3:
First task Running!
Second task Running!
之后程序就死了
|