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

📄 app.c

📁 官方的UCOSii的移植文件
💻 C
📖 第 1 页 / 共 2 页
字号:
    DispInit(2, 16);                                           	/* Initialize the LCD module                                */

    AppDispScr_SignOn();
    OSTimeDly(OS_TICKS_PER_SEC);
    pstate = 1;
    nstate = 2;


    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        msg = (CPU_INT08U *)(OSMboxPend(AppUserIFMbox, OS_TICKS_PER_SEC / 10, &err));
        if (err == OS_NO_ERR) {
            nstate = (CPU_INT32U)msg;
        }

        if (nstate != pstate) {
            pstate = nstate;
            DispClrScr();
        }

        switch (pstate) {
            case 2:
                 AppDispScr_VersionTickRate();
                 break;

            case 3:
                 AppDispScr_CPU();
                 break;

            case 4:
                 AppDispScr_CtxSw();
                 break;

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

/*
*********************************************************************************************************
*                                            DISPLAY SCREENS
*
* Descrition  : Display one of the screens used in the demonstration.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  AppDispScr_SignOn (void)
{
    Str_Copy(AppLCDLine1, "Micrium uC/OS-II");
    Str_Copy(AppLCDLine2, "  NXP  LPC2378  ");

    DispStr(0, 0, AppLCDLine1);
    DispStr(1, 0, AppLCDLine2);
}

static  void  AppDispScr_VersionTickRate (void)
{
    CPU_INT32U  value;


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

    Str_Copy(AppLCDLine2, "TickRate:   xxxx");
    value           = (CPU_INT32U)OS_TICKS_PER_SEC;
    AppFormatDec(&AppLCDLine2[12], value, 4);
    DispStr(1, 0, AppLCDLine2);
}

static  void  AppDispScr_CPU (void)
{
    CPU_INT32U  value;


    Str_Copy(AppLCDLine1, "CPU Usage:xx %  ");
    value           = (CPU_INT32U)OSCPUUsage;
    AppLCDLine1[10] = (value / 10) + '0';
    AppLCDLine1[11] = (value % 10) + '0';
    DispStr(0, 0, AppLCDLine1);

    Str_Copy(AppLCDLine2, "CPU Speed:xx MHz");
    value           = (CPU_INT32U)BSP_CPU_ClkFreq() / 1000000L;
    AppLCDLine2[10] = (value / 10) + '0';
    AppLCDLine2[11] = (value % 10) + '0';
    DispStr(1, 0, AppLCDLine2);
}

static  void  AppDispScr_CtxSw (void)
{
    CPU_INT32U  value;


    Str_Copy(AppLCDLine1, "#Ticks: xxxxxxxx");
    value = (CPU_INT32U)OSTime;
    AppFormatDec(&AppLCDLine1[8], value, 8);
    DispStr(0, 0, AppLCDLine1);

    Str_Copy(AppLCDLine2, "#CtxSw: xxxxxxxx");
    value = (CPU_INT32U)OSCtxSwCtr;
    AppFormatDec(&AppLCDLine2[8], value, 8);
    DispStr(1, 0, AppLCDLine2);
}


/*
*********************************************************************************************************
*                                         AppTaskProbeStr()
*
* Description : Output strings via the uC/Probe general communication module.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskProbeStr()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/

#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];


    (void)p_arg;

    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


/*
*********************************************************************************************************
*                                         AppProbeCallback()
*
* Description : This function is called by the uC/Probe uC/OS-II plug-in after updating task information.
*
* Argument(s) : none.
*
* Return(s)   : 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

    Probe_Counts++;

    Probe_ADC = (ADC_GetStatus(0) * 100) / 0x03FF;
    Probe_B1  = PB_GetStatus(1);

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
    ctr_curr     = OSTime;
    rx_curr      = ProbeRS232_RxCtr;
    tx_curr      = ProbeRS232_TxCtr;
    rxpkt_curr   = ProbeCom_RxPktCtr;
    txpkt_curr   = ProbeCom_TxPktCtr;
    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


/*
*********************************************************************************************************
*                                      AppFormatDec()
*
* Description : Convert a decimal value to ASCII (with leading zeros).
*
* Argument(s) : s           Pointer to the destination ASCII string.
*               value       Value to convert (assumes an unsigned value).
*               digits      The desired number of digits.
*
* Return(s)   : 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;
    }
}


/*
*********************************************************************************************************
*********************************************************************************************************
**                                         uC/OS-II APP HOOKS
*********************************************************************************************************
*********************************************************************************************************
*/

#if (OS_APP_HOOKS_EN > 0)
/*
*********************************************************************************************************
*                                      TASK CREATION HOOK (APPLICATION)
*
* Description : This function is called when a task is created.
*
* Argument(s) : ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)     : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/

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

/*
*********************************************************************************************************
*                                    TASK DELETION HOOK (APPLICATION)
*
* Description : This function is called when a task is deleted.
*
* Argument(s) : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)     : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/

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

/*
*********************************************************************************************************
*                                      IDLE TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskIdleHook(), which is called by the idle task.  This hook
*               has been added to allow you to do such things as STOP the CPU to conserve power.
*
* Argument(s) : none.
*
* Note(s)     : (1) Interrupts are enabled during this call.
*********************************************************************************************************
*/

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

/*
*********************************************************************************************************
*                                        STATISTIC TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
*               statistics task.  This allows your application to add functionality to the statistics task.
*
* Argument(s) : none.
*********************************************************************************************************
*/

void  App_TaskStatHook (void)
{
}

/*
*********************************************************************************************************
*                                        TASK SWITCH HOOK (APPLICATION)
*
* Description : This function is called when a task switch is performed.  This allows you to perform other
*               operations during a context switch.
*
* Argument(s) : none.
*
* Note(s)     : (1) Interrupts are disabled during this call.
*
*               (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                   will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
*                  task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/

#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

/*
*********************************************************************************************************
*                                     OS_TCBInit() HOOK (APPLICATION)
*
* Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
*               up most of the TCB.
*
* Argument(s) : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)     : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/

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

/*
*********************************************************************************************************
*                                        TICK HOOK (APPLICATION)
*
* Description : This function is called every tick.
*
* Argument(s) : none.
*
* Note(s)     : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/

#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 + -