二胡 https://passport2.21ic.com/?12211 [收藏] [复制] [RSS]

日志

ucosii的一个代码,任务查询

已有 751 次阅读2008-11-11 20:16 |系统分类:嵌入式系统

1 用串口输出任务信息
2 你可以用print函数重写
3 查看任务状态和任务栈使用情况,根据需要设置合适的栈长度
4 下面的状态判断可以改成switch实现

/*******************/
Uart0SendSTR("版本V1.0\r\n");

           i = OSTimeGet()/100;
           Uart0SendSTR("系统连续运行:");
           Uart0SendNUM(i/3600,0,0);
           i %= 3600;
           Uart0SendSTR("小时");
           Uart0SendNUM(i/60,0,0);
           Uart0SendSTR("分");
           Uart0SendNUM(i%60,0,0);
           Uart0SendSTR("秒\r\n");
           Uart0SendSTR("CPU利用率:");
           Uart0SendNUM(OSCPUUsage,0,0);
           Uart0SendSTR("%\r\n");
           Uart0SendSTR("任务        总堆栈        空闲栈        运行态\r\n");
           Uart0SendSTR("----        ------        ------        ------\r\n");                      
           for(i = 0;i < OS_LOWEST_PRIO+1; i ++)
           {
               err = OSTaskQuery(i,&task_data);
               if(err != OS_NO_ERR) continue;
               if(i == 2) continue;
               Uart0SendSTR((char *)task_name);
               Uart0SendSTR("\t\t");
               err = OSTaskStkChk(i,&task_stk);
               if(err != OS_NO_ERR) continue;
               Uart0SendNUM(task_stk.OSFree+task_stk.OSUsed,0,0);
               Uart0SendSTR("\t\t");
               Uart0SendNUM(task_stk.OSFree,0,0);
               Uart0SendSTR("\t\t");
               err = task_data.OSTCBStat;
               if(err == OS_STAT_RDY) Uart0SendSTR("就绪");
               else if(err == OS_STAT_SEM) Uart0SendSTR("等信号量");
               else if(err == OS_STAT_MBOX) Uart0SendSTR("等邮件");
               else if(err == OS_STAT_Q) Uart0SendSTR("等消息队列");
               else if(err == OS_STAT_SUSPEND) Uart0SendSTR("挂起");
               else if(err == OS_STAT_MUTEX) Uart0SendSTR("等互斥量");
               else if(err == OS_STAT_FLAG) Uart0SendSTR("等标志");
               Uart0SendSTR("\r\n");
               
           }


/**************/

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)