⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucosii_util.c

📁 ucos内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
static CHAR sg_osTaskInfoBrief[] = "Display Tasks Informations of System";
static CHAR sg_osTaskInfoDetail[] =
    "Command Line 0:OsTaskInfo""\r\n"
    ;

static int//0 - 成功
          //-1 - 参数数目错误
          //-2 - 参数不可识别
OsTaskInfo
    (
    int a_argc,//参数数量
    char **a_pArgv//参数列表
    )
{
    INT8U   prio;
    OS_TCB *ptcb;
    CHAR *pStrStat;
    
    
    if (a_argc > 2)
    {   //参数错误
        printf(sg_osTaskInfoDetail);
        
        return -1;
    }
    
    if (a_argc == 1)
    {   //未提供参数,显示所有任务信息
        printf("%" OS_TASK_NAME_SIZE_STR "s" " %4s" " %4s" " %4s" " %6s"     " %8s"     " %8s"     " %8s""\r\n",
                                      "NAME","PRIO","STAT","DELY"," RUNS","SWITCHES","STACK","USED");
               
        OS_ENTER_CRITICAL();
        for (prio = 0; prio <= OS_LOWEST_PRIO; prio++)
        {
            ptcb = OSTCBPrioTbl[prio];
            if ( ptcb != (OS_TCB *)0
              && ptcb != (OS_TCB *)1 )             // Does task exist? (Not a Mutex reserved task)
            {
                printf("%" OS_TASK_NAME_SIZE_STR "s", ptcb->OSTCBTaskName);     // Task name
                printf(" %4d",  ptcb->OSTCBPrio);                               // Prio
                EnumToStr(g_osTaskStateStrTbl, ptcb->OSTCBStat, &pStrStat);
                printf(" %4s",  pStrStat);                                      // Task status
                printf(" %4X",  ptcb->OSTCBDly);                                // Timeout (i.e. ticks of delayed task)
                printf(" %.4f", ((FP32)ptcb->OSTCBCyclesTot)/OSTime);           // ExecTime Percent
                printf(" %8lX", ptcb->OSTCBCtxSwCtr);                           // NumActivations
                printf(" %8lX", ptcb->OSTCBStkSize * sizeof(OS_STK));           // Stack size (in #bytes)
                if (ptcb->OSTCBStkUsed == 0)
                {
                    printf(" %8s", "n/a");                                      // not available
                }
                else
                {
                    printf(" %8lX", ptcb->OSTCBStkUsed);                        // Number of bytes used
                }
                printf("\r\n");
            }
        }
        OS_EXIT_CRITICAL();
    }
    else if (a_argc == 2)
    {   //详细显示某个特定任务的详细信息
    }
    
    return 0;
}
#endif

#if OS_VIEW_MODULE > 0
static BOOL sg_isOsViewOn = FALSE;

static CHAR sg_inputC = 0;
static BOOL sg_isInputCAvailable = FALSE;
static INT32U sg_inputCDropCnt = 0;

//------------------------------------------------------------------------------
int//Returns c if successful. If fails, it returns EOF;
OsViewPutChHook
  (
  int c//char to put into Console I/O channel
  )
{
  static char s_str[OS_VIEW_TX_STR_SIZE + 1] = "";
  static int s_cnt = 0;


  assert(sg_isOsViewOn == TRUE);
  
  s_str[s_cnt] = c;
  ++s_cnt;
  //the buffer will be flushed when a new-line character is
  //written, when the buffer is full, or when input is requested
  if ( (c == '\r') || (c == '\n')
    || (s_cnt >= OS_VIEW_TX_STR_SIZE)
    || (sg_isInputCAvailable == TRUE) )
  {
    s_str[s_cnt] = '\0';
    if (OSIntNesting > 0)
    {
      OSView_TxStr(s_str, 0);
    }
    else
    {
      OSView_TxStr(s_str, 1);
    }
    s_cnt = 0;
  }
  
  return c;
}

//------------------------------------------------------------------------------
// 函数描述:检查Console I/O是否有按键输入
int//0 - 无按键
   //非0 - 有按键
OsViewKbHitHook(void)
{
  assert(sg_isOsViewOn == TRUE);
  
  if (sg_isInputCAvailable == TRUE)
  {
    return 1;
  }
  else
  {
    // since OS_VIEW use interrupt method, so we simply return
    return 0;
  }
}

//------------------------------------------------------------------------------
int//char get from Console I/O channel
OsViewGetChHook(void)
{
  assert(sg_isOsViewOn == TRUE);
  
  // wait until input available
  while (OsViewKbHitHook() == 0)
    ;
  sg_isInputCAvailable = FALSE;
  
  return sg_inputC;
}

//------------------------------------------------------------------------------
// 函数描述:绑定到OS_VIEW Terminal的回调函数
void OsViewTerminalCallback
  (
  INT8U data//input data from OS_VIEW's terminal window
  )
{
  assert(sg_isOsViewOn == TRUE);
  
  if (sg_isInputCAvailable == TRUE)
  {// last input key has not been processed yet. so we drop this key
    // and increase the statistic counter
    ++sg_inputCDropCnt;
  }
  else
  {
  	sg_inputC = data;
  	sg_isInputCAvailable = TRUE;
  }
}

//------------------------------------------------------------------------------
// 函数描述:启动/停止uC/OS II的OS_VIEW模块
CHAR sg_osViewBrief[] = "启动/停止uC/OS II的OS_VIEW模块";
CHAR sg_osViewDetail[] =
    "命令行0:OsView switch""\r\n"
    "    参数0:switch - 开关""\r\n"
    "        - ON - 启动""\r\n"
    "        - OFF - 停止""\r\n"
    ;

int
  //0 - 成功
  //-1 - 参数数目错误
  //-2 - 参数不可识别
OsView
    (
    int a_argc,//参数数量
    char **a_pArgv//参数列表
    )
{
  if (a_argc != 2)
  {
    printf(sg_osViewDetail);
    
    return -1;
  }
  
  if (strcmp(a_pArgv[1], "OFF") == 0)
  {
    if (sg_isOsViewOn == FALSE)
    {
      printf("\r\n""OS_VIEW is already OFF");
    }
    else
    {
      printf("Console I/O has been redirected to default""\r\n");
      
      if (ConioInit() == 0)
      {
        assert(g_pGetchHookFn != NULL);
        g_pGetchHookFn = NULL;
        assert(g_pPutchHookFn != NULL);
        g_pPutchHookFn = NULL;
        assert(g_pKbhitHookFn != NULL);
        g_pKbhitHookFn = NULL;

        sg_isOsViewOn = FALSE;
      }
      else
      {
        printf("but failed!""\r\n");
      }
    }
  }
  else if (strcmp(a_pArgv[1], "ON") == 0)
  {
    if (sg_isOsViewOn == TRUE)
    {
      printf("OS_VIEW is already ON""\r\n");
    }
    else
    {
      sg_isOsViewOn = TRUE;

      printf("Console I/O has been redirected to OS_VIEW" "\r\n");
      
      OSView_Init();
    	OSView_TerminalRxSetCallback(OsViewTerminalCallback);
    	assert(g_pGetchHookFn == NULL);
    	g_pGetchHookFn = OsViewGetChHook;
    	assert(g_pPutchHookFn == NULL);
    	g_pPutchHookFn = OsViewPutChHook;
    	assert(g_pKbhitHookFn == NULL);
    	g_pKbhitHookFn = OsViewKbHitHook;
    }
  }
  else
  {
    printf(sg_osViewDetail);
    
    return -2;
  }
  
  return 0;
}
#endif

#if UCOSII_UTIL_INIT_EN > 0
//------------------------------------------------------------------------------
// 函数描述:初始化ucosii_util模块
STATUS//OK
      //ERROR
UcosiiUtilInit(void)
{
    #if LIB_SHELL_EN > 0
    STATUS result;
    
    
    #if UCOSII_UTIL_OS_TASK_INFO_EN > 0
    result = ShellRegCmd("OsTaskInfo", OsTaskInfo, sg_osTaskInfoBrief, sg_osTaskInfoDetail);
    if (result != OK)
    {
        return (STATUS)ERROR;
    }
    #endif
    
    #if OS_VIEW_MODULE > 0
    result = ShellRegCmd("OsView", OsView, sg_osViewBrief, sg_osViewDetail);
    if (result != OK)
    {
        return (STATUS)ERROR;
    }
    #endif
    
    #endif    
    
    return OK;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -