📄 systask.c
字号:
flgptn = 0;
/*
if (AT_BUF_readcount != AT_BUF_writecount)
flgptn |= INTAT_FLG;
else if (KEY_BUF_readcount != KEY_BUF_writecount)
flgptn |= INTKEY_FLG;
else if (PEN_BUF_readcount != PEN_BUF_writecount)
flgptn |= INTPEN_FLG;
*/
//
// above code replaced by following code
if ( CheckKeyIntBuf( ) != BUF_EMPTY )
flgptn |= INTKEY_FLG;
else if ( CheckPenIntBuf( ) != BUF_EMPTY )
flgptn |= INTPEN_FLG;
// yes
if( flgptn > 0x1 )
set_flg(SYS_EVENT, flgptn);
return ;
}
/*****************************************************************
* Function Name: systaskinit
* Param in:
* Result code: void
* Description: system task init
*****************************************************************/
static void systaskinit()
{
SYSTIME pk_KeyScan,pk_TouchPanel, pk_RTC;
//SYSTIME pk_Idle,pk_Refresh;
//UB i;
//MSG msg;
dbgprintf("### Systask Init ###");
/* debug */
#ifdef _DEBUG_STATUS_
InitLog(gMsgLog);
#endif
/*
memset(KEY_BUF,0xff,sizeof(KEY_DATA) * MAX_KEYBUF);
memset(PEN_BUF,0,sizeof(PEN_DATA) * MAX_PENBUF);
memset(AT_BUF,0,sizeof(AT_DATA) * MAX_ATBUF);
KEY_BUF_readcount = KEY_BUF_writecount = 0;
PEN_BUF_readcount = PEN_BUF_writecount = 0;
AT_BUF_readcount = AT_BUF_writecount = 0;
memset(CurrentKey,0xff,MAX_KEYBUF );
for (i = 0; i<MAX_KEYBUF /2; i++)
CurrentKey[i*2+1] = 0;
*/
InitialSystem( );
InitPenIntBuf( );
InitKeyIntBuf( );
pk_KeyScan.utime = 0;
pk_KeyScan.ltime = 50; //100ms
def_cyc( KEYSCANTIMER, KeyScanHandler, TCY_OFF, &pk_KeyScan ); /* define KeyScan Cychndr */
act_cyc( KEYSCANTIMER, TCY_ON );
pk_TouchPanel.utime = 0;
pk_TouchPanel.ltime = 50; // 100ms
def_cyc( TOUCHTIMER, TouchPanelHandler, TCY_OFF, &pk_TouchPanel ); /* define reflash Cychndr */
act_cyc( TOUCHTIMER, TCY_ON );
/* pen calibrated!!! */
//PenCalibration();
/*
kx = -2.816901e-001F;
bx = 2.297183e+002F;
ky = -3.146067e-001F;
by = 2.541348e+002F;
*/
/* Initial Asixwin */
ASIXInit();
/* first application task is shell task */
/* It will be started in ASIXInit() */
/*
msg.message = SM_START;
msg.wparam = SHELL_ID;
SysSendMessage(SYSTASK_ID, &msg);
*/
/* start running rtc */
//run_rtc();
#define RTCTIMER 0
pk_RTC.utime = 0;
pk_RTC.ltime = 31;
def_cyc( RTCTIMER, 0, TCY_OFF, &pk_RTC );
act_cyc( RTCTIMER, TCY_ON );
dbgprintf("### Systask Init OK ###");
}
void PenCalibration( void )
{
CHAR PenDown=0, new_check = 1, quit=0, lefttop_pressed=0, rightbottom_pressed=0, center_pressed = 0;
static UINT flgptn;
GC *pGC;
CHAR showCross = 1;
// Create One GC
dbgprintf("Init GC\n");
pGC = (GC *)SysInitGC(PHY_LCD_W, PHY_LCD_H);
gSysTcbTbl[SYSTASK_ID-1].gc = pGC;
gLcdOwnerTskId = SYSTASK_ID;
// 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, LCD_WIDTH/32, LCD_HEIGHT/16+LCD_WIDTH/20, LCD_WIDTH*31/32, LCD_HEIGHT/3, "Pen Calibration: Please press left-top cross first, then right-bottom, and center last!", GPC_REPLACE_STYLE);
DisableUartInt( UART_ALL ); // disable uart interrupt
while(!quit)
{
if( showCross )
{
// (10,10)
SysDrawHorz(( DWORD )pGC, GPC_BLACK, LCD_WIDTH/32 - LCD_WIDTH/40, LCD_HEIGHT/16, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
SysDrawVert(( DWORD )pGC, GPC_BLACK, LCD_WIDTH/32, LCD_HEIGHT/16 - LCD_WIDTH/40, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
// (150,230)
SysDrawHorz(( DWORD )pGC, GPC_BLACK, LCD_WIDTH*31/32 - LCD_WIDTH/40 , LCD_HEIGHT*15/16, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
SysDrawVert(( DWORD )pGC, GPC_BLACK, LCD_WIDTH*31/32, LCD_HEIGHT*15/16 - LCD_WIDTH/40, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
// (80,120)
SysDrawHorz(( DWORD )pGC, GPC_BLACK, LCD_WIDTH/2 - LCD_WIDTH/40, LCD_HEIGHT/2, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
SysDrawVert(( DWORD )pGC, GPC_BLACK, LCD_WIDTH/2, LCD_HEIGHT/2 - LCD_WIDTH/40, LCD_WIDTH/20+1, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
showCross = 0;
}
flgptn = 0;
// wait for Interrupt or Tasks' Message
wai_flg(&flgptn, SYS_EVENT, 0xFF, TWF_ORW);
if( flgptn & INTPEN_FLG )
{
PENDATA pendata;
ReadPenIntBuf( &pendata );
// read pen message directly from interrupt buffer PEN_BUF
switch( pendata.flag )
{
case SM_PENDOWN:
break;
case SM_PENMOVE:
// if(!PenDown)
{
PenDown++;
if (!lefttop_pressed)
{
if( PenDown == 3 )
SysDrawCircle( (DWORD)pGC, GPC_BLACK, LCD_WIDTH/32, LCD_HEIGHT/16, LCD_WIDTH/40, GPC_REPLACE_STYLE );
}else if( !rightbottom_pressed )
{
if( PenDown == 3 )
SysDrawCircle( (DWORD)pGC, GPC_BLACK, LCD_WIDTH*31/32, LCD_HEIGHT*15/16, LCD_WIDTH/40, GPC_REPLACE_STYLE );
}else
{
if( new_check )
new_check = 0;
if( PenDown == 3 )
SysDrawCircle( (DWORD)pGC, GPC_BLACK, LCD_WIDTH/2, LCD_HEIGHT/2, LCD_WIDTH/40, GPC_REPLACE_STYLE );
}
}
break;
case SM_PENUP:
if( PenDown > 2 )
{
if ( rightbottom_pressed ){
center_pressed = 1;
SysClearRec(( DWORD )pGC, GPC_WHITE, LCD_WIDTH/2 - LCD_WIDTH/40, LCD_HEIGHT/2 - LCD_WIDTH/40, LCD_WIDTH/20+1, LCD_WIDTH/20+1, GPC_REPLACE_STYLE);
}
if (lefttop_pressed ){
rightbottom_pressed = 1;
SysClearRec(( DWORD )pGC, GPC_WHITE, LCD_WIDTH*31/32 - LCD_WIDTH/40, LCD_HEIGHT*15/16 - LCD_WIDTH/40, LCD_WIDTH/20+1, LCD_WIDTH/20+1, GPC_REPLACE_STYLE);
}
if (!lefttop_pressed ){
lefttop_pressed = 1;
SysClearRec(( DWORD )pGC, GPC_WHITE, LCD_WIDTH/32 - LCD_WIDTH/40, LCD_HEIGHT/16 - LCD_WIDTH/40, LCD_WIDTH/20+1, LCD_WIDTH/20+1, GPC_REPLACE_STYLE);
}
if ( center_pressed ){
new_check = 1;
quit = 1;
}
}
PenDown = 0;
break;
default:
break;
}
clr_flg( SYS_EVENT, ~ALLINT_FLG );
}
if( flgptn & INTKEY_FLG )
{
KEYDATA keydata;
//msgtype = KEY_BUF[KEY_BUF_readcount].flag;
ReadKeyIntBuf( &keydata );
switch( keydata.flag )//msgtype)
{
case SM_KEYUP:
if( keydata.keyvalue == KEY_Cancel )
{
quit = 1;
}
break;
default:
break;
}
//KEY_BUF_readcount++;
//if (KEY_BUF_readcount >= MAX_KEYBUF)
// KEY_BUF_readcount = 0;
clr_flg(SYS_EVENT,~INTKEY_FLG);
}
flgptn &= 0x1;
if ( CheckPenIntBuf( ) != BUF_EMPTY )
flgptn |= INTPEN_FLG;
else if ( CheckKeyIntBuf( ) != BUF_EMPTY )
flgptn |= INTKEY_FLG;
// yes
if( flgptn > 0x1 )
set_flg( SYS_EVENT, flgptn );
}
SysFreeGC( (DWORD)pGC );
gSysTcbTbl[SYSTASK_ID-1].gc = NULL;
clr_flg(SYS_EVENT, ~ALLINT_FLG ); // clear SYSEVENT
EnableUartInt( UART_ALL ); // enable uart interrupt
}
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;
ClearScreen( hGC, GPC_WHITE );
// System Initial
// Initialize file system
info_y = 10;
TextOut( hGC, "初始化文件系统.....", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
InitFileSystem();
info_y += 16;
TextOut( hGC, "OK!", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
// Create Application Data Base
info_y += 16;
TextOut( hGC, "初始化数据库.....", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
CreateDataBase();
info_y += 16;
if( result != 0 )
{
sprintf( inforstr, "FAIL!(0x%08x)", result );
TextOut( hGC, inforstr, 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
}
else
TextOut( hGC, "OK!", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
// initialize GSM module
info_y += 16;
TextOut( hGC, "初始化GSM.....", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
result = 0; //InitGSM();
info_y += 16;
if( result != 0 )
{
sprintf( inforstr, "FAIL!(0x%08x)", result );
TextOut( hGC, inforstr, 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
}
else
TextOut( hGC, "OK!", 10, info_y, NULL, GPC_BLACK, GPC_REPLACE_STYLE );
SysFreeGC( hGC );
}
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].description = &gTskDspTbl[i]; // move to AsixTaskInit()
//gSysTcbTbl[i].entryCallback = NULL;
//gSysTcbTbl[i].exitCallback = NULL;
//gSysTcbTbl[i].wnd_ptr = NULL;
//gSysTcbTbl[i].atvcb = NULL;
//gSysTcbTbl[i].gc = NULL;
}
gSysTcbTbl[i].next = NULL;
gSysTcbTbl[i].id = (DWORD)&gSysTcbTbl[i];
gSysTcbTbl[i].status = DORMANT;
}
void LosePower( void )
{
ID i;
// TASKDESCRIPTIONLIST *p;
act_cyc( RTCTIMER, TCY_OFF );
act_cyc( KEYSCANTIMER, TCY_OFF );
act_cyc( TOUCHTIMER, TCY_OFF );
SysFreeTimer(EveryMinuteTimer);
SysFreeTimer(EveryHourTimer);
SysFreeTimer(EveryDayTimer);
FreeUart( );
SysClearScreen( (UW)gSysTcbTbl[gLcdOwnerTskId-1].gc, GPC_WHITE );
for( i = SYSTASK_ID; i < TASKNUM; i++ )
ter_tsk( i );
for( i = SYSTASK_ID; i < TASKNUM; i++ )
{
SysFreeGC((DWORD)gSysTcbTbl[i-1].gc);
SysFreeATVCB(gSysTcbTbl[i-1].atvcb);
if( gSysTcbTbl[i-1].description == NULL )
continue;
if( i < APP_ID_BEGIN )
continue;
SysLfree( gSysTcbTbl[i-1].description->stack );
SysLfree( gSysTcbTbl[i-1].description );
}
/* p = TaskDescription;
while( p != NULL )
{
TaskDescription = p->next;
SysLfree( p );
p = TaskDescription;
}
*/
FreeLCD( );
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -