📄 app.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
*
* 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];
static OS_STK AppTaskBootloaderStk[APP_TASK_BOOTLOADER_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
extern void AppBoot (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
/*
*********************************************************************************************************
* 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 err;
(void)p_arg; /* Prevent compiler warning */
BSP_Init(); /* Initialize the BSP */
SDRAM_Init(); /* Initialize the external SDRAM */
#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 (DEF_TRUE) { /* Task body, always written as an infinite loop. */
LED_Toggle(1);
OSTimeDlyHMSM(0, 0, 0, 20);
}
}
/*
*********************************************************************************************************
* uC/OS-VIew Terminal Window Callback
*
* Description : This is the callback function for uC/OS-View
*
* Arguments : rx_data is the received data.
*
* Returns : none
*********************************************************************************************************
*/
#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 = APP_BOOT_RETRIES; /* Set maximum number of boot attempts */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
result = load_df(AT91C_SPI_PCS0_DATAFLASH, APP_IMG_ADDR, APP_IMG_SIZE, APP_DEST_ADDR);
if (result != 0) { /* If an error occured, delay and then try again */
OSTimeDlyHMSM(0, 0, 0, 20);
if (retries > 0) {
retries--;
continue;
} else {
while (DEF_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 */
AppBoot(APP_DEST_ADDR); /* Boot the application from external RAM, does not return! */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -