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

📄 app.c

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 C
📖 第 1 页 / 共 3 页
字号:
    os_err = OSTaskCreateExt((void (*)(void *)) App_TaskKbd,
                             (void          * ) 0,
                             (OS_STK        * )&App_TaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
                             (INT8U           ) APP_TASK_KBD_PRIO,
                             (INT16U          ) APP_TASK_KBD_PRIO,
                             (OS_STK        * )&App_TaskKbdStk[0],
                             (INT32U          ) APP_TASK_KBD_STK_SIZE,
                             (void          * ) 0,
                             (INT16U          )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));

#if (OS_TASK_NAME_SIZE >= 9)
    OSTaskNameSet(APP_TASK_KBD_PRIO, "Keyboard", &os_err);
#endif
}


/*
*********************************************************************************************************
*                                            App_TaskKbd()
*
* Description : Monitor the state of the push buttons and passes messages to AppTaskUserIF()
*
* Argument(s) : p_arg       Argument passed to 'App_TaskKbd()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_TaskKbd (void *p_arg)
{
    CPU_BOOLEAN  b1_prev;
    CPU_BOOLEAN  b1;
    CPU_INT08U   key;


    (void)p_arg;

    b1_prev = DEF_FALSE;
    key     = 1;

    while (DEF_TRUE) {
        b1 = BSP_PB_GetStatus(1);

        if ((b1 == DEF_TRUE) && (b1_prev == DEF_FALSE)) {
            if (key == 2) {
                key = 1;
            } else {
                key++;
            }

            OSMboxPost(App_UserIFMbox, (void *)key);
        }

        b1_prev = b1;

        OSTimeDlyHMSM(0, 0, 0, 20);
    }
}


/*
*********************************************************************************************************
*                                            App_TaskUserIF()
*
* Description : Updates LCD.
*
* Argument(s) : p_arg       Argument passed to 'App_TaskUserIF()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_TaskUserIF (void *p_arg)
{
    CPU_INT08U  *msg;
    CPU_INT08U   err;
    CPU_INT32U   nstate;
    CPU_INT32U   pstate;


    (void)p_arg;


    App_DispScr_SignOn();
    OSTimeDlyHMSM(0, 0, 1, 0);
    nstate = 1;
    pstate = 1;


    while (DEF_TRUE) {
        msg = (CPU_INT08U *)(OSMboxPend(App_UserIFMbox, OS_TICKS_PER_SEC / 10, &err));
        if (err == OS_NO_ERR) {
            nstate = (CPU_INT32U)msg;
        }

        if (nstate != pstate) {
            LCD_Clear(APP_COLOR_WHITE);
            pstate  = nstate;
        }

        switch (nstate) {
            case 2:
                App_DispScr_TaskNames();
                break;

            case 1:
            default:
                App_DispScr_SignOn();
                break;
        }
    }
}


/*
*********************************************************************************************************
*                                          App_DispScr_SignOn()
*
* Description : Display uC/OS-II system information on the LCD.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : App_TaskUserIF().
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_DispScr_SignOn (void)
{
    CPU_INT32U  value;


    Str_Copy(App_LCDLine0, "  Micrium uC/OS-II  ");
    Str_Copy(App_LCDLine1, "ST STM32 (Cortex-M3)");

    Str_Copy(App_LCDLine2, "                    ");

    Str_Copy(App_LCDLine3, "  uC/OS-II:  Vx.yy  ");
    value            = (CPU_INT32U)OSVersion();
    App_LCDLine3[14] =  value / 100 + '0';
    App_LCDLine3[16] = (value % 100) / 10 + '0';
    App_LCDLine3[17] = (value %  10) + '0';

    Str_Copy(App_LCDLine4, "  TickRate:   xxxx  ");
    value = (CPU_INT32U)OS_TICKS_PER_SEC;
    App_FormatDec(&App_LCDLine4[14], value, 4);

    Str_Copy(App_LCDLine5, "  CPU Usage:xx %    ");
    value            = (CPU_INT32U)OSCPUUsage;
    App_LCDLine5[12] = (value / 10) + '0';
    App_LCDLine5[13] = (value % 10) + '0';

    Str_Copy(App_LCDLine6, "  CPU Speed:xx MHz  ");
    value            = (CPU_INT32U)BSP_CPU_ClkFreq() / 1000000L;
    App_LCDLine6[12] = (value / 10) + '0';
    App_LCDLine6[13] = (value % 10) + '0';

    Str_Copy(App_LCDLine7, "  #Ticks: xxxxxxxx  ");
    value = (CPU_INT32U)OSTime;
    App_FormatDec(&App_LCDLine7[10], value, 8);

    Str_Copy(App_LCDLine8, "  #CtxSw: xxxxxxxx  ");
    value = (CPU_INT32U)OSCtxSwCtr;
    App_FormatDec(&App_LCDLine8[10], value, 8);

    Str_Copy(App_LCDLine9, "                    ");

    LCD_SetTextColor(APP_COLOR_BLUE);
    LCD_DisplayString(APP_LINE_0, App_LCDLine0);
    LCD_DisplayString(APP_LINE_1, App_LCDLine1);
    LCD_SetTextColor(APP_COLOR_BLACK);
    LCD_DisplayString(APP_LINE_2, App_LCDLine2);
    LCD_DisplayString(APP_LINE_3, App_LCDLine3);
    LCD_DisplayString(APP_LINE_4, App_LCDLine4);
    LCD_DisplayString(APP_LINE_5, App_LCDLine5);
    LCD_DisplayString(APP_LINE_6, App_LCDLine6);
    LCD_DisplayString(APP_LINE_7, App_LCDLine7);
    LCD_DisplayString(APP_LINE_8, App_LCDLine8);
}



/*
*********************************************************************************************************
*                                          App_DispScr_SignOn()
*
* Description : Display uC/OS-II system information on the LCD.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : App_TaskUserIF().
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  void  App_DispScr_TaskNames (void)
{
    CPU_INT08U   ix;
    OS_TCB      *ptcb;
    CPU_CHAR    *line;
    CPU_INT08U   value;


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

    Str_Copy(App_LCDLine0, "  Micrium uC/OS-II  ");
    Str_Copy(App_LCDLine1, "ST STM32 (Cortex-M3)");

    Str_Copy(App_LCDLine2, "  Prio   Taskname   ");

    while (ptcb != NULL) {
        value = ptcb->OSTCBPrio;

        switch (ix) {
            case 0:
                 line = App_LCDLine3;
                 break;

            case 1:
                 line = App_LCDLine4;
                 break;

            case 2:
                 line = App_LCDLine5;
                 break;

            case 3:
                 line = App_LCDLine6;
                 break;

            case 4:
                 line = App_LCDLine7;
                 break;

            case 5:
                 line = App_LCDLine8;
                 break;

            case 6:
                 line = App_LCDLine9;
                 break;

            default:
                 line = (CPU_CHAR *)0;
                 break;
        }

        if (line == (CPU_CHAR *)0) {
            break;
        }

        line[0] = ' ';
        line[1] = ' ';
        line[2] = ' ';
        line[3] = value / 10 + '0';
        line[4] = value % 10 + '0';
        line[5] = ' ';
        Str_Copy_N(line + 6, ptcb->OSTCBTaskName, 14);

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

    if (ix < 6) {
        Str_Copy(App_LCDLine9, "                    ");
    }

    if (ix < 5) {
        Str_Copy(App_LCDLine8, "                    ");
    }

    if (ix < 4) {
        Str_Copy(App_LCDLine7, "                    ");
    }

    if (ix < 3) {
        Str_Copy(App_LCDLine6, "                    ");
    }

    LCD_SetTextColor(APP_COLOR_BLUE);
    LCD_DisplayString(APP_LINE_0, App_LCDLine0);
    LCD_DisplayString(APP_LINE_1, App_LCDLine1);
    LCD_SetTextColor(APP_COLOR_RED);
    LCD_DisplayString(APP_LINE_2, App_LCDLine2);
    LCD_SetTextColor(APP_COLOR_BLACK);
    LCD_DisplayString(APP_LINE_3, App_LCDLine3);
    LCD_DisplayString(APP_LINE_4, App_LCDLine4);
    LCD_DisplayString(APP_LINE_5, App_LCDLine5);
    LCD_DisplayString(APP_LINE_6, App_LCDLine6);
    LCD_DisplayString(APP_LINE_7, App_LCDLine7);
    LCD_DisplayString(APP_LINE_8, App_LCDLine8);
    LCD_DisplayString(APP_LINE_9, App_LCDLine9);
}


/*
*********************************************************************************************************
*                                             App_InitProbe()
*
* Description : Initialize uC/Probe target code.
*
* Argument(s) : none.
*
* Return(s)   : none.

⌨️ 快捷键说明

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