?? task.bak
字號:
/**********************************************************************************************
本程序只供學習使用,不得用于其它任何用途,否則后果自負。
Task.c file
作者:Computer-lov
建立日期:2006-5-8
修改日期:2006-5-15
版本:V1.0
版權所有,盜版必究。
任何技術問題可到我的博客上留言: http://computer00.21ic.org
Copyright(C) Computer-lov 2006-2016
All rights reserved
**********************************************************************************************/
#include <ADuC7026.H>
#include "interrupt.h"
#include "LED.H"
#include "ARM_00_OS_TaskSwitch.H"
#include "my_type.h"
#include "ARM_00_OS_Core.H"
#include "UART.H"
#include "KEYS.H"
#include "Task.h"
/**********************************************************************************************
任務1。處于掛起狀態,等待一條消息。系統空閑任務會掃描按鍵,當按鍵按下后,系統空閑任務會將
鍵值通過消息發送給任務1。任務1接到消息后,顯示消息的發送者以及消息的信息等。然后控制LED4的亮滅。
**********************************************************************************************/
void Task1(void)
{
uint32 PrinterDeviceAddr; //保存打印機設備的地址
PrinterDeviceAddr=OSGetDeviceAddr(OS_PRINTER_DEVICE_ID); //獲取打印機設備地址
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務啟動
prints(" Start.",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
EN_LED4(); //使能LED4
while(1)
{
OSTaskSuspend(OSCurrentPcb); //任務掛起
if(OSCurrentPcb->Msg) //如果收到消息
{
OSRequestDevice(PrinterDeviceAddr,0); //申請打印機
prints("",1);
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務標題
prints(":",1);
prints("Haha,I have got a message from: ",0); //顯示相關信息
prints(OSCurrentPcb->Msg->Sender->Title,1); //顯示發送者的標題
prints("The sender's PID is: ",0);
print_uint32(OSCurrentPcb->Msg->Sender->PID); //顯示發送者的PID
prints("",1);
prints("The message type is:",0); //消息類型
print_uint32(OSCurrentPcb->Msg->MsgType);
prints("",1);
prints("The message value is",0); //消息的值
print_uint32(*(OSCurrentPcb->Msg->pMsg));
prints("",1);
prints("",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
switch(*(OSCurrentPcb->Msg->pMsg)) //鍵值散轉
{
case KEY1: ON_LED4();break; //如果是按鍵1按下,則點亮LED4
case KEY2: OFF_LED4();break; //如果是按鍵2按下,則熄滅LED4
default: break;
}
OSCurrentPcb->Msg=0; //消息處理完畢
}
}
}
//////////////////////////////////End of function//////////////////////////////////////////////
/**********************************************************************************************
任務2。延遲1S,等待一條消息。系統空閑任務會掃描按鍵,當按鍵按下后,系統空閑任務會將
鍵值通過消息發送給任務1。任務1接到消息后,顯示消息的發送者以及消息的信息等。然后控制LED4的亮滅。
如果1S過后,還未收到消息,則顯示接收超時。
/*********************************************************************************************/
void Task2(void)
{
uint32 PrinterDeviceAddr; //保存打印機設備的地址
PrinterDeviceAddr=OSGetDeviceAddr(OS_PRINTER_DEVICE_ID); //獲取打印機設備地址
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務啟動
prints(" Start.",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
EN_LED5();
while(1)
{
OSTaskDelay(100); //延時等待消息的到來
if(OSCurrentPcb->Msg) //如果收到了消息
{
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務的標題
prints(":",1);
prints("Haha,I have got a message from: ",0);
prints(OSCurrentPcb->Msg->Sender->Title,1); //顯示消息發送者的標題
prints("The sender's PID is: ",0);
print_uint32(OSCurrentPcb->Msg->Sender->PID); //顯示消息發送者的PID
prints("",1);
prints("The message type is:",0);
print_uint32(OSCurrentPcb->Msg->MsgType); //顯示消息的類型
prints("",1);
prints("The message value is",0);
print_uint32(*(OSCurrentPcb->Msg->pMsg)); //顯示消息
prints("",1);
prints("",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
switch(*(OSCurrentPcb->Msg->pMsg)) //鍵值散轉
{
case KEY3: ON_LED5();break; //如果是按鍵3按下,則點亮LED5
case KEY4: OFF_LED5();break; //如果是按鍵4按下,則熄滅LED5
default: break;
}
OSCurrentPcb->Msg=0; //消息處理完畢
}
else //如果1秒后還未收到消息,則
{
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務的標題
prints(":",1);
prints("I have not got a message in 1 second!",1); //顯示未收到消息
prints("Time out!",1); //超時
prints("",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
}
}
}
//////////////////////////////////End of function//////////////////////////////////////////////
/**********************************************************************************************
任務3。每隔500mS點亮、熄滅一次LED6,并顯示一些信息。
**********************************************************************************************/
void Task3(void)
{
uint32 PrinterDeviceAddr; //保存打印機設備的地址
PrinterDeviceAddr=OSGetDeviceAddr(OS_PRINTER_DEVICE_ID); //獲取打印機設備地址
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務啟動
prints(" Start.",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
EN_LED6();
while(1)
{
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("HaHa,Task3! ",1); //顯示信息
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
OSTaskDelay(50); //延時50個時鐘節拍
ON_LED6(); //開LED6
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("HaHa,Task3! ",1); //顯示信息
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
OSTaskDelay(50); //延時50個時鐘節拍
OFF_LED6(); //關LED6
}
}
//////////////////////////////////End of function//////////////////////////////////////////////
/**********************************************************************************************
任務4。每隔1000mS點亮、熄滅一次LED6,并顯示一些信息。
**********************************************************************************************/
void Task4(void)
{
uint32 PrinterDeviceAddr; //保存打印機設備的地址
PrinterDeviceAddr=OSGetDeviceAddr(OS_PRINTER_DEVICE_ID); //獲取打印機設備地址
OSRequestDevice(PrinterDeviceAddr,0); // //申請使用打印機
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務啟動
prints(" Start.",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
EN_LED7();
while(1)
{
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("HaHa,Task4! ",1); //顯示信息
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
OSTaskDelay(100); //延時100個時鐘節拍
ON_LED7(); //開LED7
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("HaHa,Task4! ",1); //顯示信息
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
OSTaskDelay(100); //延時100個時鐘節拍
OFF_LED7(); //關LED7
}
}
//////////////////////////////////End of function//////////////////////////////////////////////
/**********************************************************************************************
任務5。鍵盤掃描并發送消息。
**********************************************************************************************/
void Task5(void)
{
uint32 PrinterDeviceAddr; //保存打印機設備的地址
OSpcb * Task1Pcb,* Task2Pcb; //用來保存任務pcb
OSMsg Msg; //消息
uint32 MsgValue; //保存消息值
PrinterDeviceAddr=OSGetDeviceAddr(OS_PRINTER_DEVICE_ID); //獲取打印機設備地址
OSRequestDevice(PrinterDeviceAddr,0); //申請使用打印機
prints("",1);
prints(OSCurrentPcb->Title,0); //顯示任務啟動
prints(" Start.",1);
OSFreeDevice(PrinterDeviceAddr); //釋放打印機
Task1Pcb=(OSpcb *)(uint32)OSTaskCreat((uint32)Task1,256,4,OS_THUMB_MODE,"Task1"); //創建任務1
Task2Pcb=(OSpcb *)(uint32)OSTaskCreat((uint32)Task2,256,5,OS_THUMB_MODE,"Task2"); //創建任務2
while(1)
{
OSTaskDelay(5); //延遲10ms
ScanKey(); //鍵盤掃描
if(Key.Value) //如果有鍵按下
{
MsgValue=Key.Value; //保存按鍵值
(&Msg)->MsgType=KEYBOARD_MSG; //設置要發送的消息類型
(&Msg)->pMsg=&MsgValue; //設置要發送的消息的值
(&Msg)->Length=1; //設置消息的長度
OSSendMsg(Task1Pcb,&Msg); //將消息發送給任務1
OSSendMsg(Task2Pcb,&Msg); //將消息發送給任務2
Key.Value=0; //清除鍵值,表示該次按鍵已經處理
}
}
}
//////////////////////////////////End of function//////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -