Windows CE关机APP代码实现

 

#define IOP_BASE      0xB1600000 // 0x56000000
typedef struct  {
    unsigned int  rGPACON;  // 00
    unsigned int  rGPADAT;
    unsigned int  rPAD1[2];
   
    unsigned int  rGPBCON;  // 10
    unsigned int  rGPBDAT;
    unsigned int  rGPBUP;
    unsigned int  rPAD2;
   
    unsigned int  rGPCCON;  // 20
    unsigned int  rGPCDAT;
    unsigned int  rGPCUP;
    unsigned int  rPAD3;
   
    unsigned int  rGPDCON;  // 30
    unsigned int  rGPDDAT;
    unsigned int  rGPDUP;
    unsigned int  rPAD4;
   
    unsigned int  rGPECON;  // 40
    unsigned int  rGPEDAT;
    unsigned int  rGPEUP;
    unsigned int  rPAD5;
   
    unsigned int  rGPFCON;  // 50
    unsigned int  rGPFDAT;
    unsigned int  rGPFUP;
    unsigned int  rPAD6;
   
    unsigned int  rGPGCON;  // 60
    unsigned int  rGPGDAT;
    unsigned int  rGPGUP;
    unsigned int  rPAD7;
   
    unsigned int  rGPHCON;  // 70
    unsigned int  rGPHDAT;
    unsigned int  rGPHUP;
    unsigned int  rPAD8;
}IOPreg; 
volatile IOPreg *G_pIOPRegs=NULL;


extern "C" _declspec(dllimport) BOOL VirtualCopy(LPVOID lpvDest, LPVOID lpvSrc,
             DWORD cbSize,DWORD fdwProtect);
void CStartDlg::OnButton1()
{

   G_pIOPRegs = (volatile IOPreg*)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
  if (G_pIOPRegs == NULL)
  {
   DEBUGMSG (1,(TEXT("G_pIOPRegs is not allocated/n/r")));
   // return false;
  }
  if (!VirtualCopy((PVOID)G_pIOPRegs, (PVOID)IOP_BASE, sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE))
  {
   DEBUGMSG (1,(TEXT("G_pIOPRegs is not mapped/n/r")));
   //  return false;
  }
  
  G_pIOPRegs->rGPCCON &= ~(0x3<<14)|(0x3<<12);
  G_pIOPRegs->rGPCCON |= (0x1<<14)|(0x1<<12);
  G_pIOPRegs->rGPCUP  |= (0x1<<7)|(0x1<<6);
  G_pIOPRegs->rGPCDAT |= (0x1<<7)|(0x1<<6);
  
                       G_pIOPRegs->rGPBCON&=~(0x3);
     G_pIOPRegs->rGPBCON|=0x1;
     G_pIOPRegs->rGPBDAT&=~(0x1);
     G_pIOPRegs->rGPBUP|=0x1;
    
                       G_pIOPRegs->rGPBCON &= ~(0x3<<8);                 
                       G_pIOPRegs->rGPBCON |=  (0x1<<8);     
                       G_pIOPRegs->rGPBUP  |=  (0x1<<4);                 
                       G_pIOPRegs->rGPBDAT&=  ~(0x1<<4); 

 
     G_pIOPRegs->rGPGDAT &= ~(1<<3);
     G_pIOPRegs->rGPGUP |= (0x1<<3);
     G_pIOPRegs->rGPGCON &= ~(0x3<<6);
     G_pIOPRegs->rGPGCON |= (0x1<<6);  
    
                      G_pIOPRegs->rGPADAT &= ~(1<<13); 
                      G_pIOPRegs->rGPACON &= ~(1<<13);
}

原文转自喻总的blog: http://blog.csdn.net/yudong54/article/details/5292087
 

你可能感兴趣的:(Windows CE关机APP代码实现)