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

📄 app.c

📁 ucOS_9263_Source ucOS-ii for 9263 port,from Micrium.com
💻 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
*
*                                          Atmel AT91SAM9263
*                                                on the
*                                  Atmel AT91SAM9263-EK Evaluation Board
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

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

static  OS_STK          AppTaskStartStk[APP_TASK_START_STK_SIZE];

#if (OS_VIEW_MODULE == 0) || (OS_VIEW_COMM_SEL != SER_COMM_SEL)
static  OS_STK          AppTaskSerStk[APP_TASK_SER_STK_SIZE];
static  OS_STK          AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];

static  CPU_INT08U      AppUserIFState;                         /* User I/F state                                           */
static  OS_EVENT       *AppUserIFMbox;

static  CPU_CHAR        AppSerStr[80];
#endif

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

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

#if (OS_VIEW_MODULE == 0) || (OS_VIEW_COMM_SEL != SER_COMM_SEL)
static  void            AppTaskSer                  (void *p_arg);
static  void            AppTaskKbd                  (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);
#endif

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


/*
*********************************************************************************************************
*                                                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.
*
* Arguments   : none
*
* Returns     : 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, "Start Task", &err);
#endif

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

/*$PAGE*/
/*
*********************************************************************************************************
*                                              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()'.
*
* Notes       : 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 start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

static  void  AppTaskStart (void *p_arg)
{
    CPU_INT08U  pb1_last;
    CPU_INT08U  pb2_last;


    (void)p_arg;                                                /* Prevent compiler warning                                 */


    BSP_Init();                                                 /* Initialize the BSP                                       */

#if (OS_TASK_STAT_EN > 0)
    OSStatInit();                                               /* Start stats task                                         */
#endif

#if OS_VIEW_MODULE > 0
    OSView_Init(115200);                                        /* OSView Init, baud rate = 115200                          */
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                                           /* Enable Rx Interrupts                                     */
#endif

#if (OS_VIEW_MODULE == 0) || (OS_VIEW_COMM_SEL != SER_COMM_SEL)
    Ser_Init();
    AppUserIFState  = 0;
    AppUserIFMbox   = OSMboxCreate((void *)0);                  /* Create MBOX for communication between Kbd and Ser        */
#endif

    LED_Off(0);                                                 /* Turn off ALL the LEDs                                    */

    AppTaskCreate();                                            /* Create application tasks                                 */

    pb1_last = PB_GetStatus(1);
    pb2_last = PB_GetStatus(2);

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.           */
        if (PB_GetStatus(1) == DEF_TRUE) {
            if (pb1_last == DEF_FALSE) {
                LED_Toggle(1);
                pb1_last = DEF_TRUE;
            }
        } else if( pb1_last == DEF_TRUE) {
            pb1_last = DEF_FALSE;
        }

        if (PB_GetStatus(2) == DEF_TRUE) {
            if (pb2_last == DEF_FALSE) {
                LED_Toggle(2);
                pb2_last = DEF_TRUE;
            }
        } else if (pb2_last == DEF_TRUE) {
            pb2_last = DEF_FALSE;
        }

        OSTimeDlyHMSM(0, 0, 0, 50);
    }
}

/*
*********************************************************************************************************
*                                         RS-232 OUTPUT TASK
*
* Description : This task outputs information through the RS-232 port.
*
* Arguments   : p_arg   is the argument passed to 'AppTaskSer()' by 'OSTaskCreate()'.
*
* Returns     : none
*********************************************************************************************************
*/

#if (OS_VIEW_MODULE == 0) || (OS_VIEW_COMM_SEL != SER_COMM_SEL)
static  void  AppTaskSer (void *p_arg)
{
    CPU_INT08U     *msg;
    CPU_INT08U      err;
    CPU_INT32U      pstate;
    CPU_INT32U      nstate;


    (void)p_arg;

    Ser_WrStr("\n\n\r");
    AppDispScr_SignOn();
    OSTimeDlyHMSM(0, 0, 1, 0);
    Ser_WrStr("\n\n\r");
    nstate               = 1;


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

        msg = (CPU_INT08U *)(OSMboxPend(AppUserIFMbox, OS_TICKS_PER_SEC / 10, &err));
        if (err == OS_NO_ERR) {
            if (msg != (CPU_INT08U *)0) {
                nstate = *msg;
            }
        }

        if (nstate != pstate) {
            Ser_WrStr("\n\n");
        }

        switch (nstate) {
            case 1:
                 AppDispScr_VersionTickRate();
                 break;

            case 2:
                 AppDispScr_CPU();

⌨️ 快捷键说明

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