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

📄 mainfrm.cpp

📁 wince中断 wince中断
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "IntTest.h"
#include <Pm.h>

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// Array tbSTDButton contains relevant buttons of bitmap IDB_STD_SMALL_COLOR
static TBBUTTON tbButtons[] = {
	{0, 0,				TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0,  0},  
	{0,	ID_FILE_NEW,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{1, ID_FILE_OPEN,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{2, ID_FILE_SAVE,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{0, 0,				TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
	{3, ID_EDIT_CUT,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{4, ID_EDIT_COPY,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{5, ID_EDIT_PASTE,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{0, 0,				TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0, -1},
	{6, ID_APP_ABOUT,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
	{0, 0,				TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0, 0,  0}
};
const int nNumButtons = sizeof(tbButtons)/sizeof(TBBUTTON);
const int nNumImages = 7;
const DWORD dwAdornmentFlags = 0; // exit button

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_WAIT, OnWait)
	ON_COMMAND(ID_CLOSE, OnClose)
	ON_COMMAND(ID_OPEN, OnOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	hMouse=NULL;
	// Add the buttons and adornments to the CommandBar.
	if (!InsertButtons(tbButtons, nNumButtons, IDR_MAINFRAME, nNumImages) ||
	    !AddAdornments(dwAdornmentFlags))
	{
		TRACE0("Failed to add toolbar buttons\n");
		return -1;
	}
	BOOL	RetValue = TRUE;
		
	/* IO Register Allocation */

	v_pIOPregs = (volatile IOPreg *)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
	if (v_pIOPregs == NULL) 
	{
		ERRORMSG(1,(TEXT("For IOPregs : VirtualAlloc failed!\r\n")));
		RetValue = FALSE;
	}
	else 
	{
		if (!VirtualCopy((PVOID)v_pIOPregs, (PVOID)(IOP_BASE), sizeof(IOPreg), PAGE_READWRITE | PAGE_NOCACHE)) 
		{
			ERRORMSG(1,(TEXT("For IOPregs: VirtualCopy failed!\r\n")));
			RetValue = FALSE;
		}
	}
	
	if (!RetValue) 
	{
//		RETAILMSG (1, (TEXT(":::InitializeAddresses - Fail!!\r\n") ));

		if (v_pIOPregs) 
		{
			VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE);
		}

		v_pIOPregs = NULL;
	}
	  
	else RETAILMSG (1, (TEXT(":::InitializeAddresses - Success\r\n") ));
	s2410LCD = (volatile LCDreg *)VirtualAlloc(0, sizeof(LCDreg), MEM_RESERVE, PAGE_NOACCESS);
	if (v_pIOPregs == NULL) 
	{
		ERRORMSG(1,(TEXT("For IOPregs : VirtualAlloc failed!\r\n")));
		RetValue = FALSE;
	}
	else 
	{
		if (!VirtualCopy((PVOID)s2410LCD, (PVOID)(LCD_BASE), sizeof(s2410LCD), PAGE_READWRITE | PAGE_NOCACHE)) 
		{
			ERRORMSG(1,(TEXT("For s2410LCD: VirtualCopy failed!\r\n")));
			RetValue = FALSE;
		}
	}
	
	if (!RetValue) 
	{
//		RETAILMSG (1, (TEXT(":::InitializeAddresses - Fail!!\r\n") ));

		if (s2410LCD) 
		{
			VirtualFree((PVOID) s2410LCD, 0, MEM_RELEASE);
		}

		s2410LCD = NULL;
	}
	else RETAILMSG (1, (TEXT(":::InitializeAddresses - Success\r\n") ));
	v_pIOPregs->rGPFCON  &= ~(0x3 << 4);		/* Set EINT2(GPF2) as EINT2							*/
	v_pIOPregs->rGPFCON  |=  (0x2 << 4);

    v_pIOPregs->rEXTINT0 &= ~(0x7 << 8);		/* Configure EINT2 as Falling Edge Mode				*/
    v_pIOPregs->rEXTINT0 |=  (0x2 << 8);

	v_pIOPregs->rGPECON  &= ~(0x3 << 22);		// Set GPE11 as OutPut	0						
	v_pIOPregs->rGPECON  |=  (0x01 << 22);
	v_pIOPregs->rGPEUP   &=~(0x1<<11);
	v_pIOPregs->rGPEDAT	 &=~(0x1<<11);
	
	v_pIOPregs->rGPFCON  &= ~(0x3 << 12);								
	v_pIOPregs->rGPFCON  |=  (0x1 << 12);
	//v_pIOPregs->rGPFUP
IntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
		if (!(InterruptInitialize(SYSINTR_EINT2, IntrEvent, 0, 0))) 
	{
		RETAILMSG(1, (TEXT("::: SYSINTR_EINT2 Init Fail\r\n")));
	}

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs


	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

void CMainFrame::OnWait() 
{

	/* if(!hMouse)
	{
		 RETAILMSG(1,(TEXT("hMouse is NULL")));
		hMouse = CreateEvent(NULL, FALSE, FALSE, TEXT("MouseEvent"));//by zq
	}*/
	// TODO: Add your command handler code here
//	while (1) 
	{
		if(WaitForSingleObject(IntrEvent, INFINITE)== WAIT_OBJECT_0)
			{
						AfxMessageBox(TEXT("中断被触发!!"));
						InterruptDone(SYSINTR_EINT2);
						Sleep(10);
			}
		
		/*
		else 
		{
			SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
		}*/
		Sleep(10);
	}
}

void CMainFrame::OnClose() 
{
	// TODO: Add your command handler code here
	//s2410LCD->rLCDCON5&=~(0x1<<3);
	DWORD i;
	v_pIOPregs->rGPFDAT |= (0x1 << 6);
	//i=SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
}

void CMainFrame::OnOpen() 
{
	// TODO: Add your command handler code here
//	s2410LCD->rLCDCON5|=(0x1<<3);
	
v_pIOPregs->rGPFDAT &= ~(0x1 << 6);
    
}

⌨️ 快捷键说明

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