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

📄 app.c

📁 官方的UCOSii的移植文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                              EXAMPLE CODE
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                             EXAMPLE CODE
*
*                                             NXP LPC2378
*                                                on the
*                                      Keil MCB2300 Evaluation Board
*
* Filename      : app_cfg.h
* Version       : V1.00
* Programmer(s) : BAN
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

                                                                /* ----------------- APPLICATION GLOBALS ------------------ */
static  OS_STK       AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK       AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE];
static  OS_STK       AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];

static  OS_EVENT    *AppUserIFMbox;
static  CPU_CHAR     AppLCDLine1[17];
static  CPU_CHAR     AppLCDLine2[17];

                                                                /* -------------- uC/PROBE RELATED GLOBALS ---------------- */
#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
static  OS_STK       AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE];
#endif

#if (uC_PROBE_OS_PLUGIN    > 0) && \
    (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
static  CPU_FP32     Probe_RS232RxSpd;
static  CPU_FP32     Probe_RS232TxSpd;
static  CPU_FP32     Probe_ComRxPktSpd;
static  CPU_FP32     Probe_ComTxPktSpd;
static  CPU_FP32     Probe_ComTxSymSpd;
static  CPU_FP32     Probe_ComTxSymByteSpd;

static  CPU_INT32U   Probe_RS232RxLast;
static  CPU_INT32U   Probe_RS232TxLast;
static  CPU_INT32U   Probe_ComRxPktLast;
static  CPU_INT32U   Probe_ComTxPktLast;
static  CPU_INT32U   Probe_ComTxSymLast;
static  CPU_INT32U   Probe_ComTxSymByteLast;

static  CPU_INT32U   Probe_ComCtrLast;
#endif


#if (uC_PROBE_OS_PLUGIN > 0)
static  CPU_INT32U   Probe_Counts;
static  CPU_BOOLEAN  Probe_B1;
static  CPU_INT16U   Probe_ADC;
#endif

/*
*********************************************************************************************************
*                                        LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void  AppTaskStart              (void        *p_arg);
static  void  AppTaskCreate             (void);

static  void  AppTaskKbd                (void        *p_arg);
static  void  AppTaskUserIF             (void        *p_arg);
static  void  AppDispScr_SignOn         (void);
static  void  AppDispScr_VersionTickRate(void);
static  void  AppDispScr_CPU            (void);
static  void  AppDispScr_CtxSw          (void);

#if (uC_PROBE_OS_PLUGIN > 0)
static  void  AppProbeCallback          (void);
#endif

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
static  void  AppTaskProbeStr           (void        *p_arg);
#endif

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

/*
*********************************************************************************************************
*                                    LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary initialization.
*
* Argument(s) : none
*
* Return(s)   : none
*********************************************************************************************************
*/

int  main (void)
{
    CPU_INT08U  err;


    BSP_IntDisAll();                                            /* Disable all interrupts until we are ready to accept them */

    OSInit();                                                   /* Initialize "uC/OS-II, The Real-Time Kernel"              */

    OSTaskCreateExt(AppTaskStart,                               /* Create the start task                                    */
                    (void *)0,
                    (OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],
                    APP_TASK_START_PRIO,
                    APP_TASK_START_PRIO,
                    (OS_STK *)&AppTaskStartStk[0],
                    APP_TASK_START_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if (OS_TASK_NAME_SIZE > 13)
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif

    OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II)       */
}


/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task.  The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' 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.
*
*               (2) Interrupts are enabled once the task starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppTaskStart (void *p_arg)
{
    CPU_INT08U  i;
    CPU_INT16U  dly;


    (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                                 */

#if OS_TASK_STAT_EN > 0
    OSStatInit();                                               /* Determine CPU capacity                                   */
#endif

#if uC_PROBE_OS_PLUGIN > 0
    (void)Probe_Counts;
    (void)Probe_ADC;
    (void)Probe_B1;

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_STAT_EN     > 0)
    (void)Probe_RS232RxSpd;
    (void)Probe_RS232TxSpd;
    (void)Probe_ComRxPktSpd;
    (void)Probe_ComTxPktSpd;
    (void)Probe_ComTxSymSpd;
    (void)Probe_ComTxSymByteSpd;

    (void)Probe_RS232RxLast;
    (void)Probe_RS232TxLast;
    (void)Probe_ComRxPktLast;
    (void)Probe_ComTxPktLast;
    (void)Probe_ComTxSymLast;
    (void)Probe_ComTxSymByteLast;

    (void)Probe_ComCtrLast;
#endif

    OSProbe_Init();
    OSProbe_SetCallback(AppProbeCallback);
    OSProbe_SetDelay(50);
#endif

#if (uC_PROBE_COM_MODULE > 0)
    ProbeCom_Init();                                            /* Initialize the uC/Probe communications module            */
    ProbeRS232_Init(115200);
    ProbeRS232_RxIntEn();
#endif


    AppUserIFMbox = OSMboxCreate((void *)0);                    /* Create MBOX for communication between Kbd and UserIF     */
    AppTaskCreate();                                            /* Create application tasks                                 */

    dly = (ADC_GetStatus(0) >> 6) + 10;

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */

        for (i = 1; i <= 8; i++) {
            LED_On(i);
            OSTimeDlyHMSM(0, 0, 0, dly);
            LED_Off(i);
            dly = (ADC_GetStatus(0) >> 6) + 10;
        }

        for (i = 1; i <= 8; i++) {
            LED_On(9 - i);
            OSTimeDlyHMSM(0, 0, 0, dly);
            LED_Off(9 - i);
            dly = (ADC_GetStatus(0) >> 6) + 10;
        }
    }
}


/*
*********************************************************************************************************
*                                      AppTaskCreate()
*
* Description :  Create the application tasks.
*
* Argument(s) :  none.
*
* Return(s)   :  none.
*********************************************************************************************************
*/

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

#if (uC_PROBE_COM_MODULE   > 0) && \
    (PROBE_COM_SUPPORT_STR > 0)
    OSTaskCreateExt(AppTaskProbeStr,
                    (void *)0,
                    (OS_STK *)&AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE - 1],
                    APP_TASK_PROBE_STR_PRIO,
                    APP_TASK_PROBE_STR_PRIO,
                    (OS_STK *)&AppTaskProbeStrStk[0],
                    APP_TASK_PROBE_STR_STK_SIZE,
                    (void *)0,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if (OS_TASK_NAME_SIZE > 9)
    OSTaskNameSet(APP_TASK_PROBE_STR_PRIO, "Probe Str", &err);
#endif
#endif
}


/*
*********************************************************************************************************
*                                    AppTaskKbd()
*
* Description : Monitor the state of the push buttons and passes messages to AppTaskUserIF()
*
* Argument(s) : p_arg       Argument passed to 'AppTaskKbd()' 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.
*********************************************************************************************************
*/
static  void  AppTaskKbd (void *p_arg)
{
    CPU_BOOLEAN  b1;                                            /* State of Push Button #1                                  */
    CPU_BOOLEAN  b1_prev;
    CPU_INT08U   key;


    (void)p_arg;

    key     = 2;
    b1_prev = DEF_FALSE;

    while (DEF_TRUE) {

        b1  = PB_GetStatus(1);

        if (b1 == DEF_TRUE && b1_prev == DEF_FALSE) {
            if (key == 4) {
                key = 1;
            } else {
                key++;
            }
            OSMboxPost(AppUserIFMbox, (void *)key);
        }

        b1_prev = b1;
        OSTimeDly(OS_TICKS_PER_SEC / 20);
    }
}


/*
*********************************************************************************************************
*                                    AppTaskUserIF()
*
* Description : Updates LCD.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskUserIF()' 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.
*********************************************************************************************************
*/

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


    (void)p_arg;

⌨️ 快捷键说明

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