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

📄 testmsg.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
字号:
/*************************************************************************
 *
 *  Copyright (C) Asic Center. 2001
 *  All Rights Reserved
 *
 *  Filename : testcode.c
 *  Function : Some tasks for testing system prototype, such as SHELL, TIMER
 *			   TASK, IDLE TASK, TASK A,B,C, and so on.
 *  Revision :
 *          2001/10/9  Pessia      Create this file
 *
 ************************************************************************/
 #include <stdio.h>
 #include <string.h> 
 #include <kernel\ros33\Ros33.h> //Normally, we do not appreciate including this kernel file.
 #include <ppsm.h>
 
 #define TESTMSG 0x400
 
 void shell_task(void);
 void timer_task(void);
 void a_task(void);
 void b_task(void);
 void c_task(void); 
 
UB Penflag = 0;
float kx,ky,bx,by;
unsigned short xppos1,yppos1,xppos2,yppos2,x1,x2,y1,y2;


/********************************************************************
*   Function shell_task()  
*	param in:	void		
*	param out: 	void	
*	description: Shell Task 
*					In test, we just add 1 or 2 icon on the screen,
*				 when you push it, shell task will send a message to
*				 system task to start a special task.	
********************************************************************/
void shell_task(void)
{
	MSG	msg;
		
	gpcSetColor(0xff8800);
	gpcDrawText(1,2,"Shell Task",10);
	gpcDrawText(1,15,"1-start a",9);
	gpcDrawText(2,30,"2-start b",9);
	gpcDrawText(3,45,"3-kill a",8);
	gpcDrawText(4,60,"4-kill b",8);
	gpcDrawText(5,75,"5-start",7);
	gpcDrawText(6,85,"6-c",3);
	while(1)
	{
		RecvMessage(&msg, -1);
		if(msg.message == ROS33_KEYDOWN)
		{
			switch(msg.wparam)
			{
				case 1:
					/* task id = TASKA_ID */
					msg.message = ROS33_START;
					msg.wparam = TASKA_ID;
					SendMessage(SYSTASK_ID, &msg);
					break;
					
				case 2:
					/* task id = TASKB_ID */
					msg.message = ROS33_START;
					msg.wparam = TASKB_ID;
					SendMessage(SYSTASK_ID, &msg);
					break;
					
				case 3:
					/* task id = TASKA_ID */
					msg.message = ROS33_END;
					msg.wparam = TASKA_ID;
					SendMessage(SYSTASK_ID, &msg);
					break;
					
				case 4:
					/* task id = TASKB_ID */
					msg.message = ROS33_END;
					msg.wparam = TASKB_ID;
					SendMessage(SYSTASK_ID, &msg);
					break;
				
				case 5:// send a message to task a
					msg.message = TESTMSG;
					/* .wparam is sender's ID */
					msg.wparam = TASKB_ID;
					SendMessage(TASKA_ID, &msg);
					break;
				
				case 6:
					/* task id = TASKA_ID */
					msg.message = ROS33_START;
					msg.wparam = TASKC_ID;
					SendMessage(SYSTASK_ID, &msg);					
					break;
					
				default:
					break;
			}
		}
	}	
}

/********************************************************************
*   Function timer_task()  
*	param in:	void		
*	param out: 	void	
*	description: Timer Task
*					In test, while timer task receives a timer click,
*				 it just adds a counter and does nothing else.	
********************************************************************/
void timer_task(void)
{
 	static 	UW timecount=0;
 	UINT 	flgptn;
 	char	tmp[2]="+";
 	 	 	
 	while(1)
 	{
 		/* if receive a message */
 		wai_flg(&flgptn, TIMER_EVENT, 0x01, TWF_ORW);
 		
		/* just increase timecount */
		timecount++;
		tmp[0] = timecount - 0 + '0';
		tmp[1] = 0; 
		gpcDrawText(30,110,tmp,1);
		
		/* avoid overflow */ 
		if( timecount = 9 )
			timecount = 0; 		
 	}
 	 	
}

/********************************************************************
*   Function a_task()  
*	param in:	void		
*	param out: 	void	
*	description: Task A	
********************************************************************/
void a_task(void)
{
 	MSG	msg, newmsg;
 	static int count=0;
 	char temp[20];
 	 	
 	while(1)
	{
		RecvMessage(&msg, -1);
		switch(msg.message)
		{
			case TESTMSG:
				sprintf(temp, "Agot:%d",++count);
				if(count == 1000000)
					count = 0;
				gpcDrawText(1,100,temp,strlen(temp));
				
				newmsg.message = TESTMSG;
				/* .wparam is sender's ID */
				newmsg.wparam = TASKA_ID;				
				SendMessage(msg.wparam, &newmsg);
				break;
			default:
				break;
		}
	} 				
}

 
 /********************************************************************
*   Function b_task()  
*	param in:			
*	param out: 		
*	description: Task B
********************************************************************/
void b_task(void)
{
	MSG	msg, newmsg;
	static int count=0;
 	char temp[20];
 	
 	while(1)
	{
		RecvMessage(&msg, -1);
		switch(msg.message)
		{
			case TESTMSG:
				sprintf(temp, "Bgot:%d",++count);
				if(count == 1000000)
					count = 0;
				gpcDrawText(1,120,temp,strlen(temp));
				
				newmsg.message = TESTMSG;
				/* .wparam is sender's ID */
				newmsg.wparam = TASKB_ID;				
				SendMessage(msg.wparam, &newmsg);
				break;
			default:
				break;
		}
	} 
}
 
 /********************************************************************
*   Function IdleHandler()  
*	param in:			
*	param out: 		
*	description: Task C : in this test, C's priority is higher than A & B
********************************************************************/
void Pendemo(UB flag,unsigned short x,unsigned short y);

void c_task(void)
{
	MSG	msg;
	int x,y;
	
	/* send message to system task to occupy LCD screen */
	msg.message = ROS33_SWITCH;
	msg.wparam = TASKC_ID;
	SendMessage(SYSTASK_ID, &msg);		
	
	while(1)
	{
		RecvMessage(&msg, -1);
		switch(msg.message)
		{
			case ROS33_KEYDOWN:
				/* 1 to quit */
				if(msg.wparam == 1)
				{
					msg.message = ROS33_END;
					msg.wparam = TASKC_ID;
					SendMessage(SYSTASK_ID, &msg);	
				}
				break;
			case ROS33_PENDOWN:
			case ROS33_PENMOVE:
			case ROS33_PENUP:
				x = ((COORDINATE *)&msg.lparam)->x;
				y = ((COORDINATE *)&msg.lparam)->y;
				Pendemo(msg.message,x,y);
				break;	
	
			default:
				break;
		}
	}
}

static void Pendemo(UB flag,unsigned short x,unsigned short y)
{
	if (flag == ROS33_PENDOWN) 
	{	 
		if ( Penflag == 0)
		{
			x1 = y;
			y1 = x;
			Penflag = 1;
			gpcSetColor(0x44ffff);
			gpcFillRect(0,0,30,30);
			return;
		}
		if (Penflag == 1)
		{
			x2 = y;
			y2 = x;
			Penflag = 2;
			kx =  100.0 / (x2 - x1);
			ky =  140.0 / (y2 - y1);
			bx = (120 -((x1+x2) * kx)) / 2 ;
			by = (160 - ((y1+y2) * ky)) /2 ;
			gpcSetColor(0x44ffff);
			gpcFillRect(100,140,119,159);

			return;
		}
	}
	if (Penflag >= 2)
	{
		if (flag  == ROS33_PENDOWN)
		{
			xppos1 = kx * y + bx;
			yppos1 = ky * x + by;
			gpcSetColor(0x8040ff);
			if ((xppos1 < 120) && (yppos1 <160))
				gpcFillRect(xppos1,yppos1,xppos1+1,yppos1+1);
			Penflag = 3;
		}
		if (flag == ROS33_PENMOVE)
		{
			xppos2 = kx * y + bx;
			yppos2 = ky * x + by;
			if ((xppos1 < 120) && (yppos1 <160) && (xppos2 <120) && (yppos2 < 160))
				gpcDrawLine(xppos1,yppos1,xppos2,yppos2);
			xppos1 = xppos2;
			yppos1 = yppos2;	
		}		
		if (flag  == ROS33_PENUP)
		{
			;
		}
	}
}	


⌨️ 快捷键说明

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