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

📄 systask.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************
 *  Copyright (C) Asic Center. 2001
 *  All Rights Reserved
 *
 *  Filename : systask.c
 *  Function : System Task
 *  Revision :
 *          2001/09/20     Pessia     Create this file;
 *          2001/10/9	Pessia	Modify KeyScanHandler & TouchPanelHandler 
 *							       for iset_flg at 4 places;
 *          2001/10/10	Pessia	Add SysTableInit() to initial gTskDspTbl;
 *          2002/3/13       Pessia     Move those global variables and functions associated 
 *                                                     with devices to files of these devices;
 *                                               Add init_key_pen_buf() to init KEY_BUF , PEN_BUF 
 *                                                     and so on;
 *                                               Delete all things about AT;
 *                                               Fix a bug about looking for new events after dealing
 *                                                      with last events in the end of process_int() and 
 *                                                      process_msg();
 *          2002/3/16      Pessia      Add code to enable shell catch some special key 
 *                                                      message to send SM_SWITCH
 *          2002/3/16      Pessia      Fix some bug of [case SM_SWITCH]
 ************************************************************************/
#include <stdio.h>
#include <string.h>
#include "ros33.h"

//#include "at.h"
//#include "key.h"
#include "pen.h"
         
#include "systsk.h"
#include "sysmsg.h"
#include "syserr.h"
#include "ppsmmsg.h"
#include "devmng.h"
#include "atv.h"
//#include "rtc.h"
#include "gpc.h"
#include "systmr.h"
#include "taskdsp.h"
#include "lmalloc.h"
//#include "keydef.h"

//#include "uart.h"
#include "itron.h"
#include "sysdebug.h"
#include "M68328.h"
#include "pwrctrl.h"

#include "FAL.h"

DWORD 	EveryMinuteTimer;
DWORD 	EveryHourTimer;
DWORD 	EveryDayTimer;

extern UH g_uhIntTime;     // interrupt time

void Systask( void );
////void power_down(void);

/* Prototype of  Static Functions */
static void systaskinit(void);
static void process_int(UINT flgptn);
static void process_msg(void);
static void PenCalibration(void);

/* Prototype of  Extern Functions */
extern unsigned int GFD_InitFatFS(int deviceno);
extern STATUS ASIXInit(void);
extern unsigned long InitFileSystem( void );

extern void TouchPanelHandler(void);
////extern void KeyScanHandler(void);
extern void PenEnable(void);

////extern DWORD InitGSM( void );
////extern DWORD CreateDataBase( void );
////extern unsigned long InitFileSystem( void );

extern void InitialSystem( void );


#define POS_WUCHA 5
WORD	en_disp_ad = 0;

/* gTskDspTbl will be initialed by SysTableInit() 
  * which is called by taskmain().	 */
SYSTCB	gSysTcbTbl[TASKNUM];	/* Global Task Control Block Table */
ID 		gLcdOwnerTskId=0;		/* task id of LCD owner */
SYSTCB	*CurTask=NULL;			/* point to current app task's link entry */
SYSTCB	*TaskHead=NULL;		/* Application Task List */

BYTE	SystemStart = 0;

/* Variables for Pen Calibration */
static float kx = 0;
static float bx = 0;
static float ky = 0;
static float by = 0;

static short amx1, amx2, amy1, amy2;		////for gfd

#define  TS_CAL_X(__x__)   219 * __x__ / (amx2 - amx1) + 10 - 219 * amx1 / (amx2 - amx1)
#define  TS_CAL_Y(__y__)   299 * __y__ / (amy2 - amy1) + 10 - 299 * amy1 / (amy2 - amy1)

static unsigned short PendownFlag=0;
static unsigned short AD_Value_Is_Read=0;/* Register how many times AD has been read */

static POINTS kp[256];
static BYTE kpcount = 0;

static DWORD lastpenxy;
static short last_x,last_y;
static short next_x,next_y;

//extern BYTE	array_memory[];
extern int Ttimes;
extern int Itimes;

/******************************************************************
 *	Function Name: 	Systask	
 *	Param in:		void
 *  Result code:	void
 *	Description:	system task receive and handle event infinite
 ******************************************************************/	
void Systask( void )
{
	static UINT flgptn;
	FAL_FILE fd;
	int lenth;
	int *surbuff;

////	dbgprintf("Systask Init Started\n");

	systaskinit();
	SystemStart = 1;
	
	Ttimes = 0;
	Itimes = 0;
		
	while(1) 
	{
		/* initial flgptn */
		flgptn = 0;
////		dbgprintf("wait\n");

		/* wait for Interrupt or Tasks' Message */
		wai_flg(&flgptn, SYS_EVENT, 0x000000FF, TWF_ORW);
////		dbgprintf("got int\n");

		/* check whether interrupt happend */
		if(flgptn > 0x1)
			process_int(flgptn);

		/* check whther Tasks' message came */
		if(flgptn & 0x1)
			process_msg();
	}
}

/*****************************************************************
*  Function Name: process_int 
*  Param in:	UINT flgptn
*  Result code:	void							
*  Description: process Interrupt indicated by event
*****************************************************************/
static void process_int(UINT flgptn)
{
	MSG 	newmsg;
	MSG		ppsmmsg;
	ID		destid;		/* destination */
	BYTE	msgtype;	/* message type */
	static BYTE	pen_clb_cnt = 0;
	static BYTE	power_down_cnt = 0;
	BYTE	en_pen_clb = 0, en_power_down = 0;

	/* check if it is GSM_RING interrupt or not */
	// Just test code!!!
	/*
	if( flgptn & INTGSM_RING_FLG )
	{
		// clear this event
		clr_flg(SYS_EVENT, ~INTGSM_RING_FLG);

		// disable GSM_RING interrupt 
		*(volatile unsigned char *)0x40270 &= ~0x04;

		newmsg.message = 0x400;//test
		// setflg TIMER_EVENT
		SysSendMessage(6, &newmsg);// to c task
	}
	*/

#if 0			////gfd del...	
	/* check if it is KEY Interrupt or not */
	/* here, we think there must be new event in buffer */
	/* so we needn't check KEY_BUF_readcount =?= KEY_BUF_writecount */
	if( flgptn & INTKEY_FLG )
	{	
		msgtype = KEY_BUF[KEY_BUF_readcount].flag;
		// dest task should be the one which has LcdScreen now!
		destid = gLcdOwnerTskId;
		
		// make sure that destination is running
		if( gSysTcbTbl[destid-1].status == RUNNING )
		{
			switch(msgtype)
			{
				case SM_KEY:
					break;
				
				// SM_KEYDOWN and SM_KEYREPEAT is not sent
				case SM_KEYDOWN:
					//PenDisable();
					act_cyc(KEYSCANTIMER,TCY_ON|TCY_INI);
					/*
					/////////////////////////////////////////////////
					//pessia2002/3/16:
					//System Catch Special Key, switch to SHELL
					if( KEY_BUF[KEY_BUF_readcount].keyvalue == 1)
					{
						ppsmmsg.message = SM_SWITCH;
						ppsmmsg.wparam = 0;
						SysSendMessage(SYSTASK_ID, &ppsmmsg);
						break;
					}
					/////////////////////////////////////////////////
					*/
				case SM_KEYREPEAT:
					switch( KEY_BUF[KEY_BUF_readcount].keyvalue )
					{
						case KEY_Down:
							pen_clb_cnt++;
							break;
						case KEY_POWER_DOWN:
							power_down_cnt++;
							break;
					}
					break;					
				case SM_KEYUP:
					switch( KEY_BUF[KEY_BUF_readcount].keyvalue )
					{
						case KEY_Down:
							pen_clb_cnt > 30;
							pen_clb_cnt = 0;
							en_pen_clb = 1;
							break;
						case KEY_POWER_DOWN:
							power_down_cnt > 30;
							power_down_cnt = 0;
							en_power_down = 1;
							break;
						default:
							pen_clb_cnt = 0;
							power_down_cnt = 0;
							break;
					}
					//newmsg.message = msgtype;
					//newmsg.wparam = KEY_BUF[KEY_BUF_readcount].keyvalue;
					
					//dbgoutput("Systask sent KEY message to task(%s)\n",findtskname(destid));
					//SysSendMessage(destid, &newmsg);					
					
					
					dbgoutput("Systask sent KEY message to task(%s)\n",findtskname(destid));
//					ppsmmsg.message = IRPT_KEY;
//					ppsmmsg.lparam = GetFocus();
//					ppsmmsg.wparam = KEY_BUF[KEY_BUF_readcount].keyvalue;
					AsixTransKeyMsg( &ppsmmsg, &KEY_BUF[KEY_BUF_readcount] );
					SysSendMessage(destid, &ppsmmsg);
					
					//PenEnable();
					break;
					
				default:
					break;
			}
		}
		
		KEY_BUF_readcount++;
		if (KEY_BUF_readcount >= MAX_KEY_BUF)
			KEY_BUF_readcount = 0;	
		clr_flg(SYS_EVENT,~INTKEY_FLG);
		if( en_pen_clb )
		{	
			// pen calibration
			ID	tempId;
			VRAM	*vram;

			// pen calibration
			tempId = gLcdOwnerTskId;
			PenCalibration();
			gLcdOwnerTskId = tempId;
			vram = gSysTcbTbl[gLcdOwnerTskId-1].gc->vram;
			Write2LCD( 0, 0, PHY_LCD_W-1, PHY_LCD_H-1, vram );
			en_pen_clb = 0;
		}
		if( en_power_down )
		{
			// power down
			power_down();
			en_power_down = 0;
		}				
	}
#endif			////gfd end for intkey
		
	/* check if it is PEN Interrupt or not */
	if( flgptn & INTPEN_FLG )
	{  
		msgtype = PEN_BUF[PEN_BUF_readcount].flag;
		destid = gLcdOwnerTskId;
		
		// make sure that destination is running
////		gSysTcbTbl[destid-1].status = RUNNING;		////for debug, I add this instruction
		if( gSysTcbTbl[destid-1].status == RUNNING )
		{
			switch(msgtype)
			{
				case SM_PENDOWN:
					last_x = 0;
					last_y = 0;
					lastpenxy = 0;
					//KeyDisable();
					act_cyc(TOUCHTIMER,TCY_ON|TCY_INI);
					break;
					
				case SM_PENMOVE:
////					next_x = kx * PEN_BUF[PEN_BUF_readcount].x + bx;
////					next_y = ky * PEN_BUF[PEN_BUF_readcount].y + by;
					next_x = TS_CAL_X(PEN_BUF[PEN_BUF_readcount].x)+2;
					next_y = TS_CAL_Y(PEN_BUF[PEN_BUF_readcount].y)+4;
					////next_x = 240 - next_x;			////gfd add next two line
					////next_y = 320 - next_y;
					
					if (!PendownFlag)
					{	
						// first touch panel, message should be SM_PENDOWN.
						// otherwise, message is SM_PENMOVE .
						newmsg.message = SM_PENDOWN;
						last_x = next_x;
						last_y = next_y;
						PendownFlag = 1;
					}
					else
					{
						
						// check AD value
						/*
						if ( next_x > last_x + POS_WUCHA 
							|| next_x < last_x - POS_WUCHA
							|| next_y > last_y + POS_WUCHA 
							|| next_y < last_y - POS_WUCHA )
						{
							//AD value is not right
							//break;
							next_x = last_x;
							next_y = last_y;
						}
						*/
						/*
						if ( next_x > last_x + POS_WUCHA )
							next_x = last_x + POS_WUCHA;
						else if ( next_x < last_x - POS_WUCHA )
							next_x = last_x - POS_WUCHA;
						
						if ( next_y > last_y + POS_WUCHA )
							next_y = last_y + POS_WUCHA;
						else if ( next_y < last_y - POS_WUCHA )
							next_y = last_y - POS_WUCHA;
						*/
						newmsg.message = SM_PENMOVE;
						last_x = next_x;
						last_y = next_y;
					}
					
					// Here is different with Asixwin
					// Because Asixwin uses .data to keep pointer to coordinate info(x&y).
					// Here, we use .lparam instead of pointer .data
					((POINTS *)&newmsg.lparam)->x = next_x;
					((POINTS *)&newmsg.lparam)->y = next_y;
					
					// save this coordinate
					lastpenxy = newmsg.lparam;
					
					kp[kpcount++] = *((POINTS *)&lastpenxy);
					
////					dbgoutput("Systask get PEN int: %4x\n",msgtype);
					
					// Add ACTIVEAREA Module:
					//	Ros33 message will be translated into PPSM message!
					//
					ppsmmsg.message = IRPT_NONE;
					ppsmmsg.data = (void *)lastpenxy;
					SysTransMsg(&newmsg, gSysTcbTbl[destid-1].atvcb, &ppsmmsg);
					if(ppsmmsg.message != IRPT_NONE)
					{
////						dbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
////						dbgoutput("              PEN message: %4x\n", ppsmmsg.message);
						SysSendMessage(destid, &ppsmmsg);
					}	
					// Send additional IRPT_PEN(-1,-1) message while PPSM_INPUT_DRAG_UP 
					//& PPSM_INPUT_PEN_UP	in INPUTAREA which uses CONTINIOUS mode.
					if( ppsmmsg.lparam == PPSM_INPUT_DRAG_UP || ppsmmsg.lparam == PPSM_INPUT_PEN_UP )
////					if( ppsmmsg.wparam == PPSM_INPUT_DRAG_UP || ppsmmsg.wparam == PPSM_INPUT_PEN_UP )
					{
////						dbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
////						dbgprintf("              PEN message:IRPT_PEN(31)(-1,-1)\n");
						// 2001-11-22 23:02
						ppsmmsg.message = IRPT_PEN;
						
						((POINTS *)&ppsmmsg.lparam)->x = -1;
						((POINTS *)&ppsmmsg.lparam)->y = -1;
						SysSendMessage(destid, &ppsmmsg);
					}
										
					break;
					
				case SM_PENUP:
					if (PendownFlag)
					{ 
						PendownFlag = 0;
						
						newmsg.message = SM_PENUP;
						
						// here, coordinate in penup is the same as last one in penmove
						if ( lastpenxy != 0 )
							newmsg.lparam = lastpenxy;
						else{
//							PenEnable();
							break;
						}
						
////						dbgoutput("Systask get PEN int: %4x\n",msgtype);
						
						// Add ACTIVEAREA Module:
						//	Ros33 message will be translated into PPSM message!
						//
						ppsmmsg.message = IRPT_NONE;
						ppsmmsg.data = (void *)lastpenxy;
						SysTransMsg(&newmsg, gSysTcbTbl[destid-1].atvcb, &ppsmmsg);
						if(ppsmmsg.message != IRPT_NONE)
						{
////							dbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
////							dbgoutput("              PEN message: %4x\n", ppsmmsg.message);
							SysSendMessage(destid, &ppsmmsg);
						}	
						// Send additional IRPT_PEN(-1,-1) message while PPSM_INPUT_DRAG_UP 
						//& PPSM_INPUT_PEN_UP	in INPUTAREA which uses CONTINIOUS mode.
						if( ppsmmsg.lparam == PPSM_INPUT_DRAG_UP || ppsmmsg.lparam == PPSM_INPUT_PEN_UP )
////						if( ppsmmsg.wparam == PPSM_INPUT_DRAG_UP || ppsmmsg.wparam == PPSM_INPUT_PEN_UP )
						{
////							dbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
////							dbgprintf("              PEN message:IRPT_PEN(31)(-1,-1)\n");
							// 2001-11-22 23:02
							ppsmmsg.message = IRPT_PEN;
						
							((POINTS *)&ppsmmsg.lparam)->x = -1;
							((POINTS *)&ppsmmsg.lparam)->y = -1;
							SysSendMessage(destid, &ppsmmsg);	
						}
						
						kp[kpcount].x = 0;
						kp[kpcount++].y = 0;
					}
//					PenEnable();			
					//KeyEnable();
					break;

⌨️ 快捷键说明

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