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

📄 timertsk.c

📁 上传一个带源代码的嵌入式实时多任务操作系统CMX
💻 C
字号:
/*********************************************************

Copyright (c) CMX Company. 1999. All rights reserved

*********************************************************/
/* version 5.30 */

#define CMXMODULE 1

#include <cxfuncs.h>	/* get cmx include header file */
#include <cxextern.h>	/* get cmx include header file */

#if (defined(CMXTRACKER) || defined(WINTRACKER))
#include <cmxtrack.h>	/* get cmx include header file */
#endif

/*******************************************************************
 The following is the CMX timer task. This will see if any tasks
 need their time counters decremented (because they have specified
 a time period, and thier waiting). If so then this will use the doubly
 linked list of tasks that need their time counters decremented. Once a
 task has it's time counter decrement to 0, then the task will be place
 into the RESUME state, and remove from the linked list.

 Also the cyclic timers linked list will be tested to see if any cyclic
 timers need thier respective time counters decremented. If so then this
 will use the doubly	linked list of cyclic timers that need their time
 counters decremented. Once a cyclic timer has it's time counter decrement
 to 0, then the cyclic timer will have its K_Event_Signal parameters executed
 and also the cyclic time will be reloaded, if non zero.
****************************************************************/
 
void K_I_Timer_Task(void)
{
	tcbpointer x;
	struct _tcproc *tpptr;

	tpptr = cyclic_lnk->ftlink;	/* set pointer to cyclic linked list. */
	while (tpptr != (struct _tcproc *)cyclic_lnk) /* test for done of list. */
		{
		if (!(--tpptr->tproc_timer))	/* decrement time counter and test. */
			{
			/* if 0, then reload time counter, with cyclic time. */
			if ((tpptr->tproc_timer = tpptr->reload_time) == 0)
				{
				/* if cyclic time period 0, then stop cyclic timer
					and remove from linked list. */
				tpptr->tproc_start = 0;
				tpptr->ftlink->btlink = tpptr->btlink;
				tpptr->btlink->ftlink = tpptr->ftlink;
				}
			/* execute the cyclic timer's K_Event_Signal function parameters. */ 
#if (defined(CMXTRACKER) || defined(WINTRACKER))
		if (CMXTRACKER_ON)
			{
			cmxtracker_in2(TIMER_TASK_ACTION,(byte)(tpptr - tcproc));
			}
#endif
			K_Event_Signal(tpptr->mode,tpptr->tskid_pri,tpptr->event_num);
			}
		/* adjust pointer to next linked list member. */
		tpptr = tpptr->ftlink;
		} /* while loop */
	/* set pointer to beginning of task timer link list. */
	x = tsk_timer_lnk->ftlink;
	while (x != (tcbpointer)tsk_timer_lnk)	/* if not end of linked list. */
		{
		if (x->tcbstate & TIME)	/* see if task really waiting on time out. */
			{
			if (!(--x->tcbtimer))	/* yes, go decrement the task time counter. */
				{
				/* if time expired, test to see if task waiting on resource. */
				if (x->tcbstate & (RESOURCE | SEMAPHORE))
					{
					/* yes, remove task from resource wait linked list. */
					x->fwlink->bwlink = x->bwlink;
					x->bwlink->fwlink = x->fwlink;
					}
				/* set the task into the RESUME state. */
				x->tcbstate = RESUME | TIME_EXPIRED;
				/* indicate we should remove task from link list, this
					will be done by the function that place this task
					into the wait (sleep) state. This way we do NOT
					waste time in here performing this. */
				x->tcbtimer = 1;
				if (x->priority < active_priority) 
					PREEMPTED;	/* yes, set preempted scheduling flag */
				}
			}
		x = x->ftlink;	/* point to next link. */
		}
}	/* K_I_Timer_Task */

⌨️ 快捷键说明

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