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

📄 app.c

📁 Micrium-NXP-uCOS-II-LPC2378-SK.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
static  void  AppTaskCreate (void)
{
    CPU_INT08U      err;


    OSTaskCreateExt(AppTaskUserIF,
                    (void *)0,
                    (OS_STK *)&AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE - 1],
                    APP_TASK_USER_IF_PRIO,
                    APP_TASK_USER_IF_PRIO,
                    (OS_STK *)&AppTaskUserIFStk[0],
                    APP_TASK_USER_IF_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 8
    OSTaskNameSet(APP_TASK_USER_IF_PRIO, "User I/F", &err);
#endif

    OSTaskCreateExt(AppTaskKbd,
                    (void *)0,
                    (OS_STK *)&AppTaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
                    APP_TASK_KBD_PRIO,
                    APP_TASK_KBD_PRIO,
                    (OS_STK *)&AppTaskKbdStk[0],
                    APP_TASK_KBD_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 8
    OSTaskNameSet(APP_TASK_KBD_PRIO, "Keyboard", &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
}

/*
*********************************************************************************************************
*                                            DISPLAY SCREENS
*
* Descrition:  These functions each display one of the screens used in the demonstration.
*
* Arguments :  none
*
* Returns   :  none
*********************************************************************************************************
*/

static  void  AppDispScr_Transition (void)
{
    CPU_INT32U      idx;
    CPU_INT32U      x;
    CPU_INT32U      y;
    CPU_INT32U      r;
    CPU_INT32U      g;
    CPU_INT32U      b;
    CPU_INT32U      temp;
    CPU_INT32U      color;



    for (idx = 0; idx < 512; idx++) {

        x       = rand() % 120;
        y       = rand() % 120;
        r       = rand() % 15;
        g       = rand() % 15;
        b       = rand() % 15;

        temp    = idx / 32;

        if (r < temp) {
            r   = temp;
        }

        if (g < temp) {
            g   = temp;
        }

        if (b < temp) {
            b   = temp;
        }

        color   = (r << 8) | (g << 4) | b;
        GLCD_DrawRectangle(x, y, 10, 10, color);
        OSTimeDlyHMSM(0, 0, 0, 1);
    }
}

static  void  AppDispScr_SignOn (void)
{
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLACK,    COLOR_WHITE);
    GLCD_SetWindow( 5,  0, 131, 80);
    GLCD_TextSetPos(0, 0);
    printf(" Micrium   \r\n");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II\r\n");

    GLCD_SetFont(&Terminal_9_12_6,      COLOR_BLACK,    COLOR_WHITE);
    GLCD_SetWindow( 5,  70, 131, 120);
    GLCD_TextSetPos(0, 0);
    printf("  for NXP LPC2378  \r\n"
           " on IAR LPC2378-SK \r\n");
}

static  void  AppDispScr_VersionTickRate (void)
{
    CPU_INT32U    value;


    GLCD_SetWindow( 5,  0, 131, 131);
    GLCD_TextSetPos(0, 0);
    value = OSVersion();
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLACK,    COLOR_WHITE);
    printf(        " \r\n V%d.%d%d \r\n", value / 100, (value % 100) / 10, (value %  10));

    GLCD_SetFont(&Terminal_9_12_6,      COLOR_BLACK,    COLOR_WHITE);
    GLCD_SetWindow( 5,  40, 131, 131);
    printf("Tick rate   = %d Hz   \r\n"
           "Total ticks = %d      \r\n"
           "Total number of       \r\n"
           "context switches =    \r\n"
           "        %d            \r\n", OS_TICKS_PER_SEC, OSTime, OSCtxSwCtr);
}

static  void  AppDispScr_CPU (void)
{
    CPU_INT32U    value;


    GLCD_SetWindow( 5,  0, 131, 131);
    GLCD_TextSetPos(0, 0);
    value = OSVersion();
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLACK,    COLOR_WHITE);
    printf(        " \r\n V%d.%d%d \r\n", value / 100, (value % 100) / 10, (value %  10));

    GLCD_SetFont(&Terminal_9_12_6,      COLOR_BLACK,    COLOR_WHITE);
    GLCD_SetWindow( 5,  40, 131, 131);
    printf("The CPU usage is %d%%.\r\n"
           "The CPU speed is      \r\n"
           "       %d Hz          \r\n", OSCPUUsage, BSP_CPU_ClkFreq());
}

static  void  AppDiscScr_TaskNames (void)
{
    CPU_INT08U  idx;
    OS_TCB     *ptcb;


    ptcb    = &OSTCBTbl[0];
    idx     = 0;

    GLCD_SetWindow( 5,  0, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II\r\n");

    GLCD_SetWindow( 5,  30, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_9_12_6,      COLOR_BLACK,    COLOR_WHITE);
    printf("Task info: \r\n");

    GLCD_SetWindow( 5,  45, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_9_12_6,      COLOR_RED,      COLOR_WHITE);
    printf("Prio\t Taskname  \r\n");

    GLCD_SetWindow( 5,  60, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_6_8_6,       COLOR_BLACK,    COLOR_WHITE);
    while (ptcb != NULL) {
        printf("%d \t %s\r\n", ptcb->OSTCBPrio, ptcb->OSTCBTaskName);

        ptcb        = ptcb->OSTCBPrev;
        idx++;
    }
}

static  void  AppDispScr_TaskStacks (void)
{
    CPU_INT08U  idx;
    CPU_INT16U  stk_pct;
    CPU_INT32U  stk_sz;
    CPU_INT32U  stk_use;
    CPU_INT32U  stk_max;
    OS_TCB     *ptcb;


    ptcb    = &OSTCBTbl[0];
    idx     = 0;

    GLCD_SetWindow( 5,  0, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II\r\n");

    GLCD_SetWindow( 5,  30, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_9_12_6,      COLOR_BLACK,    COLOR_WHITE);
    printf("Stack info: \r\n");

    GLCD_SetWindow( 5,  45, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_9_12_6,      COLOR_RED,      COLOR_WHITE);
    printf("Prio\t Stack  \r\n");

    GLCD_SetFont(&Terminal_6_8_6,       COLOR_BLACK,    COLOR_WHITE);
    while (ptcb != NULL) {
        stk_sz      = ptcb->OSTCBStkSize * sizeof (OS_STK);
        stk_use     = (CPU_INT32U)(ptcb->OSTCBStkBase) - (CPU_INT32U)(ptcb->OSTCBStkPtr);
        stk_max     = ptcb->OSTCBStkUsed;

        if (stk_sz != 0) {
            stk_pct = 100 * stk_use / stk_sz;

            GLCD_SetWindow(3,  60 + idx * 8, 131, 60 + (idx + 1) * 8);
            GLCD_TextSetPos(0, 0);
            printf("%d", ptcb->OSTCBPrio);

            if (stk_sz / 10 < 90) {
                GLCD_DrawRectangle(20, 60 + idx * 8, stk_sz  / 10, 6, COLOR_GREEN1);
            }
            if (stk_max / 10 < 90) {
                GLCD_DrawRectangle(20, 60 + idx * 8, stk_max / 10, 6, COLOR_GREEN2);
            }
            if (stk_use / 10 < 90) {
                GLCD_DrawRectangle(20, 60 + idx * 8, stk_use / 10, 6, COLOR_GREEN3);
            }

            GLCD_SetWindow( 105,  60 + idx * 8, 131, 60 + (idx + 1) * 8);
            GLCD_TextSetPos(0, 0);
            printf("%d%%", stk_pct);
        }

        ptcb        = ptcb->OSTCBPrev;
        idx++;
    }
}

static  void  AppDispScr_TaskCPU (void)
{
    CPU_INT32U  idx;
    CPU_INT32U  jdx;
    CPU_INT32U  kdx;
    OS_TCB     *ptcb;


    GLCD_SetWindow( 5,  0, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_ORANGE,   COLOR_WHITE);
    printf("uC/");
    GLCD_SetFont(&Terminal_18_24_12,    COLOR_BLUE,     COLOR_WHITE);
    printf(   "OS-II\r\n");

    GLCD_SetWindow( 5,  25, 131, 131);
    GLCD_TextSetPos(0, 0);
    GLCD_SetFont(&Terminal_9_12_6,      COLOR_RED,      COLOR_WHITE);
    printf("Prio and CPU %% Color: \r\n");

    GLCD_SetFont(&Terminal_6_8_6,      COLOR_BLACK,     COLOR_WHITE);

    idx     = 0;
    ptcb    = &OSTCBTbl[0];
    while (idx < CPU_USAGE_NUM_TASKS) {
        if (ptcb == NULL) {
            break;
        }

#if CPU_USAGE_NUM_TASKS > 8
        if (idx < 4) {
            GLCD_SetWindow( 5, 40 + (idx    ) * 8, 131, 131);
        } else if (idx < 8) {
            GLCD_SetWindow(50, 40 + (idx - 4) * 8, 131, 131);
        } else if (idx < 12) {
            GLCD_SetWindow(95, 40 + (idx - 8) * 8, 131, 131);
        }
#else
        if (idx < 4) {
            GLCD_SetWindow( 5, 40 + (idx    ) * 8, 131, 131);
        } else if (idx < 8) {
            GLCD_SetWindow(70, 40 + (idx - 4) * 8, 131, 131);
        }
#endif

        GLCD_TextSetPos(0, 0);
        printf("%d", ptcb->OSTCBPrio);


#if CPU_USAGE_NUM_TASKS > 8
        if (idx < 4) {
            GLCD_DrawRectangle(25, 40 + (idx    ) * 8, 6,  6, AppTaskCPUUsageColors[idx]);
        } else if (idx < 8) {
            GLCD_DrawRectangle(70, 40 + (idx - 4) * 8, 6,  6, AppTaskCPUUsageColors[idx]);
        } else if (idx < 12) {
            GLCD_DrawRectangle(115, 40 + (idx - 8) * 8, 6,  6, AppTaskCPUUsageColors[idx]);
        }
#else
        if (idx < 4) {
            GLCD_DrawRectangle(20, 40 + (idx    ) * 8,   6,   6, AppTaskCPUUsageColors[idx]);
            GLCD_SetWindow(    30, 40 + (idx    ) * 8, 131, 131);
        } else if (idx < 8) {
            GLCD_DrawRectangle(85, 40 + (idx - 4) * 8,   6,   6, AppTaskCPUUsageColors[idx]);
            GLCD_SetWindow(    95, 40 + (idx - 4) * 8, 131, 131);
        }

        GLCD_TextSetPos(0, 0);
        printf("%0.1f%%", OSProbe_TaskCPUUsage[idx]);
#endif

        ptcb    = ptcb->OSTCBPrev;
        idx++;
    }


#if CPU_USAGE_NUM_TASKS > 8
    GLCD_DrawRectangle(45, 38, 1,  34, COLOR_RED);
    GLCD_DrawRectangle(90, 38, 1,  34, COLOR_RED);
#else
    GLCD_DrawRectangle(65, 38, 1,  34, COLOR_RED);
#endif

    GLCD_DrawRectangle(10, 125 - 50, 105, 50, COLOR_WHITE);
    GLCD_DrawRectangle(10, 125 - 50,   2, 50, COLOR_BLACK);
    GLCD_DrawRectangle(10,      125, 105,  2, COLOR_BLACK);

    kdx         = AppTaskCPUUsageIdx;

    if (kdx < CPU_USAGE_NUM_SAMPLES) {

        kdx    += CPU_USAGE_BUF_SIZE - CPU_USAGE_NUM_SAMPLES;
    } else {

        kdx    -= CPU_USAGE_NUM_SAMPLES;
    }

    for (jdx = 0; jdx < CPU_USAGE_NUM_SAMPLES - 1; jdx++) {

        kdx++;
        if (kdx >= CPU_USAGE_BUF_SIZE) {

            kdx = 0;
        }

        for (idx = 0; idx < CPU_USAGE_NUM_TASKS; idx++) {

            GLCD_DrawLine(10 + jdx * 3, 125 - AppTaskCPUUsage[idx][kdx] * 1 / 2, 10 + (jdx + 1) * 3, 125 - AppTaskCPUUsage[idx][kdx + 1] * 1 / 2, AppTaskCPUUsageColors[idx]);
        }
    }

    GLCD_DrawRectangle(10, 125 - 50,   2, 50, COLOR_BLACK);
    GLCD_DrawRectangle(10,      125, 105,  2, COLOR_BLACK);
}

/*
*********************************************************************************************************
*                                          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;
    volatile  CPU_INT32U  factorial;


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

/*
*********************************************************************************************************
*                                      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);
    }
}

/*
*********************************************************************************************************
*                                          uC/OS-VIew Terminal Window Callback
*
* Description : This is the callback function for uC/OS-View
*
* Arguments   : rx_data   is the received data.
*
* Returns     : none
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx (CPU_INT08U rx_data)
{
}
#endif

⌨️ 快捷键说明

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