📄 systask.c
字号:
/*************************************************************************
*
* 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 & gDevUseTbl
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <kernel\ros33\ros33.h>
//#include <sys\at.h>
//#include <sys\key.h>
//#include <sys\pen.h>
#include <sys\systsk.h>
#include <sys\sysmsg.h>
#include <sys\syserr.h>
#include <sys\ppsmmsg.h>
#include <sys\devmng.h>
#include <sys\atv.h>
#include <sys\gpc.h>
#include <sys\systmr.h>
#include <sys\taskdsp.h>
#include <sys\lmalloc.h>
#include <asixwin.h>
#include <asixapp.h>
#include <sys\sysdebug.h>
// simulator header
#include <simdrv\export\driver.h>
/* gTskDspTbl & gDevUseTbl will be initialed by SysTableInit() which is called by
* taskmain(). */
SYSTCB gSysTcbTbl[TASKNUM]; /* Global Task Control Block Table */
/* interrupt data buf and read/write pointer*/
unsigned short xpos,ypos,PendownFlag=0;
UW passedticks=0; /* Used to record how many ticks have passed */
/* it should be clear when system init */
UW currentclock=0; /* Record current clock */
ID gLcdOwnerTskId=0; /* task id of LCD owner */
//static float kx = 0;
//static float bx = 0;
//static float ky = 0;
//static float by = 0;
//SYSTCB *CurTask=NULL; /* point to current app task's link entry */
SYSTCB *TaskHead=NULL; /* Application Task List */
DWORD EveryMinuteTimer;
DWORD EveryHourTimer;
DWORD EveryDayTimer;
//extern void LCD_refresh();
//extern void KEYO3_0(unsigned char data);
//extern unsigned char Get_TK_coordinate(unsigned short *xposition, unsigned short *yposition);
/* we should run rtc in systaskinit() */
void run_rtc(void);
extern void TouchPanelHandler(void);
extern void KeyScanHandler(void);
extern void PenEnable(void);
//extern DWORD InitGSM( void );
extern DWORD CreateDataBase( void );
extern void InitFileSystem( void );
extern void InitialSystem( void );
void Systask( void );
static void systaskinit();
static void process_int(UINT flgptn);
static void process_msg();
static void PenCalibration( void );
/* init Asixwin in systaskinit() */
extern STATUS ASIXInit(void);
/********************************************************************************
* Function Name: Systask
* Param in: void
* Result code: void
* Description: system task receive and handle event infinite
********************************************************************************/
void Systask( void )
{
static UINT flgptn;
systaskinit();
// FlashWriteBlock( CHINESE_FONT_LIB_START, (DWORD)GPCFONT11K, CHINESE_FONT_LIB_SIZE );
while(1) {
/* initial flgptn */
flgptn = 0;
/* wait for Interrupt or Tasks' Message */
wai_flg(&flgptn, SYS_EVENT, 0xFF, TWF_ORW);
/* check whether interrupt happend */
if(flgptn > 0x1)
{
// dbgprintf( "systask get interrupt!" );
process_int(flgptn);
}
/* check whther Tasks' message came */
if(flgptn & TASKMSG_FLG )
{
// dbgprintf( "systask get message!" );
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 */
//UB msgtype; // message type
static UW lastpenxy;
UB penRes = BUF_EMPTY, keyRes = BUF_EMPTY;
//char str[30];
static UB pen_clb_cnt;
memset( &newmsg, 0, sizeof(MSG) );
memset( &ppsmmsg, 0, sizeof(MSG) );
/* check if it is Timer Interrupt or not */
if( flgptn & INTTIMER_FLG )
{
/* clear this event */
clr_flg(SYS_EVENT, ~INTTIMER_FLG);
/* setflg TIMER_EVENT */
set_flg(TIMER_EVENT, TIMER_FLG);
}
/* 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 )
{
// ( longn_qi 2001/10/31 revised )
KEYDATA keydata;
// debug
#ifdef _DEBUG_STATUS_
AddKeyLog(gMsgLog, &KEY_BUF[KEY_BUF_readcount]);
#endif
//msgtype = KEY_BUF[KEY_BUF_readcount].flag;
ReadKeyIntBuf( &keydata );
// 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( keydata.flag )//msgtype)
{
case SM_KEY:
break;
case SM_KEYDOWN:
//******************************************//
//pessia2002/3/16:
//System Catch Special Key, switch to SHELL
if( keydata.keyvalue == KEY_Down)
pen_clb_cnt = 0;
break;
//*****************************************//
case SM_KEYREPEAT:
if( keydata.keyvalue == KEY_Down )
{
pen_clb_cnt++;
}
break;
case SM_KEYUP:
if( keydata.keyvalue == KEY_Down && pen_clb_cnt > 5 )
{
// 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 );
pen_clb_cnt = 0;
break;
}
/*
newmsg.message = keydata.flag;//msgtype;
newmsg.wparam = keydata.keyvalue;//KEY_BUF[KEY_BUF_readcount].keyvalue;
dbgoutput("Systask sent KEY message to task(%s)\n",findtskname(destid));
SysSendMessage(destid, &newmsg);
*/
//ppsmmsg.messageType = PPSM_MESSAGE;
AsixTransKeyMsg( &ppsmmsg, &keydata );
SysSendMessage(destid, &ppsmmsg);
break;
default:
break;
}
}
//KEY_BUF_readcount++;
//if (KEY_BUF_readcount >= MAX_KEYBUF)
// KEY_BUF_readcount = 0;
clr_flg(SYS_EVENT,~INTKEY_FLG);
}
/* check if it is PEN Interrupt or not */
if( flgptn & INTPEN_FLG )
{
PENDATA pendata;
/* debug */
#ifdef _DEBUG_STATUS_
AddPenLog(gMsgLog, &PEN_BUF[PEN_BUF_readcount]);
#endif
//msgtype = PEN_BUF[PEN_BUF_readcount].flag;
ReadPenIntBuf( &pendata );
destid = gLcdOwnerTskId;
/* make sure that destination is running */
if( gSysTcbTbl[destid-1].status == RUNNING )
{
switch( pendata.flag )
{
case SM_PENDOWN:
//act_cyc(TOUCHTIMER,TCY_ON|TCY_INI);
break;
case SM_PENMOVE:
if (!PendownFlag)
{
/* first touch panel, message should be SM_PENDOWN. */
/* otherwise, message is SM_PENMOVE .*/
newmsg.message = SM_PENDOWN;
PendownFlag = 1;
msgdbgprintf( "Pen Down\n" );
}
else
{
msgdbgprintf( "Pen Move" );
newmsg.message = SM_PENMOVE;
}
/* 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 = pendata.x;
((POINTS *)&newmsg.lparam)->y = pendata.y;
/* save this coordinate */
lastpenxy = newmsg.lparam;
/* 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)
{
msgdbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
msgdbgoutput(" 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 )
{
msgdbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
msgdbgprintf(" 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;
msgdbgprintf( "Pen Up" );
/* here, coordinate in penup is the same as last one in penmove */
newmsg.lparam = lastpenxy;
/* 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)
{
msgdbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
msgdbgoutput(" 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 )
{
msgdbgoutput("Systask sends PEN message to task(%s)\n",findtskname(destid));
msgdbgprintf(" 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;
default :
break;
}
}
//PEN_BUF_readcount++;
//if (PEN_BUF_readcount >= MAX_PENBUF)
// PEN_BUF_readcount = 0;
clr_flg(SYS_EVENT,~INTPEN_FLG);
}
/* to add new interrupt handle code here... */
/* ................. */
/* now, we think all events except Tasks' message have been handled */
flgptn &= 0x1;
/* check if any interrupt happened while executing above code */
/* yes, setflg SYS_EVENT to avoid missing event */
/* even some event was setflg again, it is still worthy */
/* problem : how to know whether Timer Interrupt happened or not? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -