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

📄 asixapp.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
*
* Copyright  2000 National ASIC Center, All right Reserved
*
* FILE NAME:			asixapp.c
* PROGRAMMER:			Lingming
* Date of Creation:		2001/08/29
* 
* DESCRIPTION: 			The task related part of asix window system. 
*						Include the Initial and task creataion,end and
*						so on. this file offers the Application Programmer
*                       the ASIX Window task API.
*
* NOTE:			 		 
*						 
*
* FUNCTIONS LIST:
* -------------------------------------------------------------------------
* 
* SYSTCB *ASIXCreateTask (TASKDESCRIPTION *description)
* STATUS ASIXKillTask(SYSTCB *taskptr)
* STATUS EndofTask(void)
* SYSTCB *TaskLookUp(TASKDESCRIPTION *desptr)
* STATUS EntryCallBack(U32 prev_taskid)
* STATUS ExitCallBack (U32 next_taskid)
* TASKDESCRIPTION *TaskRegist(TASKDESCRIPTION *tasktemp)
* STATUS TaskUnRegist(TASKDESCRIPTION *taskptr)
* void SysDeamon(void)
* void SysSleep(void)
* 
* GLOBAL VARS LIST:
* 
*
* TaskDescription[]		the table descripts the application relevent
*						information such as app name, stack size ,etc
*						it is also a const table which means the infor
*						in this table will not be changed during running  
* 
* CurTask				the pointer that point to current task 
* 
* TaskHead				the head pointer of the task list
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2001/08/29	by Lingming		Creation of this file
* 2001/08/29	by Lingming		seperate the task related part from window
*								operating part	
* 2001/10/26	by Lingming		in EntryCallBack() we donot need to scan the
*								window list anymore because we insert new 
*								created win at the head of the list								
* 2001/11/28	by Lingming		in ExitCallBack(),add font size getting
* 2002/03/09    by Lingming		We add GetCurTask() to replace the old PPSM version's 
*								CurTask. Now we can discard the Entry and Exit Call back.
*								The app which is running can get itselves Systcb ptr. 				
* 2002/3/13      by Pessia      move AsixTaskInit() here from shell.c
* 2002/09/10	by longn_qi		added function "CreateDynamicTask"
* 2002/09/11	by longn_qi		added function "ASIXStartTask"
*								added function "IsRegistered"
*								added function "DynAllocateTskID"
*								added function "DynFreeTskID"
*								modified function "ASIXTaskInit"
*								modified function "TaskRegist"
*								modified function "TaskUnRegist"
*								modified function "ASIXTaskInit"
*************************************************************************/

/* SDS C lib */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* asix window include file*/
#include "asixwin.h"
#include "asixapp.h"
#include "asix_wn.h"
#include "asix_tb.h"
#include "asixdbg.h"

#include "atv.h"

/* The following icons are stored in bmpdata.c
 * We will put all icons in one file when we 
 * finished the project.
 */
extern const U8  news[];
extern const U8  xitong[];
extern const U8  yingyong[];
extern const U8  gupiao[];
extern const U8  dianhua[];
extern const U8  baozhiwangzhan[];
extern const U8  jishi[];
extern const U8  dingwei[];
extern const U8  xh1[];
extern const U8  e_mail[];

TASKDESCRIPTIONLIST *TaskDescription=NULL;//the task description list head(动态的)
//extern SYSTCB	*CurTask;		//point to current task's link entry
extern SYSTCB	*TaskHead;		//the head of the task link

ID	DynTskIDBegin = APP_ID_BEGIN;
SYSTCB	*DynTaskHead = &gSysTcbTbl[APP_ID_BEGIN-1];

/*下面这两个变量不是本C文件的内容,这儿定义只是为了测试*/
//struct MENU_ITEM	SysMenu_Item[MAX_SYSMENU+1];	/* the largest item number is 15 */
//SYSTCB				*SysMenu_Taskptr[MAX_SYSMENU+1];/* the last one is unused*/

extern void RegisterAppTask(  );
extern TASKDESCRIPTION	ShellTskDesp;
extern TASKDESCRIPTION PhoneTskDesp;
extern TASKDESCRIPTION CallCardTskDesp;
extern TASKDESCRIPTION NOTETskDesp;
extern TASKDESCRIPTION sampleTskDesp;

void AsixTaskInit( void )
{
//	U8	i;
//	ID	id;
//	TASKDESCRIPTIONLIST  *ptskdsp;
//	TASKDESCRIPTION	*desp;
//	DWORD *stack;
//	extern TASKDESCRIPTION TaskTemplate[];
	
////	dbgprintf( "### Asix Task Init ###\n");
	
	/* 
	  * When initial, TaskDescription should be NULL in order to 
	  * fit hot-reset-debugging	 */
#ifdef HOT_RESET_DEBUG_CODE_ENABLE
	TaskDescription = NULL;
#endif

//	for (i=0; TaskTemplate[i].name!=NULL; i++) 
//		TaskRegist((TASKDESCRIPTION *)&TaskTemplate[i]);	
	RegisterAppTask();
	Add2ShortcutTask( &ShellTskDesp );
	//Add2ShortcutTask( &PhoneTskDesp );

/*	for( ptskdsp = TaskDescription, id = APP_ID_BEGIN; 
		ptskdsp != NULL && id<TASKNUM ; 
		id++ , ptskdsp = ptskdsp->next)
	{
		desp = ptskdsp->desp;
		if( desp->entry != NULL )		
		{
			stack = (DWORD *)SysLmalloc(sizeof(DWORD) *
										(desp->stksize / 4) ); 
			// when got no mem, unregist this taskdsp, and continue. 
			//  modified by Pessia 01-11-25
			if(stack == NULL)
			{
				gSysTcbTbl[id-1].status = DORMANT;
				TaskUnRegist(ptskdsp);
				continue;
			}
	    		vcre_tsk(id,  desp->entry,  desp->pri, 
				(U32)(stack + (desp->stksize/4)) );
	    		gSysTcbTbl[id-1].status = DORMANT;
			gSysTcbTbl[id-1].description = ptskdsp;
			gSysTcbTbl[id-1].group = desp->group;
//			gSysTcbTbl[id-1].icon = (unsigned short *)ptskdsp->icon;//2002/5/8
			gSysTcbTbl[id-1].icon = (char *)desp->icon;
			//panic("CREATE TASK: ID=%d: ", id);
			//panic("NAME=%s: ", ptskdsp->name);
			//panic("ENTRY=%x\n", ptskdsp->entry);
    		}else {
    			panic("NULL ENTRY: ID=%d: ",id);
    			panic("NAME=%s\n", desp->name);
    		}
      }
	
	DynTskIDBegin = id;
	panic("CREATE TASK NUM: %d: \n", id-APP_ID_BEGIN+1);
*/
////	dbgprintf( "### Asix Task Init OK ###\n");
	return;
}

SYSTCB *ASIXCreateTask ( TASKDESCRIPTION *description )
{
	
	U32	taskid; 
//	SYSTCB 	*taskptr, *listptr;
	register U8 i;
	
	/* param check */
	if ( description == NULL || description->entry == NULL )
		return NULL;
	
	/* create the task */	
	if ( AdvTaskCreate( &taskid , (P_VOID)description->entry, -20, -20, -20, -20,
		description->stksize, description->newscreen, description->scr_w,
		description->scr_h, NULL) )
		return NULL;
		
	/* hook the callback funcs */
	TaskHook(taskid, (void *)EntryCallBack, (void *)ExitCallBack);
			
	if ( TaskHead == NULL ) 
	{
		SysMenu_Item[0].item_text = description->name;
		SysMenu_Item[0].item_status = 1;
		SysMenu_Taskptr[0] = (SYSTCB *)taskid;
		return (SYSTCB *)taskid;
	}
		
	for (i = 0; i < MAX_SYSMENU && SysMenu_Item[i].item_text != NULL ; i++);
	if ( i < MAX_SYSMENU && description->mode != ASIX_DEAMON) {
		SysMenu_Item[i].item_text = description->name;
		SysMenu_Item[i].item_status = 1;
		SysMenu_Taskptr[i] = (SYSTCB *)taskid;
	}
	  
	return (SYSTCB *)taskid;
}

// start applicaiton task
STATUS ASIXStartTask( DWORD id )
{
	TASKDESCRIPTION	*desp;
	SYSTCB	*task;
	WORD	i;
	MSG		msg;

	if( (id < 1) || (id > TASKNUM) )
		return ASIX_ERROR;

	desp = gSysTcbTbl[id-1].description->desp;
	task = &gSysTcbTbl[id-1];

	memset( &msg, 0, sizeof(MSG) );

	if( task->status == DORMANT )	// dormant
	{
		// add to system menu
		if( desp->newscreen == 1 )
		{
			if ( TaskHead == NULL ) 
			{
				SysMenu_Item[0].item_text = desp->name;
				SysMenu_Item[0].item_status = 1;
				SysMenu_Taskptr[0] = task;
			}
			else
			{
				for (i = 0; i < MAX_SYSMENU && SysMenu_Item[i].item_text != NULL ; i++)
					;
				if ( i < MAX_SYSMENU && desp->mode != ASIX_DEAMON)
				{
					SysMenu_Item[i].item_text = desp->name;
					SysMenu_Item[i].item_status = 1;
					SysMenu_Taskptr[i] = (SYSTCB *)task;
				}
			}
		}
		msg.message = SM_START;
	}
	else	// already run
	{
		if( desp->newscreen == 1 )
		{
			msg.message = SM_SWITCH;
			msg.wparam = SWAP_TO_FOREGROUND;
		}
		else
			return ASIX_OK;
	}
	
	msg.lparam = id;
	if(SysSendMessage(SYSTASK_ID, &msg) != SYS_OK)
		return ASIX_ERROR;
	return ASIX_OK;
}

