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

📄 app.c

📁 LPC2106开发板上面的uCOS移植代码最新版2.83
💻 C
字号:
/*
*********************************************************************************************************
*
*                                             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 LPC2106
*                                                on the
*                                        IAR LPC210x Kickstart Card
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

#include <includes.h>


/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/

OS_STK      AppTaskStartStk[APP_TASK_START_STK_SIZE];

static  CPU_INT08U  EINT_Char;
static  OS_EVENT   *EINT_Mbox;


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

static  void  AppTaskStart(void *p_arg);

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

static  void   EINT1_ISRHandler(void);
static  void   EINT2_ISRHandler(void);


/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.
*
* Arguments   : none
*********************************************************************************************************
*/

void  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, "Startup", &err);
#endif

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


/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
* Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppTaskStart (void *p_arg)
{
    CPU_INT08U   i;
    CPU_INT16U   delay;
    CPU_INT08U  *msg;
    CPU_INT08U   value;


    (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(19200);
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                                           /* Enable Rx Interrupts                                     */
#endif

    EINT_Mbox = OSMboxCreate((void *)0);                        /* Create mailbox for PB control of user IF                 */
    delay       = 50;                                           /* Initialize delay time                                    */
    PB_EINT1_Init(EINT1_ISRHandler);                            /* Initialize external interrupt EINT1                      */
    PB_EINT2_Init(EINT2_ISRHandler);                            /* Initialize external interrupt EINT2                      */

    LED_On(13);
    LED_On(14);
    LED_On(15);
    LED_On(16);

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        for (i = 1; i <= 16; i++) {
            LED_On(i);                                          /* Turn on next light                                       */
            LED_Off(16 - (22 - i) % 16);                        /* Turn off 5th last light                                  */

            msg = (CPU_INT08U *)OSMboxAccept(EINT_Mbox);        /* Retrieve message from mailbox                            */
            if (msg != (CPU_INT08U *)0) {                       /*  ... If there is a message ...                           */
                value = *msg;                                   /*  ... Then store the message ...                          */
                if (value == 1) {                               /*  ... If the message is 1 ...                             */
                    if (delay > 5) {
                        delay -= 5;                             /*  ... Then decrease the delay by 5 ms ...                 */
                    }
                } else {                                        /*  ... Else if message is not 1 ...                        */
                    delay += 5;                                 /*  ... Then increase the delay by 5 ms.                    */
                }
            }

            OSTimeDlyHMSM(0, 0, 0, delay);                      /* Delay task                                               */
        }
    }
}


/*
*********************************************************************************************************
*                                      TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/

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


/*
*********************************************************************************************************
*                                      EXTERNAL INTERRUPT ISRs
*
* Description:  These functions are the ISR handlers for External INTerrupts 1 and 2, respectively, which
*               are connected to push buttons 2 and 4.
*
* Argument(s):  none
*
* Returns    :  none
*********************************************************************************************************
*/

static  void  EINT1_ISRHandler (void)
{
    EINT_Char    = 1;
    OSMboxPost(EINT_Mbox, &EINT_Char);
    EXTINT      |= 0x07;
    VICVectAddr  = 0;
}

static  void  EINT2_ISRHandler (void)
{
    EINT_Char    = 2;
    OSMboxPost(EINT_Mbox, &EINT_Char);
    EXTINT      |= 0x07;
    VICVectAddr  = 0;
}

⌨️ 快捷键说明

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