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

📄 app.c

📁 大名鼎鼎的uCOS-II在ARM1176处理器上的移植源代码+说明文档.强烈推荐!
💻 C
📖 第 1 页 / 共 2 页
字号:
                AppFormatDec(s, stk_pct, 2);
                s[2] = '%';
                LCD_DispStr   (32 + i * 2 + 1,(stk_sz / 40) + 1, s,          black); 
            }
            
            ptcb        = ptcb->OSTCBPrev;
            i++;
        } else {
            ptcb        = &OSTCBTbl[0];   
            i           = 0;            
        }
    }
}

/*
*********************************************************************************************************
*                                          CALCULATE FACTORIAL
*
* Description : This function uses a recursive function to calculate a factorial, thereby having 
*               variable stack usage.
*
* Returns     : none
*
* Arguments   : none
*
* Notes       : 
*********************************************************************************************************
*/

static  void  AppTaskFactorial (void *p_arg) 
{    
    CPU_INT08U  i;
    CPU_INT32U  factorial;
    
    
    i = 0;
    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        factorial = AppRecursiveFactorial(i++ % 50);
    }
}

/*
*********************************************************************************************************
*                                        Timer callback function
*********************************************************************************************************
*/

#if OS_TMR_EN > 0
static  void  AppTmrCallback (OS_TMR *ptmr, void *p_arg)
{
    CPU_INT08U   i;


    (void)&ptmr;
    i   = (CPU_INT08U)p_arg;
    AppTmrTbl[i].AppTmrCtr++;
}
#endif

/*
*********************************************************************************************************
*                                CONVERT R, G, B INTO 16-BIT COLOR
*
* Description: This function accepts red, green, and blue components of a color and returns a
*              16-bit value.
*
* Argument(s): red     is a 5-bit red   component
*              blue    is a 5-bit blue  component
*              green   is a 5-bit green component
*
* Returns    : The 16-bit color.
*********************************************************************************************************
*/

static  CPU_INT16U  AppFormatColor(CPU_INT08U  red, CPU_INT08U  green, CPU_INT16U blue) 
{
    return (((red & 0x1F) << 0) | ((green & 0x1F) << 5) | ((blue & 0x1F) << 10)); 
}


/*
*********************************************************************************************************
*                                      FORMAT A DECIMAL VALUE
*
* Description: This function converts a decimal value to ASCII (with leading zeros)
*
* Argument(s): s       is a pointer to the destination ASCII string
*              value   is the value to convert (assumes an unsigned value)
*              digits  is the desired number of digits
*
* Returns    : None
*********************************************************************************************************
*/

static  void  AppFormatDec (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits)
{
    CPU_INT08U  i;
    CPU_INT32U  mult;


    mult = 1;
    for (i = 0; i < (digits - 1); i++) {
        mult *= 10;
    }
    while (mult > 0) {
        *s++ = value / mult + '0';
        value %= mult;
        mult  /= 10;
    }
    *s = 0;
}

/*
*********************************************************************************************************
*                                    PRINT SYSTEM INFORMATION ON LCD
*
* Description: This function displays uC/OS-II system information on the LCD.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  AppPrintPage (void)
{
    CPU_INT08U  s[20];
    CPU_INT32U  value;
    CPU_INT16U  blue;
    CPU_INT16U  orange;
    CPU_INT16U  black;
    
    
    black   = AppFormatColor( 0, 0,  0);
    blue    = AppFormatColor( 0, 0, 31);
    orange  = AppFormatColor(28, 14,  0);


    LCD_DispStr(1,  0, "Micrium"         , black);
    LCD_DispStr(1,  7,        " uC/"     , orange);
    LCD_DispStr(1, 11,            "OS-II", blue);
    
    LCD_DispStr(2,  0, "    on the      ", black);
    
    LCD_DispStr(3,  0, "ARM1176JZF-S  CP", black);


    OS_StrCopy(s, "Vx.yy");
    LCD_DispStr(5,  0, "uC/"             , orange);
    LCD_DispStr(5,  3,    "OS-II:  "     , blue);
    
    value = (CPU_INT32U)OSVersion();
    s[1]  = value / 100 + '0';
    s[3]  = (value % 100) / 10 + '0';
    s[4]  = (value %  10) + '0';
    LCD_DispStr(5, 11, &s[0], black);


    OS_StrCopy(s, "TickRate:   xxxx");
    LCD_DispStr(6, 0, s, black);

    value = (CPU_INT32U)OS_TICKS_PER_SEC;
    AppFormatDec(&s[12], value, 4);
    LCD_DispStr(6, 12, &s[12], black);


    OS_StrCopy(s, "CPU Usage:  xx %");
    LCD_DispStr(7, 0, s, black);

    value = (CPU_INT32U)OSCPUUsage;
    s[10] = (value / 10) + '0';
    s[11] = (value % 10) + '0';
    LCD_DispStr(7, 12, &s[12], black);


    OS_StrCopy(s, "#Ticks: xxxxxxxx");
    LCD_DispStr(8, 0, s, black);

    value = (CPU_INT32U)OSTime;
    AppFormatDec(&s[8], value, 8);
    LCD_DispStr(8, 8, &s[8], black);


    OS_StrCopy(s, "#CtxSw: xxxxxxxx");
    LCD_DispStr(9, 0, s, black);

    value = (CPU_INT32U)OSCtxSwCtr;
    AppFormatDec(&s[8], value, 8);
    LCD_DispStr(9, 8, &s[8], black);
}


/*
*********************************************************************************************************
*                                           UPDATE LCD
*
* Description: This function updates the information on the LCD.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  AppUpdatePage (void)
{
    CPU_INT08U  s[9];
    CPU_INT32U  value;
    CPU_INT16U  blue;
    CPU_INT16U  orange;
    CPU_INT16U  black;
    
    
    black   = AppFormatColor( 0, 0,  0);
    blue    = AppFormatColor( 0, 0, 31);
    orange  = AppFormatColor(28, 14,  0);


    OS_StrCopy(s, "xxxx");
    value = (CPU_INT32U)OS_TICKS_PER_SEC;
    AppFormatDec(&s[0], value, 4);
    LCD_DispStr(6, 12, s, black);

    OS_StrCopy(s, "xx");
    value = (CPU_INT32U)OSCPUUsage;
    s[0] = (value / 10) + '0';
    s[1] = (value % 10) + '0';
    LCD_DispStr(7, 12, s, black);

    OS_StrCopy(s, "xxxxxxxx");
    value = (CPU_INT32U)OSTime;
    AppFormatDec(&s[0], value, 8);
    LCD_DispStr(8, 8, s, black);

    OS_StrCopy(s, "xxxxxxxx");
    value = (CPU_INT32U)OSCtxSwCtr;
    AppFormatDec(&s[0], value, 8);
    LCD_DispStr(9, 8, s, black);
}

/*
*********************************************************************************************************
*                                      CALCULATE FACTORIAL
*
* Description: This function calculates a factorial recursively.
*
* Argument(s): i
*
* Returns    : i!
*********************************************************************************************************
*/

static  CPU_INT32U  AppRecursiveFactorial (CPU_INT08U  i)
{
    if (i == 0) {
        return (1);
    } else {
        OSTimeDlyHMSM(0, 0, 0, 100);
        return (AppRecursiveFactorial(i - 1) * i);
    }
}

/*
*********************************************************************************************************
*                                      CREATE APPLICATION TASKS
*********************************************************************************************************
*/

static  void  AppTaskCreate (void)
{
    CPU_INT08U  err;


    OSTaskCreateExt(AppTaskGraph,
                    (void *)0,
                    (OS_STK *)&AppTaskGraphStk[APP_TASK_GRAPH_STK_SIZE - 1],
                    APP_TASK_GRAPH_PRIO,
                    APP_TASK_GRAPH_PRIO,
                    (OS_STK *)&AppTaskGraphStk[0],
                    APP_TASK_GRAPH_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 5
    OSTaskNameSet(APP_TASK_GRAPH_PRIO, "Graph", &err);
#endif

    OSTaskCreateExt(AppTaskStacks,
                    (void *)0,
                    (OS_STK *)&AppTaskStacksStk[APP_TASK_STACKS_STK_SIZE - 1],
                    APP_TASK_STACKS_PRIO,
                    APP_TASK_STACKS_PRIO,
                    (OS_STK *)&AppTaskStacksStk[0],
                    APP_TASK_STACKS_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(APP_TASK_STACKS_PRIO, "Stack Graph", &err);
#endif

    OSTaskCreateExt(AppTaskFactorial,
                    (void *)0,
                    (OS_STK *)&AppTaskFactorialStk[APP_TASK_FACTORIAL_STK_SIZE - 1],
                    APP_TASK_FACTORIAL_PRIO,
                    APP_TASK_FACTORIAL_PRIO,
                    (OS_STK *)&AppTaskFactorialStk[0],
                    APP_TASK_FACTORIAL_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 9
    OSTaskNameSet(APP_TASK_FACTORIAL_PRIO, "Factorial", &err);
#endif}
}

⌨️ 快捷键说明

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