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

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

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

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

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

/*
*********************************************************************************************************
*                                    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 OS_VIEW_MODULE > 0
    OSView_Init(38400);                                         /* OSView Init, baud rate = 38400                           */
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                                           /* Enable Rx Interrupts                                     */
#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
}


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

    DispInit(2, 16);                                           	/* Initialize the LCD module                                */

⌨️ 快捷键说明

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