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

📄 app.c

📁 uCOS-II 2.8和uC-TCP/IP在ATMEL AT91SAM9261上移植
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                                 (c) Copyright 2004, Micrium, Weston, FL
*                                          All Rights Reserved
*
*                                              AT91SAM9261
*                                              Sample code
* File : APP.C
* By   : Eric Shufro
*********************************************************************************************************
*/

#include <includes.h>

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

static  OS_STK  AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK  AppTaskBootloaderStk[APP_TASK_BOOTLOADER_STK_SIZE];

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

extern  void  Boot(CPU_INT32U  Addr);
static  void  AppTaskStart(void *p_arg);
static  void  AppTaskBootloader(void *p_arg);

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

/*
*********************************************************************************************************
*                                             C ENTRY POINT
*********************************************************************************************************
*/

int  main (void)
{
    CPU_INT08U err;


    BSP_IntDisAll();                                                    /* Disable ALL interrupts to the interrupt controller       */

    OSInit();                                                           /* Initialize uC/OS-II                                      */

                                                                        /* Create start task                                        */
    OSTaskCreateExt(AppTaskStart,
                    NULL,
                    (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,
                    NULL,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

                                                                        /* Assign names to created tasks                            */
#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif
   
    OSStart();                                                          /* Start 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 err;
    
    
    (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(38400);                                                 /* OSView Init, baud rate = 38400                           */
    OSView_TerminalRxSetCallback(AppTerminalRx);
    OSView_RxIntEn();                                                   /* Enable Rx Interrupts                                     */
#endif

    OSTaskCreateExt(AppTaskBootloader,                                  /* Create boot loader task                                  */
                    NULL,
                    (OS_STK *)&AppTaskBootloaderStk[APP_TASK_BOOTLOADER_STK_SIZE - 1],
                    APP_TASK_BOOTLOADER_PRIO,
                    APP_TASK_BOOTLOADER_PRIO,
                    (OS_STK *)&AppTaskBootloaderStk[0],
                    APP_TASK_BOOTLOADER_STK_SIZE,
                    NULL,
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

                                                                        /* Assign names to created tasks                            */
#if OS_TASK_NAME_SIZE > 11
    OSTaskNameSet(APP_TASK_BOOTLOADER_PRIO, "Boot Loader", &err);
#endif
    
    LED_Off(0);                                                         /* Turn off ALL the LEDs                                    */

    while (TRUE) {                                                      /* Task body, always written as an infinite loop.           */
        LED_Toggle(1);
        OSTimeDlyHMSM(0, 0, 0, 20);
    }
}

/*
*********************************************************************************************************
*                                     uC/OS-View TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/

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

/*
*********************************************************************************************************
*                                              BOOT LOADER TASK
*
* Description : This task drives the boot loading process. It copies the specified number of bytes from 
*               the specified source medium to external RAM. The boot loader terminates after the call
*               to Boot().
*
* 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) Always be aware of the boot loader image size (check the binary file size). 
*                  It must not surpass the start address of the application in dataflash, 
*                  0x8000. See macro: IMG_ADDRESS in app_cfg.h.
*
*               3) NAND Flash booting is still under development.
*********************************************************************************************************
*/

static  void  AppTaskBootloader (void *p_arg)
{
    CPU_SR      cpu_sr;
    CPU_INT08S  result;
    CPU_INT08U  retries;
    
    
    retries = BOOT_RETRIES;                                             /* Set maximum number of boot attempts                      */
    
    while (TRUE) {                                                      /* Task body, always written as an infinite loop.           */
        switch (BOOT_FROM) {
            case DATAFLASH:
            	 result = load_df(AT91C_SPI_PCS0_DATAFLASH, IMG_ADDRESS, IMG_SIZE, COPY_TO_ADDR);
                 break;
                 
            case NANDFLASH:
            	 result = load_nandflash(IMG_ADDRESS, IMG_SIZE, COPY_TO_ADDR);                
                 break;  
                 
            default:                  
                 break;
        }            
	   
        if (result != 0) {                                              /* If an error occured, delay and then try again            */
            OSTimeDlyHMSM(0, 0, 0, 20);
            if (retries > 0) {
                retries--;
                continue;
            } else {
                while (TRUE) {
                    OSTimeDlyHMSM(0, 0, 0, 100);
                }
            }
        }
        
        CPU_CRITICAL_ENTER();                                           /* Disable global interrupts before loading new application */
       (void)cpu_sr;                                                    /* Prevent compiler warning that cpu_sr was set & not used  */
       
        Boot(COPY_TO_ADDR);                                             /* Boot the application from external RAM, does not return! */
    }
}

    


⌨️ 快捷键说明

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