📄 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
*
* 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 GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS ------------------ */
static OS_STK App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
/* -------------- uC/PROBE RELATED GLOBALS ---------------- */
#define TASK_STK_SIZE 100 /* Size of each task's stacks (# of WORDs) */
OS_STK Task10Stk[TASK_STK_SIZE];
OS_STK Task15Stk[TASK_STK_SIZE];
OS_STK Task20Stk[TASK_STK_SIZE];
INT8U cnt1=0,cnt2=0,cnt3=0;
OS_EVENT *ResourceMutex;
void TaskPrio10(void *pdata);
void TaskPrio15(void *i);
void TaskPrio20(void *i);
/*
*********************************************************************************************************
* 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" */
ResourceMutex=OSMutexCreate(9,&err);
OSTaskCreate(TaskPrio10, (void *)0,&Task10Stk[TASK_STK_SIZE - 1],10);
OSTaskCreate(TaskPrio15, (void *)0,&Task15Stk[TASK_STK_SIZE - 1],15);
OSTaskCreate(TaskPrio20, (void *)0,&Task20Stk[TASK_STK_SIZE - 1],20);
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(10, "Task_PRIO10", &err);
OSTaskNameSet(15, "Task_PRIO15", &err);
OSTaskNameSet(20, "Task_PRIO20", &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 TaskPrio10(void *pdata)
{
INT8U err;
for (;;)
{
OSMutexPend(ResourceMutex,0,&err);
cnt1++;
printf("\rTaskprio10 running. Taskprio10 count is %d\n",cnt1);
BSP_LED_Off (3);
OSMutexPost(ResourceMutex);
OSTimeDly(6);
}
}
void TaskPrio15(void *i)
{
INT8U err;
for (;;)
{
OSMutexPend(ResourceMutex,0,&err);
cnt2++;
printf("\rTaskprio15 running. Taskprio15 count is %d\n",cnt2);
BSP_LED_On (3);
OSMutexPost(ResourceMutex);
OSTimeDly(6);
}
}
void TaskPrio20(void *i)
{
INT8U err;
for (;;)
{
OSMutexPend(ResourceMutex,0,&err);
cnt3++;
OSTimeDly(60);
printf("\rTaskprio20 running.Taskprio20 count is %d\n",cnt3);
printf("\rNow the priority of Taskprio20 upgrades to %d\n",OSPrioCur);
BSP_LED_Off (0);
OSMutexPost(ResourceMutex);
OSTimeDly(6);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -