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

📄 app.c

📁 ST32F10xxx+uCOSII2.85的官方源代码,带LCD驱动,支持Keil3和IAR环境.这个可以做为参考,实际使用需要修改,他做的太复杂了,目录也很深
💻 C
📖 第 1 页 / 共 2 页
字号:

    (void)p_arg;

    b1_prev = DEF_FALSE;
    key     = 1;

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

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

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

        b1_prev = b1;

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


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

static  void  AppDispScr_SignOn (void)
{
    CPU_INT32U  value;


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

    Str_Copy(AppLCDLine2, "                    ");

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

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

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

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

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

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

    Str_Copy(AppLCDLine9, "                    ");

    LCD_SetTextColor(COLOR_BLUE);
    LCD_DisplayString(APP_LINE_0, AppLCDLine0);
    LCD_DisplayString(APP_LINE_1, AppLCDLine1);
    LCD_SetTextColor(COLOR_BLACK);
    LCD_DisplayString(APP_LINE_2, AppLCDLine2);
    LCD_DisplayString(APP_LINE_3, AppLCDLine3);
    LCD_DisplayString(APP_LINE_4, AppLCDLine4);
    LCD_DisplayString(APP_LINE_5, AppLCDLine5);
    LCD_DisplayString(APP_LINE_6, AppLCDLine6);
    LCD_DisplayString(APP_LINE_7, AppLCDLine7);
    LCD_DisplayString(APP_LINE_8, AppLCDLine8);
}


static  void  AppDispScr_TaskNames (void)
{
    CPU_INT08U   idx;
    OS_TCB      *ptcb;
    CPU_CHAR    *line;
    CPU_INT08U   value;


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

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

    Str_Copy(AppLCDLine2, "  Prio   Taskname   ");

    while (ptcb != NULL) {

        value = ptcb->OSTCBPrio;

        switch (idx) {
            case 0:
                 line = AppLCDLine3;
                 break;

            case 1:
                 line = AppLCDLine4;
                 break;

            case 2:
                 line = AppLCDLine5;
                 break;

            case 3:
                 line = AppLCDLine6;
                 break;

            case 4:
                 line = AppLCDLine7;
                 break;

            case 5:
                 line = AppLCDLine8;
                 break;

            case 6:
                 line = AppLCDLine9;
                 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;
        idx++;
    }

    if (idx < 6) {
        Str_Copy(AppLCDLine9, "                    ");
    }

    if (idx < 5) {
        Str_Copy(AppLCDLine8, "                    ");
    }

    if (idx < 4) {
        Str_Copy(AppLCDLine7, "                    ");
    }

    if (idx < 3) {
        Str_Copy(AppLCDLine6, "                    ");
    }

    LCD_SetTextColor(COLOR_BLUE);
    LCD_DisplayString(APP_LINE_0, AppLCDLine0);
    LCD_DisplayString(APP_LINE_1, AppLCDLine1);
    LCD_SetTextColor(COLOR_RED);
    LCD_DisplayString(APP_LINE_2, AppLCDLine2);
    LCD_SetTextColor(COLOR_BLACK);
    LCD_DisplayString(APP_LINE_3, AppLCDLine3);
    LCD_DisplayString(APP_LINE_4, AppLCDLine4);
    LCD_DisplayString(APP_LINE_5, AppLCDLine5);
    LCD_DisplayString(APP_LINE_6, AppLCDLine6);
    LCD_DisplayString(APP_LINE_7, AppLCDLine7);
    LCD_DisplayString(APP_LINE_8, AppLCDLine8);
    LCD_DisplayString(APP_LINE_9, AppLCDLine9);
}


/*
*********************************************************************************************************
*                                         STRING OUTPUT TASK
*
* Description : This task constantly output a string via the uC/Probe general communication module.
*
* Arguments   : p_arg   is the argument passed to 'AppTaskProbeStr()' by 'OSTaskCreate()'.
*
* Returns     : none
*********************************************************************************************************
*/

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
static  void  AppTaskProbeStr (void *p_arg)
{
            CPU_INT32U   i;
    static  CPU_CHAR     buffer[64];


    i   = 0;

    while (DEF_TRUE) {
        Str_Copy(buffer, "String Tx #xxxxx\n");
        AppFormatDec(&buffer[11], i, 5);
        i++;
        ProbeCom_TxStr(buffer, 100);
        OSTimeDlyHMSM(0, 0, 1, 0);
    }
}
#endif


/*
*********************************************************************************************************
*                                         uC/Probe Callback
*
* Description : This task is called by the uC/Probe uC/OS-II plug-in after updating task information.
*
* Arguments   : none.
*
* Returns     : none
*********************************************************************************************************
*/

#if (uC_PROBE_OS_PLUGIN > 0)
static  void  AppProbeCallback (void)
{
#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
    CPU_INT32U  ctr_curr;
    CPU_INT32U  rx_curr;
    CPU_INT32U  tx_curr;
    CPU_INT32U  rxpkt_curr;
    CPU_INT32U  txpkt_curr;
    CPU_INT32U  sym_curr;
    CPU_INT32U  symbyte_curr;
#endif
    CPU_INT32U  joystick;


    Probe_Counts++;

    Probe_B1 = PB_GetStatus(1);

    joystick = Joystick_GetStatus();

    if ((joystick & JOYSTICK_LEFT) == JOYSTICK_LEFT) {
        Probe_JoyLeft = DEF_TRUE;
    } else {
        Probe_JoyLeft = DEF_FALSE;
    }

    if ((joystick & JOYSTICK_RIGHT) == JOYSTICK_RIGHT) {
        Probe_JoyRight = DEF_TRUE;
    } else {
        Probe_JoyRight = DEF_FALSE;
    }

    if ((joystick & JOYSTICK_UP) == JOYSTICK_UP) {
        Probe_JoyUp = DEF_TRUE;
    } else {
        Probe_JoyUp = DEF_FALSE;
    }

    if ((joystick & JOYSTICK_DOWN) == JOYSTICK_DOWN) {
        Probe_JoyDown = DEF_TRUE;
    } else {
        Probe_JoyDown = DEF_FALSE;
    }

    if ((joystick & JOYSTICK_CENTER) == JOYSTICK_CENTER) {
        Probe_JoyCenter = DEF_TRUE;
    } else {
        Probe_JoyCenter = DEF_FALSE;
    }

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
    ctr_curr     = OSTime;
    rxpkt_curr   = ProbeRS232_RxPktCtr;
    txpkt_curr   = ProbeRS232_TxPktCtr;
    rx_curr      = ProbeRS232_RxCtr;
    tx_curr      = ProbeRS232_TxCtr;
    sym_curr     = ProbeCom_TxSymCtr;
    symbyte_curr = ProbeCom_TxSymByteCtr;

    if ((ctr_curr - Probe_ComCtrLast) >= OS_TICKS_PER_SEC) {

        Probe_RS232RxSpd      = ((CPU_FP32)(rx_curr      - Probe_RS232RxLast)      / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;
        Probe_RS232TxSpd      = ((CPU_FP32)(tx_curr      - Probe_RS232TxLast)      / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;
        Probe_ComRxPktSpd     = ((CPU_FP32)(rxpkt_curr   - Probe_ComRxPktLast)     / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;
        Probe_ComTxPktSpd     = ((CPU_FP32)(txpkt_curr   - Probe_ComTxPktLast)     / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;
        Probe_ComTxSymSpd     = ((CPU_FP32)(sym_curr     - Probe_ComTxSymLast)     / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;
        Probe_ComTxSymByteSpd = ((CPU_FP32)(symbyte_curr - Probe_ComTxSymByteLast) / (ctr_curr - Probe_ComCtrLast)) * OS_TICKS_PER_SEC;

        Probe_ComCtrLast       = ctr_curr;
        Probe_RS232RxLast      = rx_curr;
        Probe_RS232TxLast      = tx_curr;
        Probe_ComRxPktLast     = rxpkt_curr;
        Probe_ComTxPktLast     = txpkt_curr;
        Probe_ComTxSymLast     = sym_curr;
        Probe_ComTxSymByteLast = symbyte_curr;
    }
#endif
}
#endif


/*
*********************************************************************************************************
*                                      FORMAT A DECIMAL VALUE
*
* Description: This function converts a decimal value to ASCII (with leading zeros)
*
* Arguments  : 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;
    }
}


/*
*********************************************************************************************************
*                                   APPLICATION-DEFINED HOOKS
*
* Description: These functions are called by the hooks in os_cpu_c.c.
*
* Returns    : none
*********************************************************************************************************
*/

#if (OS_APP_HOOKS_EN > 0)
void  App_TaskCreateHook (OS_TCB *ptcb)
{
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN > 0)
    OSProbe_TaskCreateHook(ptcb);
#endif
}


void  App_TaskDelHook (OS_TCB *ptcb)
{
    (void)ptcb;
}


#if OS_VERSION >= 251
void  App_TaskIdleHook (void)
{
}
#endif


void  App_TaskStatHook (void)
{
}


#if OS_TASK_SW_HOOK_EN > 0
void  App_TaskSwHook (void)
{
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN > 0)
    OSProbe_TaskSwHook();
#endif
}
#endif


#if OS_VERSION >= 204
void  App_TCBInitHook (OS_TCB *ptcb)
{
    (void)ptcb;
}
#endif


#if OS_TIME_TICK_HOOK_EN > 0
void  App_TimeTickHook (void)
{
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN > 0)
    OSProbe_TickHook();
#endif
}
#endif
#endif

⌨️ 快捷键说明

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