📄 app.c
字号:
/*
*************************************************************************************************************
* APPLICATION SPECIFIC SAMPLE CODE
*
* (c) Copyright 2005, Micrium, Weston, FL
* All Rights Reserved
*
* File : APP.C
* By : Jean J. Labrosse
*************************************************************************************************************
*/
#include <includes.h>
/*
**************************************************************************************************************
* VARIABLES
**************************************************************************************************************
*/
INT32U AppTickISRCtr;
OS_STK AppTaskStartStk[OS_TASK_START_STK_SIZE];
OS_STK AppTask1Stk[OS_TASK_1_STK_SIZE];
OS_STK AppTask2Stk[OS_TASK_2_STK_SIZE];
/*
**************************************************************************************************************
* FUNCTION PROTOTYPES
**************************************************************************************************************
*/
void main(void);
static void AppTaskStart(void *p_arg);
static void AppTaskCreate(void);
static void AppTask1(void *p_arg);
static void AppTask2(void *p_arg);
static void AppTickInit(void);
/*
**************************************************************************************************************
* MAIN
**************************************************************************************************************
*/
void main (void)
{
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
OSTaskStkSize = OS_TASK_IDLE_STK_SIZE; /* Setup the Idle and Statistics Task sizes */
OSTaskStkSizeHard = OS_TASK_IDLE_STK_SIZE_HARD;
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTaskStkSize = OS_TASK_START_STK_SIZE;
OSTaskStkSizeHard = OS_TASK_START_STK_SIZE_HARD;
OSTaskCreateExt(AppTaskStart,
(void *)0,
(OS_STK *)&AppTaskStartStk[OSTaskStkSize - 1],
OS_TASK_START_PRIO,
OS_TASK_START_PRIO,
(OS_STK *)&AppTaskStartStk[OSTaskStkSizeHard],
OSTaskStkSize - OSTaskStkSizeHard,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
/*---- Create any other task you want before we start multitasking --------------------------------*/
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 'AppTaskStart()' 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.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
(void)p_arg; /* Prevent compiler warnings */
BSP_Init(); /* Initialize the Board Support Package */
AppTickInit(); /* Initialize the tick interrupts needed by uC/OS-II */
AppTaskCreate(); /* Create other application tasks */
while (TRUE) { /* Task body, always written as an infinite loop. */
LED_Toggle(6);
OSTimeDly(OS_TICKS_PER_SEC / 10);
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
OSTaskStkSize = OS_TASK_1_STK_SIZE;
OSTaskStkSizeHard = OS_TASK_1_STK_SIZE_HARD;
OSTaskCreateExt(AppTask1,
(void *)0,
(OS_STK *)&AppTask1Stk[OSTaskStkSize - 1],
OS_TASK_1_PRIO,
OS_TASK_1_PRIO,
(OS_STK *)&AppTask1Stk[OSTaskStkSizeHard],
OSTaskStkSize - OSTaskStkSizeHard,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskStkSize = OS_TASK_2_STK_SIZE;
OSTaskStkSizeHard = OS_TASK_2_STK_SIZE_HARD;
OSTaskCreateExt(AppTask2,
(void *)0,
(OS_STK *)&AppTask2Stk[OSTaskStkSize - 1],
OS_TASK_2_PRIO,
OS_TASK_2_PRIO,
(OS_STK *)&AppTask2Stk[OSTaskStkSizeHard],
OSTaskStkSize - OSTaskStkSizeHard,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
}
/*
*********************************************************************************************************
* TASK #1
*********************************************************************************************************
*/
static void AppTask1 (void *p_arg)
{
(void)p_arg;
while (TRUE) {
LED_Toggle(7);
OSTimeDly(OS_TICKS_PER_SEC / 5);
}
}
/*
*********************************************************************************************************
* TASK #2
*********************************************************************************************************
*/
static void AppTask2 (void *p_arg)
{
(void)p_arg;
while (TRUE) {
LED_Toggle(8);
OSTimeDly(OS_TICKS_PER_SEC / 2);
}
}
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
* interrupts every 1 to 100 mS).
*
* Arguments : none
*********************************************************************************************************
*/
static void AppTickInit (void)
{
AppTickISRCtr = 0;
TCCR0 = 0x0F;
TCNT0 = 0; /* Start TCNT at 0 for a new cycle */
OCR0 = CPU_CLK_FREQ / OS_TICKS_PER_SEC / 1024 - 1;
TIFR |= 0x02; /* Clear TIMER0 compare Interrupt Flag */
TIMSK |= 0x02; /* Enable TIMER0 compare Interrupt */
}
/*
*********************************************************************************************************
* TIMER #0 IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*
* Note(s) : 1) There is no need to clear the interrupt since this is done automatically in Output
* Compare mode when the ISR is executed.
*********************************************************************************************************
*/
void AppTickISR_Handler (void)
{
AppTickISRCtr++;
OSTimeTick(); /* If the interrupt is from the tick source, call OSTimeTick() */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -