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

📄 sysmain.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
字号:
//------------------------------------------------------------------------------
// File:        Sysmain.c
// Date:        2001-6-13 am 09:02:31
// Written by:  CYu
// Decription:  
// Modification record
//------------------------------------------------------------------------------
// Copyright:   EPSON Proprietary Material
//              Copyright (c) 2001, All Rights Reserved
//              SHANGHAI EPSON ELECTRONICS CO., LTD.
//
//              DISTRIBUTION PROHIBITED without written authorization from EPSON
//------------------------------------------------------------------------------

/* system and standard header */
#define _SIZE_T_DEFINED
#include <windows.h>
#include <string.h>
#include <time.h>

#include <kernel\ros33\ros33.h>
#include <sys\systsk.h>
#include <sys\systmr.h>

/* simulator header */
#include <simsys\include\sysmacro.h>
#include <simdrv\export\driver.h>
#include <simsrv\export\simsrv.h>

/* debug */
#include <sys\sysdebug.h>

#define WM_REFRESH			(WM_USER +1)
#define WM_POWEROFF			(WM_USER +2)

#define TIMERID_SIMCLKINT	(TSK_NUM + 1)
#define TIMERID_SIMPENINT	(TIMERID_SIMCLKINT + TOUCHTIMER)
#define TIMERID_SIMKEYINT	(TIMERID_SIMCLKINT + KEYSCANTIMER)
//#define TIMERID_SIMCLKINT	1
//#define TIMERID_SIMPENINT	TOUCHTIMER
//#define TIMERID_SIMKEYINT	KEYSCANTIMER
typedef struct 
{
	unsigned long low;
	unsigned long high;
}ulong64;

extern UW		passedticks;		// defined in systask.c		
extern UW		currentclock;		// defined in systask.c

FILE	*DebugLogFile;
//HANDLE	hEventInt;
HANDLE	hEnEventInt;
CRITICAL_SECTION CriticalSection;

static SYSTEMTIME	CurSysTime;		// current system time

static HWND CreateClientWindow( HINSTANCE hinst );
static LRESULT CALLBACK ClientWndProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam );

extern void InitSys( void );		// defined in initsys.c
extern void taskmain( void );		// defined in taskmain.c

void TK_Scan_Start(void);
void TK_Scan_Stop(void);

extern void LosePower( void );

//------------------------------------------------------------------------------
// Function name  : WinMain
// Description    : 
// Return type    : intWINAPI 
// Argument       : HINSTANCE hInst
// Argument       : HINSTANCE hPrevInst
// Argument       : LPSTR lpszCmdLine
// Argument       : int nCmdShow
// Remarks        : 
// So also        : 
//------------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hInst, 
					HINSTANCE hPrevInst, 
					LPSTR lpszCmdLine, 
					int nCmdShow )
{
    MSG msg;
    //unsigned long (*pAppMain)( unsigned long );
    STARTUPINFO si;
    PROCESS_INFORMATION pi;


    //pAppMain = (VOID*)GetProcAddress( hInst, "AppMain" );
	
//	if( serverStatus == SS_SRVSTARTED )
//	{
//		MessageBox( NULL, "Another simulator is running!", "Information", MB_OK | MB_ICONINFORMATION );
//	}
	if( hwndPanel == 0 )
	{
		memset( &si, 0, sizeof( STARTUPINFO ) );
		if( !CreateProcess(
				"simsrv.exe",          // name of executable module
				NULL,                   // command line string
				NULL,                   // SD
				NULL,                   // SD
				FALSE,                  // handle inheritance option
				NORMAL_PRIORITY_CLASS,  // creation flags
				NULL,                   // new environment block
				NULL,                   // current directory name
				&si,                    // startup information
				&pi                     // process information
				) )
		{
			MessageBox( NULL, "Unable to open simulation server!", "Error", MB_OK | MB_ICONERROR );
			return FALSE;
		}
	}

    hwndClient = CreateClientWindow( hInst );
	
	while( serverStatus != SS_SRVSTARTED )
		Sleep( 10 );
	
	DebugLogFile = fopen( "dbglog.txt", "w" );

	InitializeCriticalSection(&CriticalSection);
	CreateEvent( NULL, TRUE, FALSE, "IntEvent" );
	taskmain( );

    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
		TranslateMessage( &msg );
        DispatchMessage( &msg );
    }

    //hwndClient = 0;
	//if( hwndPanel )
	//	PostMessage( hwndPanel, WM_CLOSE, 0, 0 );

    return 0;
}

//------------------------------------------------------------------------------
// Function name  : CreateClientWindow
// Description    : 
// Return type    : HWND
// Argument       : HINSTANCE hinst
// Remarks        : 
// So also        : 
//------------------------------------------------------------------------------
HWND CreateClientWindow( HINSTANCE hinst )
{
    HWND hwnd;

	WNDCLASS wc;

    wc.lpszClassName = "Client";
	wc.hInstance     = hinst;
	wc.lpfnWndProc   = ClientWndProc;
	wc.hCursor       = NULL;
	wc.hIcon         = NULL;
	wc.lpszMenuName  = NULL;
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;

	if( !RegisterClass( &wc ) )
	    return FALSE;

    hwnd = CreateWindowEx(
        0,//WS_EX_CLIENTEDGE,
		"Client",
		"",
		WS_OVERLAPPED,
		CW_USEDEFAULT,
        CW_USEDEFAULT,
		CW_USEDEFAULT,
        CW_USEDEFAULT,
		NULL,
		NULL,//LoadMenu( hinstThis, MAKEINTRESOURCE( IDR_MainMenu ) ),
		hinst,
		NULL );

    return hwnd;
}

//------------------------------------------------------------------------------
// Function name  : ClientWndProc
// Description    : 
// Return type    : LRESULTCALLBACK 
// Argument       : HWND hwnd
// Argument       : UINT uMsg
// Argument       : WPARAM wParam
// Argument       : LPARAM lParam
// Remarks        : 
// So also        : 
//------------------------------------------------------------------------------
LRESULT CALLBACK ClientWndProc( HWND hwnd,
								UINT uMsg,
								WPARAM wParam,
								LPARAM lParam )
{
    //HDC		hdc;
    //PAINTSTRUCT	ps;
	//char str[30];

    switch( uMsg )
    {
	    //case WM_CREATE:
 	    //    break;
	    //case WM_PAINT:
	    //    hdc = BeginPaint( hwnd, (LPPAINTSTRUCT)&ps );
	    //    EndPaint( hwnd, (LPPAINTSTRUCT)&ps );
	    //    break;
		case WM_POWEROFF:
        case WM_CLOSE:
            LosePower();
			DestroyWindow( hwnd );
			hwndClient = 0;
			PostMessage( hwndScreen, WM_PAINT, 0, 0 );
			{
				int i;
#if ENABLE_SYSMSG_STATISTIC
				for( i = 0; i < MLBX_NUM; i++ )
					fprintf( DebugLogFile, "MailBox:%d max length:%ld\n", i, gSysMsgSta[i].max );
#endif
#if ENABLE_SYSFLG_STATISTIC
				for( i = 0; i < FLG_NUM; i++ )
					fprintf( DebugLogFile, "Event:%d times:%ld\n", i, gSysFlgSta[i] );
#endif
#if ENABLE_SYSCALL_STATISTIC
				for( i = 0; i < SYSCAL_NUM; i++ )
					fprintf( DebugLogFile, "SysCall:%s %ld\n", gSyscallSta[i].name, gSyscallSta[i].sta );
#endif
			}
			fclose( DebugLogFile );
            break;
	    case WM_DESTROY:
	        PostQuitMessage( 0 );
	        break;
        case WM_TIMER:
			switch( wParam )
			{
				case TIMERID_SIMCLKINT:
					passedticks++;
					currentclock++;
					//dbgoutput( "%d", passedticks );
					iset_flg( TIMER_EVENT, TIMER_FLG);
					break;
				case TIMERID_SIMPENINT:
					if( WritePenIntBuf( &pen ) == SUCCESS )
						iset_flg( SYS_EVENT, INTPEN_FLG );
					break;
				case TIMERID_SIMKEYINT:
					if( WriteKeyIntBuf( &key ) == SUCCESS )
						iset_flg( SYS_EVENT, INTKEY_FLG );
					break;
			}
            break;
		case WM_REFRESH:
			RefreshLCD( );
			break;
        //case SM_ADDTIMER:
            // wParam is task/timer id, lParam is elapse
        //    SetTimer( hwnd, wParam, lParam, 0 );
        //    break;
	    default:
	        return DefWindowProc( hwnd, uMsg, wParam, lParam );
    }
    return 0;
}

void TK_Scan_Start(void)
{
	act_cyc( TOUCHTIMER, TCY_ON );
	return;
}

void TK_Scan_Stop(void)
{
	act_cyc( TOUCHTIMER, TCY_OFF );
	return;
}

ulong64 ReadTotalMilliSecond( void )
{
	ulong64	time;

	time.high = 0;
	time.low = GetTickCount( );

	return time;
}

unsigned short Read_MilliSecond( void )
{
	GetLocalTime( &CurSysTime );
	return CurSysTime.wMilliseconds;
}


void ReadGlobalTime( ASIX_TIME *time )
{
	GetLocalTime( &CurSysTime );

	time->hour = CurSysTime.wHour;
	time->minute = CurSysTime.wMinute;
	time->second = CurSysTime.wSecond;

	return;
}

void ReadGlobalDate( ASIX_DATE *date )
{
	GetLocalTime( &CurSysTime );

	date->year = CurSysTime.wYear;
	date->month = CurSysTime.wMonth;
	date->day = CurSysTime.wDay;

	return;
}

void SetGlobalTime( ASIX_TIME *time )
{
	CurSysTime.wHour = time->hour;
	CurSysTime.wMinute = time->minute;
	CurSysTime.wSecond = time->second;

	SetLocalTime( &CurSysTime );

	return;
}

void SetGlobalDate( ASIX_DATE *date )
{
	CurSysTime.wYear = date->year;
	CurSysTime.wMonth = date->month;
	CurSysTime.wDay = date->day;

	SetLocalTime( &CurSysTime );

	return;
}

void Idle( void )
{
	Sleep( 10000 );
	return;
}

⌨️ 快捷键说明

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