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

📄 system.c

📁 microwindows上的修改的GUI
💻 C
字号:
/*
 *  RTEMS System Layer for emGUI
 *
 *
 *  COPYRIGHT (c) 2001 - 2010.
 *  emTech System Corporation.
 *
 *  The license and distribution terms for this file may be
 *  found in found in the file LICENSE.
 */

/*	Huangf emcore@263.net
 */
 
#include "emGUI.h"

static rtems_id	evSysQ;

void SysHandleEvent();

static void emGUI_sysTaskEntry()
{
	SysHandleEvent();
}

void emGUI_sysInitialoization()
{
	rtems_id	taskID;
	
	rtems_message_queue_create(
		rtems_build_name('G', 'U', 'I', 'Q'),
		EMGUI_SYSQ_SIZE,
		4 * sizeof(unsigned32),
		RTEMS_FIFO,
		&evSysQ
	);

	rtems_task_create(
		rtems_build_name('G', 'U', 'I', 'T'),
		EMGUI_SYSTHREAD_PRIORITY,
		EMGUI_SYSTHREAD_STACKSIZE,
		RTEMS_NO_ASR,
		RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
		&taskID
	);

	rtems_task_start(
		taskID,
		(rtems_task_entry)emGUI_sysTaskEntry,
		0
	);
}
	
boolean SysGetEvent(
	unsigned32 timo
)
{
	unsigned32 	size;
	int 		status;
	
	size = sizeof(_evSys_Snapshot);
	
	status = rtems_message_queue_receive(
		evSysQ,
		&_evSys_Snapshot,
		&size,
		RTEMS_WAIT,
		timo
	);

	return !status;
}

void SysSendEvent(
	unsigned32 type,
	unsigned32 data1,
	unsigned32 data2,
	unsigned32 data3
)
{
	_SysEvent event = {
		type,
		data1,
		data2,
		data3
	};

	rtems_message_queue_send(
		evSysQ,
		&event,
		sizeof(event)
	);
}

/*  create messageQ for a Application
 */
unsigned32 CreateMsgQ()
{
	rtems_id 	q;
	unsigned32	status;
	
	status = rtems_message_queue_create(
		rtems_build_name('G', 'U', 'I', 'q'),
		APPLICATION_MESSAGEQ_SIZE,
		4 * sizeof(unsigned32),
		RTEMS_FIFO,
		&q
	);

	if (status){
		return 0;
	}
	else{
		return (unsigned32)q;
	}
}

/*  create a Application's task and make it running
 *  this is not a very good version
 */
unsigned32 CreateAppTask(
	Application	*app,
	void		*appMain
)
{
	rtems_id	taskID;
	unsigned32 	status;
	
	status = rtems_task_create(
		rtems_build_name('G', 'U', 'I', 't'),
		EMGUI_APPLICATION_PRIORITY,
		EMGUI_APPLICATION_STACKSIZE,
		0,
		RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
		&taskID
	);
	
	if (status){
		/*  failed */
		return 0;
	}
	
	rtems_task_start(
		taskID,
		(rtems_task_entry)appMain,
		(unsigned32)app
	);

	return taskID;
}

void SysDeleteTask(
	unsigned32 taskID
)
{
	rtems_task_delete(
		taskID
	);
}

void SysDeleteMsgQ(
	unsigned32 msgqID
)
{
	rtems_message_queue_delete(
		msgqID
	);
}

boolean SysGetAppMessage(
	struct Application *__p
)
{
	if (__p == NULL){
		return FALSE;
	}
	
	{
	
		unsigned32 	size;
		unsigned32	status;
		
		size = sizeof(__p->msgBuf);
	
		status = rtems_message_queue_receive(
			__p->msgQ,
			&__p->msgBuf[0],
			&size,
			RTEMS_WAIT,
			0
		);

		return !status;
	}
}

static void __PostMessage(
	AppID		appID,
	WndID		wndID,
	unsigned16	msg,
	unsigned16	nParam,
	unsigned32	lParam
)
{
	unsigned32 msgdata[4];
	
	if (appID == NULL){
		SysSendEvent(
			msg,
			nParam,
			lParam >> 16,
			lParam & 0x0000FFFF
		);
		return;
	}

	/*  system message */
	msgdata[0] = EVS_SYSTEM;
	msgdata[1] = (unsigned32)wndID;
	msgdata[2] = (msg << 16) | (nParam);
	msgdata[3] = lParam;
	
	rtems_message_queue_send(
		appID->msgQ,
		&msgdata[0],
		sizeof(msgdata)
	);
}

void PostAppMessage(
	AppID		appID,
	unsigned16	msg,
	unsigned16	nParam,
	unsigned32	lParam
)
{
	__PostMessage(
		appID,
		NULL,
		msg,
		nParam,
		lParam
	);
}

void PostMessage(
	WndID		wndID,
	unsigned16	msg,
	unsigned16	nParam,
	unsigned32	lParam
)
{
	if (wndID == NULL || wndID->application == NULL){
		return;
	}
	
	__PostMessage(
		wndID->application,
		wndID,
		msg,
		nParam,
		lParam
	);
}

void PostSysMessage(
	unsigned16	msg,
	unsigned16	nParam,
	unsigned32	lParam
)
{
	__PostMessage(
		NULL,
		NULL,
		msg,
		nParam,
		lParam
	);
}

boolean SysSendAppMessage()
{
	struct Application *__p;
	
	/*  Application list should be task safe */
	__p = FirstApplication();
	
	if (__p == NULL){
		return FALSE;
	}
	
	rtems_message_queue_send(
		__p->msgQ,
		&_evSys_Snapshot,
		sizeof(_evSys_Snapshot)
	);

	return TRUE;
}

void SysApplicationTermination()
{
	rtems_task_delete(
		RTEMS_SELF
	);
}

void emGUIInitialization()
{
	/*  other initialization */
	AppInitialization();
	WndInitialization();
	
	emGUI_sysInitialoization();
}

/*  glue code for send_mouse_msg used by MicroWindows version
 *  change later
 */
asm(".global send_mouse_msg");
asm("send_mouse_msg:");
asm("jmp SysSendEvent");

⌨️ 快捷键说明

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