⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_tasksw.c

📁 51上的RTOS
💻 C
字号:
/* $$$$$$$$$$$$$$$$$$   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 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -