app.c
来自「在IAR EWARM开发环境下的ucos_2操作系统在LPC2200上的应用」· C语言 代码 · 共 204 行
C
204 行
/*
*********************************************************************************************************
* 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 LPC2103
* on the
* IAR LPC2103-01-SK Evaluation Board
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : FT
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define APP_LCD_SCR_SIGN_ON 1
#define APP_LCD_SCR_VER_TICK_RATE 2
#define APP_LCD_SCR_CPU 3
#define APP_LCD_SCR_CTXSW 4
#define APP_LCD_SCR_BOARD_INFO 5
#define APP_LCD_SCR_FIRST APP_LCD_SCR_SIGN_ON
#define APP_LCD_SCR_LAST APP_LCD_SCR_BOARD_INFO
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS ------------------ */
static OS_STK App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
#define TASK_STK_SIZE 200 /* Size of each task's stacks (# of WORDs) */
OS_STK Task1Stk[TASK_STK_SIZE];
OS_STK Task2Stk[TASK_STK_SIZE];
void Task1(void *pdata);
void Task2(void *pdata);
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void App_TaskStart (void *p_arg);
/*
*********************************************************************************************************
* 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.
*
* Argument(s) : none
*
* Return(s) : none
*********************************************************************************************************
*/
int 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" */
OSTaskCreate(Task1, (void *)0, &Task1Stk[TASK_STK_SIZE - 1], 3);
OSTaskCreate(Task2, (void *)0, &Task2Stk[TASK_STK_SIZE - 1], 4);
OSTaskCreateExt((void (*)(void *)) App_TaskStart, /* Create the start task */
(void *) 0,
(OS_STK *)&App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
(INT8U ) APP_CFG_TASK_START_PRIO,
(INT16U ) APP_CFG_TASK_START_PRIO,
(OS_STK *)&App_TaskStartStk[0],
(INT32U ) APP_CFG_TASK_START_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
#if (OS_TASK_NAME_SIZE > 5)
OSTaskNameSet(APP_CFG_TASK_START_PRIO, "Start", &err);
OSTaskNameSet(3, "Task1", &err);
OSTaskNameSet(4, "Task2", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*
*********************************************************************************************************
* AppTaskStart()
*
* Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (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 starts because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void App_TaskStart (void *p_arg)
{
CPU_INT08U i;
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity */
#endif
BSP_LED_Off(0); /* Turn OFF all the LEDs */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
for (i = 1; i <= 16; i++) {
BSP_LED_Off(i - 1);
OSTimeDlyHMSM(0, 0, 0, 50);
BSP_LED_On(i);
OSTimeDlyHMSM(0, 0, 0, 50);
}
}
}
void Task2(void *pdata)
{
INT8U j=0;
for (;;)
{
j++;
puts("Task2 running.\r\n");
BSP_LED_Off(0);
BSP_LED_On(0);
if(j==2)
{
OSTaskSuspend(3);
puts("\rTask1 Suspend.\n");
BSP_LED_On(0);
}
if(j==3)
{
OSTaskResume(3);
puts("\rTask1 Resume.\n");
BSP_LED_On(0);
}
if(j==4)
{
OSTaskDel(3);
puts("\rTask1 Delete.\n");
BSP_LED_On(0);
j=0;
}
OSTimeDly(60);
}
}
void Task1(void *pdata)
{
while(1)
{
puts("Task1 running.\r\n");
BSP_LED_Off(0);
OSTimeDly(60);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?