STATUS StartService( TASKDESCRIPTIONLIST *desplst )
{
	if( desplst == NULL || desplst->desp == NULL )
		return ASIX_ERROR;

	if( desplst->taskid < SRVTSK_ID_BEGIN || desplst->taskid >= SHELL_ID )
		return ASIX_ERROR;

	if( desplst->desp->mode != ASIX_SERVICE )
		return ASIX_ERROR;

	// service already started
	if( gSysTcbTbl[desplst->taskid-1].status == RUNNING )
		return ASIX_OK;

	if( gSysTcbTbl[desplst->taskid-1].description == NULL )
	{
		ID	id = desplst->taskid;
		TASKDESCRIPTION	*desp = desplst->desp;
		
		// create task
		vcre_tsk( id,  desp->entry,  desp->pri, (U32)(desplst->stack + ((desp->stksize-3)/4)) );
		gSysTcbTbl[id-1].description = desplst;

		if( desp->newscreen == 1 )
		{
			gSysTcbTbl[id-1].gc = (GC *)SysInitGC(desp->scr_w, desp->scr_h);
			gSysTcbTbl[id-1].atvcb = (ATVCB *)SysInitATVCB();
		}
	}

	gSysTcbTbl[desplst->taskid-1].status = RUNNING;
	sta_tsk( desplst->taskid, 0 );
	
	return ASIX_OK;
}

// Dynamically Create Application Task
DWORD CreateDynamicTask( TASKDESCRIPTION *description, BYTE mode )
{
	ID		id;
	SYSTCB	*task;
//	WORD	i;
	TASKDESCRIPTIONLIST	*desplst;

	if( description == NULL || description->entry == NULL )
		return 0;

	if( mode == RUN_AS_EXISTED_TASK )
	{	
		desplst = IsRegistered( description );
		if( desplst != NULL )		// already registered
		{
			task = &gSysTcbTbl[desplst->taskid-1];
			ASIXStartTask( desplst->taskid );		
			return desplst->taskid;
		}
	}
	
	// register task
	desplst = TaskRegist( description );
	if( desplst == NULL )
		return 0;
	
//	stksize = sizeof(DWORD) * (description->stksize+3)/4;
//	stack = (DWORD *)SysLmalloc( stksize ); 
//	if( stack == NULL)
//		return 0;

	// create task
	id = desplst->taskid;
	task = &gSysTcbTbl[id-1];
	task->description = desplst;
//	task->stack = stack;
	task->id = (DWORD)task;
	task->wnd_ptr = NULL;
	task->devices = 0;
	task->status = DORMANT;
//	task->group = description->group;
//	task->icon = (char *)description->icon;

	// start task
	ASIXStartTask( id );

	return id;
}

// Get the Status of Application Task
DWORD GetAppTaskStatus( TASKDESCRIPTION *description )
{
//	WORD	i;


	return 0;
}

/* EntryCallBack() task call this func, */	
/*
STATUS ASIXKillTask(SYSTCB *taskptr)
{	
register SYSTCB 		*listptr;
register U8				i;
	
	if (taskptr == NULL || taskptr->id == 0 || taskptr->status != ASIX_TASK_KILLING)
		return ASIX_ERROR;
		
	if ( CurTask == taskptr || taskptr->wnd_ptr != NULL )	
		return ASIX_ERROR;
	
	for (listptr = TaskHead; listptr->next != taskptr && listptr->next->next != NULL; listptr = listptr->next );
	
	if (listptr->next != taskptr ) return ASIX_ERROR;
	
	// Delete all the messages of this task. LM 01/05/17 
	AdvMessageDelete(taskptr->id, 0xffff, 0xffffffff); 
	
	TaskTerminate(taskptr->id);
	
	for (i = 0; i < MAX_SYSMENU && SysMenu_Taskptr[i] != taskptr; i++);
	if ( SysMenu_Taskptr[i] == taskptr ) {
		MoveBlock(&SysMenu_Taskptr[i+1], &SysMenu_Taskptr[i], (MAX_SYSMENU-i)*sizeof(SYSTCB *));	
		MoveBlock(&SysMenu_Item[i+1], &SysMenu_Item[i], (MAX_SYSMENU-i)*sizeof(struct MENU_ITEM)); 	
	}
	
	return ASIX_OK;
}		
*/

⌨️ 快捷键说明

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