?? os_tasksw.c
字號(hào):
/* $$$$$$$$$$$$$$$$$$ Copyrigth (c) $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
File name: OS_TaskSW.c
Function describe: task attemper;create task;delete task
Compiler: Keil uVision2
Version: 1.01
Programmer: Shawyoo
最近修改日期:20040729
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
#define OS_GLOBALS 1
#include "RTOS.h"
#include "OS_TaskSW.h"
////////////////////////// osTask
struct
{
uchar Ready[MAX_TASK_ID_DIV8]; //
//uchar Running[MAX_TASK_ID_DIV8];
} osTask;
//////////////////////////////////////
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function: delete all task
Entrance parameter:none
Exit parameter: none
Global parameter: osTask
Local parameter: 1 byte
Call function: none
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
void OSDeleteAllTask(void)
{
uchar i;
for(i=0;i<MAX_TASK_ID_DIV8;i++)
{
osTask.Ready[i]=0;
//osTask.Running[i]=0;
}
} // function end
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function: create one task
Entrance parameter: task ID
Exit parameter: none
Global parameter: osTask
Local parameter:2 bytes
Call function: none
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
void OSCreateTask(uchar taskID)
{
uchar i;
i=0;
while(taskID>8) { taskID-=8; i++; }
if(i<MAX_TASK_ID_DIV8)
osTask.Ready[i]|=TaskFlagTab[taskID];
} // function end
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function: delete one task
Entrance parameter: task ID
Exit parameter: none
Global parameter: osTask
Local parameter:2 bytes
Call function: none
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
void OSDeleteTask(uchar taskID)
{
uchar i;
i=0;
while(taskID>8) { taskID-=8; i++; }
if(i<MAX_TASK_ID_DIV8)
{
osTask.Ready[i]&=(~TaskFlagTab[taskID]);
//osTask.Running[i]&=(~TaskFlagTab[taskID]);
}
} // function end
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function: Create periodicity excute task
Entrance parameter: None
Exit parameter: none
Global parameter: osTask,osTick
Local parameter: 4 bytes
Call function: none
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
void OSPeriodicityTask()
{
uchar i,j;
uint tick;
NOP(); NOP();
for(i=0;i<MAX_TASK_ID_DIV8;i++)
{
for(j=0;j<8;j++)
{
tick=CycleExcute[i][j];
if((tick!=0)&&(osTick%tick==0))
OSCreateTask(i*8+j); //
}
}
}
/* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function: switch task,and excute the highest PRI task
Entrance parameter: NULL
Exit parameter: none
Global parameter: osTask
Local parameter:3 bytes
Call function: all task function and "TaskSwitchReturn";
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
////////////////////////////
void OSTaskSwitch(void)
{
//static osDoneTaskID;
static uchar i,j,id,tc; // task ID,task counter,
static uchar run; // task running flag
NOP(); NOP();
NOP(); NOP();
/////////////////////////////////////////////////
OSPeriodicityTask();
NOP(); NOP();
for(tc=0,i=0;i<MAX_TASK_ID_DIV8;i++)
{
id=osTask.Ready[i];
if(id) tc++; // task counter
}
if((tc!=0)&&(run!=TASK_RUNNING)) //
{
for(i=0;i<MAX_TASK_ID_DIV8;i++)
{
id=osTask.Ready[i];
for(j=0;j<8;j++)
{
if(id&0x01)
{
NOP(); NOP();
NOP(); NOP();
run=TASK_RUNNING;
ResetWatchDog();
NOP(); NOP();
NOP(); NOP();
TaskEntrance[i][j](); // execute one task
NOP(); NOP();
NOP(); NOP();
OSDeleteTask(i*8+j); //
run=TASK_STOP;
}
id>>=1;
}
}
}
NOP(); NOP();
TaskSwitchReturn();
} // function end
/* File end $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -