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

📄 cmx_init.c

📁 上传一个带源代码的嵌入式实时多任务操作系统CMX
💻 C
📖 第 1 页 / 共 2 页
字号:
	K_Task_Name(cmxtracker_slot,"CMXTracker");		/* Name for task */
	K_Task_Start(cmxtracker_slot);					/* start CMXTracker task */
	init_cmxtracker();
#endif
#if (!defined(WINBUG) && !defined(WINTRACKER))
		/* The following is for serial channel 0, 80C16x processor */
		P3 |= 0X0400;		/* now set up serial channel 0, for use with CMXBug */
		DP3 |= 0X0400;
		DP3 &= 0XF7FF;
/*		S0BG  = 0x0033; */		/* 9600 Baud using 16 MHz	*/
		S0BG  = 0x0040;		/* 9600 Baud using 40 MHz	*/
		S0TIC = 0;				/* clear errorflags	*/
		S0RIC = 0;
		S0EIC = 0;
		S0TIR = 1;
		S0CON = 0x8011;
#else
		setbaud();
#endif	/* #if (!defined(WINBUG) && !defined(WINTRACKER)) */
}

#if CMXTRACKER_ENABLE > 0
void init_cmxtracker(void)
{
	num_records = 0;
	cmxtracker_in_ptr = cmxtracker_array;
	cmxtracker_ctr = sizeof (cmxtracker_array);
}
#endif

byte K_Bug_Getchr(byte *ptr)
{
	if ( S0EIR )
		{
		S0PE = 0;
		S0FE = 0;
		S0EIR = 0;
		S0RIR = 0;
		return(0);
		}
	else if ( S0RIR )
		{
		*ptr = S0RBUF & 0x7F;
		S0RIR = 0;
		return(1);
		}
	else
		return(0);
}

void K_Bug_Putchr(char c)
{
	while ( ! S0TIR ) 
		;
	S0TIR  = 0;
	S0TBUF = c;
}
#endif

#pragma global
byte K_I_Intrp_Pipe_In(byte a, byte b, byte c, word16 d, void *mesg)
{
	PIPE_STRUC *in_ptr;

#if CMXTRACKER_ENABLE > 0
	if ((!(TEST_CMX_ACTIVE)) || (CMXTRACKER_ACTIVE))
		return(K_ERROR);
#else
	if (!(TEST_CMX_ACTIVE))
		return(K_ERROR);
#endif
	PROC_SAVE_INT;	/* disable interrupts */
	if (pipe_slots_avail)
		{
		in_ptr = &pipe[in_ctr];
		--pipe_slots_avail;
		if (++in_ctr == C_PIPE_SIZE)
			in_ctr = 0;
		PROC_RESTORE_INT;	/* enable interrupts */
		DO_INT_PIPE;		/*	Set the do interrupt pipe flag. */
		in_ptr->identifier = a;
		in_ptr->p1 = b;
		switch(a) {
			case 5:
			case 6:
				in_ptr->pipe_u.p3 = d;
				break;
			case 7:
				in_ptr->pipe_u.p4 = mesg;
				break;
			case 8:
				in_ptr->p2 = c;
				in_ptr->pipe_u.p3 = d;
				break;
				}
			return(K_OK);
			}
		else
			{
			PROC_RESTORE_INT;	/* enable interrupts */
			return(K_ERROR);
			}
}
#pragma public

/*********************************************************************
 The following function executes the functions that the interrupts
 place into the interrupt pipe. called only by CMX K_I_Scheduler.
*********************************************************************/
void K_I_Intrp_Pipe_Out(void)
{
	byte parm1;
	byte parm2;

	while(1)
		{
#if CMXTRACKER_ENABLE
		if (!CMXTRACKER_ACTIVE)
			{
			cmxtracker_in1(INT_ACTION);
			}
#endif
		out_ptr = &pipe[out_ctr];
		switch (out_ptr->identifier) {
			case 0:
				K_Task_Wake(out_ptr->p1);
				break;
			case 1:
				K_Task_Wake_Force(out_ptr->p1);
				break;
			case 2:
				K_Task_Start(out_ptr->p1);
				break;
			case 3:
				K_Timer_Stop(out_ptr->p1);
				break;
			case 4:
				K_Timer_Restart(out_ptr->p1);
				break;
			case 5:
				parm1 = out_ptr->p1;
				K_Timer_Initial(parm1,out_ptr->pipe_u.p3);
				break;
			case 6:
				parm1 = out_ptr->p1;
				K_Timer_Cyclic(parm1,out_ptr->pipe_u.p3);
				break;
			case 7:
				parm1 = out_ptr->p1;
				K_Mesg_Send(parm1,out_ptr->pipe_u.p4);
				break;
			case 8:
				parm1 = out_ptr->p1;
				parm2 = out_ptr->p2;
				K_Event_Signal(parm1,parm2,out_ptr->pipe_u.p3);
				break;
			case 9:
				K_Semaphore_Post(out_ptr->p1);
				break;
			default:
				/* What should we do here, possibly reset pipe ? to be beginning */
				break;
			}
		PROC_DISABLE_INT;	/* disable interrupts */
		pipe_slots_avail++;
		if (++out_ctr == C_PIPE_SIZE)
			out_ctr = 0;
		if (out_ctr == in_ctr)
			{
			CLR_DO_INT_PIPE;	/* no, reset do interrupt pipe flag. */
			break;		/* exit. */
			}
		PROC_ENABLE_INT;	/* re-enable interrupts and process more. */
		}
	PROC_ENABLE_INT;	/* re-enable interrupts and exit. */
}

/******************************************************************
	K_OS_Tick_Update:  Called from timer interrupt routine to signal that
	the CMX task timer should execute if need be.
	THIS CODE EXECUTES ONLY AT INTERRUPT LEVEL.
**********************************************************************/
#pragma global
void K_OS_Tick_Update(void)
{
	if (TEST_CMX_ACTIVE)	/* see if CMX OS has been entered. */
		{
#if CMXBUG_ENABLE > 0
		if (!CMXBUG_ACTIVE)
			{
			if (activetcb->tcbstate & RUNNING)
				stat_array[activetcb - cmx_tcb] += 1;
			else
				stat_array[0] += 1;
			}
#endif

#if CMXTRACKER_ENABLE
	if (!CMXTRACKER_ACTIVE)
		{
#if (defined(WINTRACKER))
#if CMXTRACKER_TICK_UPDATE
		track_tick_count++;	/* increment long counter */
#endif	/* #if CMXTRACKER_TICK_UPDATE */
#endif	/* #if (defined(WINTRACKER)) */
#endif	/* #if CMXTRACKER_ENABLE */

		cmx_tick_count++;	/* increment long counter */

		if (!(--rtc_count))	/* converts hardware tics to CMX delay tics */
			{
#if CMXTRACKER_ENABLE
			{
			cmxtracker_in1(CMX_TIC_CALL);
			}
#endif
			rtc_count = RTC_SCALE;	/* reset counter with rtc prescaler */
			/* the following will see if a task timer needs servicing or
				a cyclic timer needs servicing. */
			if ((tsk_timer_lnk->ftlink != (tcbpointer)tsk_timer_lnk) ||
				(cyclic_lnk->ftlink != (struct _tcproc *)cyclic_lnk))
				{
				DO_TIMER_TSK;	/* yes, set flag to indicate that CMX timer
									task should execute. */
				}
  			}

			if (TEST_SLICE_ENABLE)	/* see if time slicing active. */
				{
				if (!(--tslice_count))	/* if so, decrement and test time slice
												counter. */
					{
					DO_TIME_SLICE;		/* set flag indicating time count expired. */
					SLICE_DISABLE;		/* disable time slicing. */
					}
				}
#if CMXTRACKER_ENABLE
		}
#if (defined(WINTRACKER))
	else
		compute_tick_count++;
#endif			/* #if (defined(WINTRACKER)) */
#endif			/* #if CMXTRACKER_ENABLE */
		}
}	/* K_OS_Tick_Update */
#pragma public

#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
byte K_Task_Name(byte task_slot,char *name)
{
	tcbpointer tcbptr;

	if(K_I_Get_Ptr(task_slot,&tcbptr))	/* send address of pointer */
		return(K_ERROR);
	task_name[task_slot] = name;
	return(K_OK);
}
#endif 

byte K_OS_Task_Slot_Get(void)
{
	return ((struct _tcb *)activetcb - cmx_tcb);
}

word32 K_OS_Tick_Get_Ctr(void)
{
	return(cmx_tick_count);
}

void K_I_Func_Return(void)
{
	/* this function will decrement the task block (lock) counter.
		Also see if the interrupt count is 0 and if so, will
		test to see any of the CMX 5 flags are set, which will then call
		the K_I_Scheduler to invoke possibly a task switch */

#if (defined(WINBUG))
	if (bug_step_one)
		{
		if ((activetcb	- cmx_tcb) != cmxbug_slot)
			{
			if (!(--bug_step_count))
				{
				bug_step_one = 0;
				if (cmx_tcb[cmxbug_slot].tcbstate & WAIT)
					{
					cmx_tcb[cmxbug_slot].tcbstate = RESUME;
					PREEMPTED;	/* yes, set the preempted scheduling flag */
					}
				}
			}
		}
#endif		/* #if (defined(WINBUG)) */
	K_I_Enable_Sched();
}

/*****************************************************************
 The following is the CPU reduced power function. The user
 MUST write their own and they must ensure that the proceesor
 returns to the caller, without modifying the stack.

 NOTE: the CMX K_I_Scheduler calls this function which is in the assembly
 module supplied. The user may find it necessary to modify the
 assembly file, so every thing is correct when the CPU
 comes out of the reduced power state. ALSO the CPU must let
 the interrupts wake it up, out of the reduced power state
 so as the task's timers and cyclic timers may have their
 time counters decremented if need be.
*****************************************************************/
void K_OS_Low_Power_Func(void)
{
}


#if (defined(WINTRACKER))
#if CMXTRACKER_TICK_UPDATE == 0
#pragma global
void K_OS_Update_Track_Tick(void)
{
	if (!CMXTRACKER_ACTIVE)
		{
		track_tick_count++;	/* increment long counter */
		}
}
#pragma public
#endif		/* #if CMXTRACKER_TICK_UPDATE == 0 */
#endif		/* #if (defined(WINTRACKER)) */

⌨️ 快捷键说明

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