?? main.c
字號:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: Main.c
** Last modified Date: 2007.01.18
** Last Version: 1.0
** Description: The main function example template 主函數(shù)例子模版
**
**--------------------------------------------------------------------------------------------------------
** Created By: Steven Zhou 周紹剛
** Created date: 2007.01.18
** Version: 1.0
** Descriptions: The original version 初始版本
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao
** Modified date: 2007.10.29
** Version: 1.1
** Description: The second version 第二版
**
*********************************************************************************************************/
#include <includes.h>
/*********************************************************************************************************
CONSTANTS 常量
*********************************************************************************************************/
/*********************************************************************************************************
VARIABLES 變量
*********************************************************************************************************/
static OS_STK Task_StartStk[TASK_START_STK_SIZE]; /* The stack of start task */
/* 啟動任務(wù)的堆棧 */
static OS_STK Task_AStk[TASK_A_STK_SIZE];
static OS_STK Task_BStk[TASK_B_STK_SIZE];
OS_EVENT *DispMsg;
/*********************************************************************************************************
FUNCTION PROTOTYPES 函數(shù)聲明
*********************************************************************************************************/
static void taskStart (void *parg); /* The start task 啟動任務(wù) */
static void taskA (void *parg);
static void taskB (void *parg);
static void taskCreate (void);
/*********************************************************************************************************
** Function name: main
** Descriptions: uC/OS移植模板
** input parameters: 無
** output parameters: 無
** Returned value: 無
** Created by: Steven Zhou 周紹剛
** Created Date: 2007.01.18
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao 倪力考
** Modified date: 2007.10.29
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int main (void)
{
intDisAll(); /* Disable all the interrupts */
/* 關(guān)閉所有中斷 */
OSInit(); /* Initialize the kernel of uC */
/* OS-II 初始化uC/OS-II的內(nèi)核 */
OSTaskCreate ( taskStart,
(void *)0,
&Task_StartStk[TASK_START_STK_SIZE-1],
TASK_START_PRIO ); /* Initialize the start task */
/* 初始化啟動任務(wù) */
OSStart(); /* Start uC/OS-II 啟動uC/OS-II */
return(0) ;
}
/*********************************************************************************************************
** Function name: Task_Start
** Descriptions: Start task
** input parameters: *p_arg
** output parameters: 無
** Returned value: 無
** Created by: Steven Zhou 周紹剛
** Created Date: 2007.01.18
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao 倪力考
** Modified date: 2007.10.29
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
static void taskStart (void *parg)
{
(void)parg;
targetInit(); /* Initialize the target's MCU */
/* 初始化目標(biāo)單片機 */
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Enable statistics */
/* 使能統(tǒng)計功能 */
#endif
ledToggle(0xff);
OSTimeDly(OS_TICKS_PER_SEC / 2);
ledToggle(0xff);
OSTimeDly(OS_TICKS_PER_SEC / 2);
ledToggle(0xff);
/*
* Create the other tasks here. 在這里創(chuàng)建其他任務(wù)
*/
taskCreate();
while (1) {
OSTaskSuspend(OS_PRIO_SELF); /* The start task can be pended*/
/* here.啟動任務(wù)可在這里掛起 */
}
}
/*********************************************************************************************************
The other tasks 其他任務(wù)
*********************************************************************************************************/
/*
* Add the other tasks here . 在這里增加其他任務(wù)
*/
/*********************************************************************************************************
** Function name: taskCreate
** Descriptions: CREATE APPLICATION TASKS
** input parameters: 無
** output parameters: 無
** Returned value: 無
** Created by: maliang
** Created Date: 2007.04.17
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao 倪力考
** Modified date: 2007.10.29
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
static void taskCreate (void)
{
DispMsg = OSMboxCreate((void*)0);
OSTaskCreate (taskA, (void *)0,
&Task_AStk[TASK_A_STK_SIZE-1], TASK_A_PRIO);
OSTaskCreate (taskB, (void *)0,
&Task_BStk[TASK_B_STK_SIZE-1], TASK_B_PRIO);
}
/*********************************************************************************************************
** Function name: taskA
** Descriptions: The tasks A
** input parameters: *parg
** output parameters: 無
** Returned value: 無
** Created by: maliang
** Created Date: 2007.04.17
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao 倪力考
** Modified date: 2007.10.29
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
static void taskA(void *parg)
{
INT8U ucErr;
INT8U *ucMsg;
(void)parg;
while (1) {
ucMsg = OSMboxPend(DispMsg, 0, &ucErr);
ledToggle(*ucMsg);
}
}
/*********************************************************************************************************
** Function name: taskB
** Descriptions: The tasks B
** input parameters: *parg
** output parameters: 無
** Returned value: 無
** Created by: maliang
** Created Date: 2007.04.17
**--------------------------------------------------------------------------------------------------------
** Modified by: Ni Likao 倪力考
** Modified date: 2007.10.29
**-------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
static void taskB(void *parg)
{
INT8U ucKey, ucMsg;
(void)parg;
while (1) {
ucKey = keyRead( );
while (keyRead( ) != 0xFF) { /* 等待按鍵釋放,消除按鍵抖動 */
;
}
switch (ucKey) {
case 0xFE: /* KEY1按下 */
ucMsg = 1;
OSMboxPost(DispMsg, (void *)&ucMsg); /* 發(fā)送信號量 */
break;
case 0xFD: /* KEY2按下 */
ucMsg = 2;
OSMboxPost(DispMsg, (void *)&ucMsg); /* 發(fā)送信號量 */
break;
case 0xFB: /* KEY3按下 */
ucMsg = 3;
OSMboxPost(DispMsg, (void *)&ucMsg); /* 發(fā)送信號量 */
break;
case 0xF7: /* KEY4按下 */
ucMsg = 4;
OSMboxPost(DispMsg, (void *)&ucMsg); /* 發(fā)送信號量 */
break;
default:
break;
}
OSTimeDly(2);
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -