问题:1、为什么Keyprocess_task()这个函数没有任务调度的延时函数呢,后面比它优先级低的任务msgdis_task()什么时候运行呢?是不是Keyprocess_task()的OSQPend函数没有请求到消息,然后阻塞后才运行msgdis_task()呢?2、还有就是OSQPend函数的返回值是多少呢?p=OSQPend((OS_Q* )&DATA_Msg, (OS_TICK )0, (OS_OPT )OS_OPT_PEND_BLOCKING, (OS_MSG_SIZE* )&size, (CPU_TS* )0, (OS_ERR* )&err); LCD_ShowString(5,270,100,16,16,p);咋返回值可以超出消息队列数量4而一直在不停的增加呢?
/任务优先级#define START_TASK_PRIO 3//任务堆栈大小 #define START_STK_SIZE 128//任务控制块OS_TCB StartTaskTCB;//任务堆栈 CPU_STK START_TASK_STK[START_STK_SIZE];//任务函数void start_task(void *p_arg);
//任务优先级#define MAIN_TASK_PRIO 4//任务堆栈大小 #define MAIN_STK_SIZE 128//任务控制块OS_TCB Main_TaskTCB;//任务堆栈 CPU_STK MAIN_TASK_STK[MAIN_STK_SIZE];void main_task(void *p_arg);
//任务优先级#define KEYPROCESS_TASK_PRIO 5//任务堆栈大小 #define KEYPROCESS_STK_SIZE 128//任务控制块OS_TCB Keyprocess_TaskTCB;//任务堆栈 CPU_STK KEYPROCESS_TASK_STK[KEYPROCESS_STK_SIZE];//任务函数void Keyprocess_task(void *p_arg);
//任务优先级#define MSGDIS_TASK_PRIO 6//任务堆栈#define MSGDIS_STK_SIZE 128//任务控制块OS_TCB Msgdis_TaskTCB;//任务堆栈CPU_STK MSGDIS_TASK_STK[MSGDIS_STK_SIZE];//任务函数void msgdis_task(void *p_arg);
//定时器1的回调函数void tmr1_callback(void *p_tmr,void *p_arg){ u8 *pbuf; static u8 msg_num; OS_ERR err; pbuf = mymalloc(SRAMIN,10); //申请10个字节 if(pbuf) //申请内存成功 { msg_num++; sprintf((char*)pbuf,"ALIENTEK %d",msg_num); //发送消息 OSQPost((OS_Q* )&DATA_Msg, (void* )pbuf, (OS_MSG_SIZE)10, (OS_OPT )OS_OPT_POST_FIFO, (OS_ERR* )&err); if(err != OS_ERR_NONE) { myfree(SRAMIN,pbuf); //释放内存 OSTmrStop(&tmr1,OS_OPT_TMR_NONE,0,&err); //停止定时器1 tmr1sta = !tmr1sta; LCD_ShowString(10,150,100,16,16,"TMR1 STOP! "); } } }
//主任务的任务函数void main_task(void *p_arg){ u8 key,num; OS_ERR err; u8 *p; while(1) { key = KEY_Scan(0); //扫描按键 if(key) { //发送消息 OSQPost((OS_Q* )&KEY_Msg, (void* )&key, (OS_MSG_SIZE)1, (OS_OPT )OS_OPT_POST_FIFO, (OS_ERR* )&err); } num++; if(num%10==0) check_msg_queue(p);//检查DATA_Msg消息队列的容量 if(num==50) { num=0; LED0 = ~LED0; } OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_PERIODIC,&err); //延时10ms }}
//按键处理任务的任务函数void Keyprocess_task(void *p_arg){ u8 num; u8 *key; OS_MSG_SIZE size; OS_ERR err; while(1) { //请求消息KEY_Msg key=OSQPend((OS_Q* )&KEY_Msg, (OS_TICK )0, (OS_OPT )OS_OPT_PEND_BLOCKING, (OS_MSG_SIZE* )&size, (CPU_TS* )0, (OS_ERR* )&err); switch(*key) { case WKUP_PRES: //KEY_UP控制LED1 LED1 = ~LED1; break; case KEY2_PRES: //KEY2控制蜂鸣器 BEEP = ~BEEP; break; case KEY0_PRES: //KEY0刷新LCD背景 num++; LCD_Fill(126,111,233,313,lcd_discolor[num%14]); break; case KEY1_PRES: //KEY1控制定时器1 tmr1sta = !tmr1sta; if(tmr1sta) { OSTmrStart(&tmr1,&err); LCD_ShowString(10,150,100,16,16,"TMR1 START!"); } else { OSTmrStop(&tmr1,OS_OPT_TMR_NONE,0,&err); //停止定时器1 LCD_ShowString(10,150,100,16,16,"TMR1 STOP! "); } break; } }}
//显示消息队列中的消息void msgdis_task(void *p_arg){ u8 *p; OS_MSG_SIZE size; OS_ERR err; while(1) { //请求消息 p=OSQPend((OS_Q* )&DATA_Msg, (OS_TICK )0, (OS_OPT )OS_OPT_PEND_BLOCKING, (OS_MSG_SIZE* )&size, (CPU_TS* )0, (OS_ERR* )&err); LCD_ShowString(5,270,100,16,16,p); myfree(SRAMIN,p); //释放内存 OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err); //延时1s }}
一周热门 更多>