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

📄 systask.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* draw two crosses: one is on left-top, the other is on right-down */
	SysSetBkColor(( DWORD )pGC, GPC_BLUE);
	SysSetColor(( DWORD )pGC, GPC_WHITE);
	SysClearScreen(( DWORD )pGC, GPC_WHITE);

	//SysDrawText(( DWORD )pGC, GPC_BLACK, 10, 20, 140, 84, "Pen Calibration: Please press left-top cross first, then right-bottom, and center last!", GPC_REPLACE_STYLE);
	SysDrawText(( DWORD )pGC, GPC_BLACK, 40, 20, 140, 84, "笔定位:先点左上角,然后点右下角,最后点中间!", GPC_REPLACE_STYLE);
/*
#define DEFAULT_LEFT	0x0258
#define DEFAULT_TOP		0x01E0
#define DEFAULT_RIGHT	0x0D88
#define DEFAULT_BOTTOM	0x0E40

	avx1 = DEFAULT_LEFT;
	avy1 = DEFAULT_TOP;
	avx2 = DEFAULT_RIGHT;
	avy2 = DEFAULT_BOTTOM;
*/	
////	DisableUartInt( UART_ALL );	// disable uart interrupt
	
	while(!quit)
	{
		if( showCross )
		{
#ifdef LICON
			/* (10,10) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 5, 10, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 10, 5, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			
			/* (150,230) */
////			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 145, 230, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
////			SysDrawVert(( DWORD )pGC, GPC_BLACK, 150, 225, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
		
			/* (80,120) */
////			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 75, 120, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
////			SysDrawVert(( DWORD )pGC, GPC_BLACK, 80, 115, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			
			/* (230,310) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 225, 310, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 230, 305, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
		
			/* (120,160) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 115, 160, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 120, 155, 11, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
#else
			/* (20,20) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 5, 20, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 15, 10, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			
			/* (230,310) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 215, 300, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 225, 290, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
		
			/* (120,160) */
			SysDrawHorz(( DWORD )pGC, GPC_BLACK, 110, 160, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
			SysDrawVert(( DWORD )pGC, GPC_BLACK, 120, 150, 21, GPC_SOLID_LINE, GPC_REPLACE_STYLE);

#endif
			
			showCross = 0;
		}
	
		flgptn = 0;
		/* wait for Interrupt or Tasks' Message */
    	wai_flg(&flgptn, SYS_EVENT, 0xFF, TWF_ORW);
    	
    	if( flgptn & INTPEN_FLG )
    	{
			msgtype = PEN_BUF[PEN_BUF_readcount].flag;
			/* read pen message directly from interrupt buffer PEN_BUF */
			switch(msgtype)
			{
				case SM_PENDOWN:
					last_x1=0;
					last_y1=0;
					last_x2=0;
					last_y2=0;
					last_x3=0;
					last_y3=0;

					act_cyc(TOUCHTIMER,TCY_ON|TCY_INI);
					break;	
			
				case SM_PENMOVE:
//					if(!PenDown)
					{
						PenDown++;
						if (!lefttop_pressed)
						{				
							y1 = PEN_BUF[PEN_BUF_readcount].y;
							x1 = PEN_BUF[PEN_BUF_readcount].x;
							if(!(last_x1&&last_y1)){
								last_x1 = x1;
								last_y1 = y1;
							}else{
								if ( x1 > last_x1 + AD_WUCHA 
									|| x1 < last_x1 - AD_WUCHA
									|| y1 > last_y1 + AD_WUCHA 
									|| y1 < last_y1 - AD_WUCHA ){
										x1 = ( x1 + last_x1 * PenDown )/( PenDown + 1 );
										y1 = ( y1 + last_y1 * PenDown )/( PenDown + 1 );
								}
								
							}
							if( PenDown == 3 )
#ifdef LICON			
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 10, 10, 5, GPC_REPLACE_STYLE );
#else
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 15, 20, 10, GPC_REPLACE_STYLE );
#endif			
						}else if( !rightbottom_pressed )
						{
							y2 = PEN_BUF[PEN_BUF_readcount].y;
							x2 = PEN_BUF[PEN_BUF_readcount].x;
							if(!(last_x2&&last_y2)){
								last_x2 = x2;
								last_y2 = y2;
							}else{
								if ( x2 > last_x2 + AD_WUCHA 
									|| x2 < last_x2 - AD_WUCHA
									|| y2 > last_y2 + AD_WUCHA 
									|| y2 < last_y2 - AD_WUCHA ){
										x2 = ( x2 + last_x2 * PenDown )/( PenDown + 1 );
										y2 = ( y2 + last_y2 * PenDown )/( PenDown + 1 );
								}
							}
							if( PenDown == 3 )
////								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 150, 230, 5, GPC_REPLACE_STYLE );
#ifdef LICON		
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 230, 310, 5, GPC_REPLACE_STYLE );
#else
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 225, 300, 10, GPC_REPLACE_STYLE );
#endif			
						}else
						{	
////							x3 = kx * PEN_BUF[PEN_BUF_readcount].x + bx;
////							y3 = ky * PEN_BUF[PEN_BUF_readcount].y + by;
							x3 = TS_CAL_X(PEN_BUF[PEN_BUF_readcount].x);
							y3 = TS_CAL_Y(PEN_BUF[PEN_BUF_readcount].y);
							
							if( new_check )
							{	
								last_x3 = x3;
								last_y3 = y3;
								new_check = 0;
							}
							else
							{
								
/*								if ( next_x > x3 + POS_WUCHA )
									next_x = x3 + POS_WUCHA;
								else if ( next_x < x3 - POS_WUCHA )
									next_x = x3 - POS_WUCHA;
								
								if ( next_y > y3 + POS_WUCHA )
									next_y = y3 + POS_WUCHA;
								else if ( next_y < y3 - POS_WUCHA )
									next_y = y3 - POS_WUCHA;
							
								x3 = next_x;
								y3 = next_y;
*/
								if ( x3 > last_x3 + POS_WUCHA 
									|| x3 < last_x3 - POS_WUCHA
									|| y3 > last_y3 + POS_WUCHA 
									|| y3 < last_y3 - POS_WUCHA ){
										x3 = ( x3 + last_x3 * PenDown )/( PenDown + 1 );
										y3 = ( y3 + last_y3 * PenDown )/( PenDown + 1 );
								}
							}
							if( PenDown == 3 )
////								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 80, 120, 5, GPC_REPLACE_STYLE );
#ifdef LICON		
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 120, 160, 5, GPC_REPLACE_STYLE );							
#else
								SysDrawCircle( (DWORD)pGC, GPC_BLACK, 120, 160, 10, GPC_REPLACE_STYLE );							
#endif			
						}
					}
					break;
					
				case SM_PENUP:
					if( PenDown > 2 )
					{
						if ( rightbottom_pressed ){
							center_pressed = 1;
////							SysClearRec(( DWORD )pGC, GPC_WHITE, 75, 115, 10, 10, GPC_REPLACE_STYLE);
#ifdef LICON		
							SysClearRec(( DWORD )pGC, GPC_WHITE, 115, 155, 15, 15, GPC_REPLACE_STYLE);
#else
							SysClearRec(( DWORD )pGC, GPC_WHITE, 110, 150, 25, 25, GPC_REPLACE_STYLE);
#endif			
						}
												
						if (lefttop_pressed ){
							amx1 = x1;
							amx2 = x2;
							amy1 = y1;
							amy2 = y2;
/*
							kx =  (230.0-10.0) / (x2 - x1);
							ky =  (310.0-10.0) / (y2 - y1);
							bx = (240.0 -(x1+x2) * kx) / 2 ;
							by = (320.0 -(y1+y2) * ky) / 2 ;
*/

/*
							kx =  (150.0-10.0) / (x2 - x1);
							ky =  (230.0-10.0) / (y2 - y1);
							bx = (160.0 -(x1+x2) * kx) / 2 ;
							by = (240.0 -(y1+y2) * ky) / 2 ;
*/ ////gfd
	
	/*						kx =  (150.0-10.0) / (avx2 - avx1);
							ky =  (230.0-10.0) / (avy2 - avy1);
							bx = (160.0 -(avx1+avx2) * kx) / 2 ;
							by = (240.0 -(avy1+avy2) * ky) / 2 ;
	*/						
							rightbottom_pressed = 1;
////							SysClearRec(( DWORD )pGC, GPC_WHITE, 140, 220, 18, 18, GPC_REPLACE_STYLE);	
#ifdef LICON		
							SysClearRec(( DWORD )pGC, GPC_WHITE, 220, 300, 18, 18, GPC_REPLACE_STYLE);
#else
							SysClearRec(( DWORD )pGC, GPC_WHITE, 210, 290, 28, 28, GPC_REPLACE_STYLE);
#endif			
						}
						
						if (!lefttop_pressed ){						
							lefttop_pressed = 1;
#ifdef LICON		
							SysClearRec(( DWORD )pGC, GPC_WHITE, 1, 1, 15, 15, GPC_REPLACE_STYLE);
#else
							SysClearRec(( DWORD )pGC, GPC_WHITE, 1, 1, 35, 35, GPC_REPLACE_STYLE);
#endif			
						}
						
						if ( center_pressed ){						
							new_check = 1;
							if ( x3 > 125 || x3 < 115	|| y3 >  165 || y3 < 155 )
							{
								lefttop_pressed=0, rightbottom_pressed=0, center_pressed = 0;
								last_x1 = 0,last_y1 = 0,last_x2 = 0,last_y2 = 0,last_x3 = 0,last_y3 = 0;
#ifdef LICON								
								SysClearRec(( DWORD )pGC, GPC_WHITE, 10, 20, 140, 60, GPC_REPLACE_STYLE );
							
								SysDrawText(( DWORD )pGC, GPC_BLACK, 10, 20, 140, 84, "Pen Calibration is invalid.\nTry again!", GPC_REPLACE_STYLE);
#else
								SysClearRec(( DWORD )pGC, GPC_WHITE, 40, 20, 140, 60, GPC_REPLACE_STYLE );
							
								SysDrawText(( DWORD )pGC, GPC_BLACK, 40, 20, 140, 84, "定位不准.\n请重试!", GPC_REPLACE_STYLE);
#endif								
								showCross = 1;
							}
							else
								quit = 1;
						}
					}
					
					PenDown = 0;
					
//					PenEnable();
					break;
					
				default:
					break;
			}
			PEN_BUF_readcount = (PEN_BUF_readcount +1) % MAX_PENBUF;
		}
#if 0				/////gfd		
		if( flgptn & INTKEY_FLG )
		{	
			msgtype = KEY_BUF[KEY_BUF_readcount].flag;
			switch(msgtype)
			{
				case SM_KEY:
					break;
				case SM_KEYDOWN:
					act_cyc(KEYSCANTIMER,TCY_ON|TCY_INI);
				case SM_KEYREPEAT:
					break;					
				case SM_KEYUP:					
					if( KEY_BUF[KEY_BUF_readcount].keyvalue == KEY_Cancel )
					{
						quit = 1;
					}
					KeyEnable();
					break;
					
				default:
					break;
			}
			KEY_BUF_readcount++;
			if (KEY_BUF_readcount >= MAX_KEY_BUF)
				KEY_BUF_readcount = 0;	
		}
#endif				////gfd 		
		if( flgptn & TASKMSG_FLG )
		{
			process_msg();
		}

		
		clr_flg( SYS_EVENT, ~ALLINT_FLG );
		flgptn = 0;
	
////		if (KEY_BUF_readcount != KEY_BUF_writecount)
////			flgptn |= INTKEY_FLG;
		if (PEN_BUF_readcount != PEN_BUF_writecount)
			flgptn |= INTPEN_FLG;
		
		/* yes */
		if( flgptn > 0x1 )
			set_flg(SYS_EVENT, flgptn);
	}
	
	en_disp_ad = 0;
	
	gLcdOwnerTskId = lastid;
	
	loc_cpu();
	dbgprintf("Clear SYSEVENT\n");
	clr_flg(SYS_EVENT, ~ALLINT_FLG); 	/* clear SYSEVENT */
	unl_cpu();

////	EnableUartInt( UART_ALL );	// enable uart interrupt
	SysFreeGC( pGC );
	
	dbgprintf("Systask Init End\n\n");
}


void InitialSystem()
{
	DWORD	hGC;
	char	inforstr[50];
	WORD	info_y;
	DWORD	result = 0;

	hGC = SysInitGC(PHY_LCD_W, PHY_LCD_H);
	gSysTcbTbl[SYSTASK_ID-1].gc = (GC *)hGC;
	gLcdOwnerTskId = SYSTASK_ID;
	SysClearScreen( hGC, GPC_WHITE );

	// System Initial
	// Initialize file system
	info_y = 10;
	SysTextOut( hGC, GPC_BLACK, 10, info_y, "初始化文件系统.....", GPC_REPLACE_STYLE );
	result = InitFileSystem();
	if( result != 0 )
	{
		info_y += 16;
		sprintf( inforstr, "FAIL!(0x%08x)", result );
		SysTextOut( hGC, GPC_BLACK, 10, info_y, inforstr, GPC_REPLACE_STYLE );
	}
	else
	{
		info_y += 16;
		SysTextOut( hGC, GPC_BLACK, 10, info_y, "OK!", GPC_REPLACE_STYLE );
	}
	
	// Create Application Data Base
	info_y += 16;
	SysTextOut( hGC, GPC_BLACK, 10, info_y, "初始化数据库.....", GPC_REPLACE_STYLE );
	CreateDataBase();
	info_y += 16;
	if( result != 0 )
	{
		sprintf( inforstr, "FAIL!(0x%08x)", result );
		SysTextOut( hGC, GPC_BLACK, 10, info_y, inforstr, GPC_REPLACE_STYLE );
	}
	else
		SysTextOut( hGC, GPC_BLACK, 10, info_y, "OK!", GPC_REPLACE_STYLE );

	// initialize GSM module
	info_y += 16;
	SysTextOut( hGC, GPC_BLACK, 10, info_y, "初始化GSM.....", GPC_REPLACE_STYLE );
////	result = InitGSM();
	info_y += 16;
	if( result != 0 )
	{
		sprintf( inforstr, "FAIL!(0x%08x)", result );
		SysTextOut( hGC, GPC_BLACK, 10, info_y, inforstr, GPC_REPLACE_STYLE );
	}
	else
		SysTextOut( hGC, GPC_BLACK, 10, info_y, "OK!", GPC_REPLACE_STYLE );
	
	
	SysFreeGC( hGC );
}



/* init systcb table */
void SysTcbTableInit( void )
{
	int i;
	
	memset(gSysTcbTbl, 0, sizeof(SYSTCB)*TASKNUM);
	
	/* gSysTcbTbl init */
	for(i=0;i<TASKNUM-1;i++)
	{
		gSysTcbTbl[i].next = &gSysTcbTbl[i+1];
		gSysTcbTbl[i].id = (DWORD)&gSysTcbTbl[i];
		gSysTcbTbl[i].status = DORMANT;
	}
	gSysTcbTbl[i].next = NULL;
	gSysTcbTbl[i].id = (DWORD)&gSysTcbTbl[i];
	gSysTcbTbl[i].status = DORMANT;
}

#if 0		////gfd del...
void power_down(void)
{
	register UINT old_imr;
	
	
	//extern void TurnOffLCD( void );
	
	
	
#ifndef PCTLR
#define PCTLR *((unsigned char *)0xFFFFF207 )	/* Power Control Register */
#endif
#ifndef PLLCR
#define PLLCR *((unsigned short *)0xFFFFF200 )	/* PLL Control Register */
#endif
	
	/*************************************************************\
	 *  DISPATCH FORBIDDEN
	\*************************************************************/
	dis_dsp();
	
	/* Mask all interrupts */
	old_imr = IMR;
	IMR = 0xFFFFFFFF;

	
	/* Turn off LCD. */
	TurnOffLCD();
	/* Change RTC's frequence to 1Hz. */
	//set_rtc( RTCIENR_1HZ );
	stop_rtc();
	/* change sys_clk()'s tick */
	g_uhIntTime = 1000;  /* 1000/RTC's frequence(1Hz) */
	
	/* Restore all interrupts */
	//IMR &= ( ( old_imr |IMR_MTMR1 ) & ( ~IMR_MRTC ) );

	/* Close PLL */
	PLLCR |= 0x0008;
	asm("	STOP #$2000");
	
	/* CPU halt! */
	/* .............  */
	
	IMR = old_imr;
	TurnOnLCD();
	ena_dsp();
	
	/*************************************************************\
	 *  DISPATCH OK
	\*************************************************************/
}

#endif 		////gfd end

⌨️ 快捷键说明

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