bak_io.cpp
上传用户:qiulin1960
上传日期:2013-10-16
资源大小:2844k
文件大小:6k
源码类别:

Windows CE

开发平台:

Windows_Unix

  1. //
  2. // Copyright (c) Microsoft Corporation.  All rights reserved.
  3. //
  4. //
  5. // Use of this source code is subject to the terms of the Microsoft end-user
  6. // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
  7. // If you did not accept the terms of the EULA, you are not authorized to use
  8. // this source code. For a copy of the EULA, please see the LICENSE.RTF on your
  9. // install media.
  10. //
  11. /*
  12. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  13. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  14. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  15. PARTICULAR PURPOSE.
  16. */
  17. #include <windows.h>
  18. #include <pm.h>
  19. #include "pmplatform.h"
  20. #include "bak_hw.h"
  21. //  Global structure
  22. extern BLStruct g_BLInfo;
  23. extern HANDLE   g_evtSignal[NUM_EVENTS];
  24. DWORD 
  25. BAK_Init(DWORD dwContext)
  26. {
  27. HANDLE  hThread;
  28. DWORD   dwThreadID;
  29. RETAILMSG(1, (TEXT("BAK_Init: dwContext = 0x%xrn"), dwContext));
  30. // Perform all one-time initialization of the backlight
  31. if (!BacklightInitialize())
  32. {
  33. RETAILMSG(1, (TEXT("BAK_Init:couldn't initialize backlight hardware rn")));
  34. return 0;
  35. }
  36. // Create the backlight service thread
  37. hThread = CreateThread(NULL, 0, BL_MonitorThread, NULL, 0, &dwThreadID);
  38. if (hThread == NULL) 
  39. {
  40. RETAILMSG(1, (TEXT("BAK_Init: failed to create BL_MonitorThreadrn")));
  41. return 0;
  42. }
  43. return dwThreadID;
  44. }
  45. BOOL 
  46. BAK_Deinit(DWORD dwContext)
  47. {
  48. BL_Deinit();
  49.     return TRUE;
  50. }
  51. DWORD 
  52. BAK_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
  53. {
  54. return dwData;
  55. }
  56. BOOL 
  57. BAK_Close(DWORD Handle)
  58. {
  59.     return TRUE;
  60. }
  61. void 
  62. BAK_PowerDown(void)
  63. {
  64.     BL_On(FALSE);
  65. }
  66. void
  67. BAK_PowerUp(void)
  68. {
  69. BL_PowerOn(TRUE);
  70. }
  71. DWORD 
  72. BAK_Read(DWORD Handle, LPVOID pBuffer, DWORD dwNumBytes)
  73. {
  74. return 0;
  75. }
  76. DWORD 
  77. BAK_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
  78. {
  79. return 0;
  80. }
  81. DWORD 
  82. BAK_Seek(DWORD Handle, long lDistance, DWORD dwMoveMethod)
  83. {
  84. return (DWORD) -1;
  85. }
  86. BOOL 
  87. BAK_IOControl(
  88.   DWORD Handle, 
  89.   DWORD dwCode, 
  90.   PBYTE pBufIn, 
  91.   DWORD dwLenIn,
  92.   PBYTE pBufOut, 
  93.   DWORD dwLenOut, 
  94.   PDWORD pdwActualOut
  95.   )
  96. {
  97.     BOOL RetVal = TRUE;
  98.     DWORD dwErr = ERROR_SUCCESS;    
  99.     switch (dwCode) 
  100. {
  101. RETAILMSG(1, (TEXT("BAK_IOControl: Handle = 0x%x, dwCode = 0x%xrn"), Handle, dwCode));
  102. RETAILMSG(1, (TEXT("               pBufIn = 0x%x, dwLenIn = 0x%xrn"), pBufIn, dwLenIn));
  103. RETAILMSG(1, (TEXT("               pOutBuf = 0x%x, dwLenOut = 0x%xrn"), pBufOut, dwLenOut));
  104. RETAILMSG(1, (TEXT("               pdwActualOut = 0x%xrn"), pdwActualOut));
  105.         //
  106.         // Power Management
  107.         //
  108. case IOCTL_POWER_CAPABILITIES: 
  109.         {
  110.             PPOWER_CAPABILITIES ppc;
  111. RETAILMSG(1, (TEXT("BAK: IOCTL_POWER_CAPABILITIESrn")));   
  112.             
  113. if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(POWER_CAPABILITIES)) ) {
  114.                 RetVal = FALSE;
  115.                 dwErr = ERROR_INVALID_PARAMETER;
  116.                 break;
  117.             }
  118.             ppc = (PPOWER_CAPABILITIES)pBufOut;
  119.             
  120.             memset(ppc, 0, sizeof(POWER_CAPABILITIES));
  121.             // support D0, D4 
  122.             ppc->DeviceDx = 0x11;
  123.             // Report our power consumption in uAmps rather than mWatts. 
  124.             ppc->Flags = POWER_CAP_PREFIX_MICRO | POWER_CAP_UNIT_AMPS;
  125.             
  126. // 25 m = 25000 uA
  127.             // TODO: find out a more accurate value
  128. ppc->Power[D0] = 25000;
  129.             
  130.             *pdwActualOut = sizeof(POWER_CAPABILITIES);
  131.         } break;
  132. case IOCTL_POWER_SET: 
  133.         {
  134.             CEDEVICE_POWER_STATE NewDx;
  135.             if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(CEDEVICE_POWER_STATE)) ) {
  136.                 RetVal = FALSE;
  137.                 dwErr = ERROR_INVALID_PARAMETER;
  138.                 break;
  139.             }
  140.             
  141.             NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
  142.             if ( VALID_DX(NewDx) ) {
  143.                 switch ( NewDx ) {
  144.                 case D0:
  145.                     //  Power changed, we need to notify the monitor thread to resync
  146.                     //  the timer
  147.                     SetEvent(g_evtSignal[BL_POWEREVT]);
  148.                     BL_On(TRUE);
  149.                     break;
  150.                 default:
  151.                     BL_On(FALSE);
  152.                     break;
  153.                 }
  154.                 RETAILMSG(1, (TEXT("BAK: IOCTL_POWER_SET: D%u rn"), NewDx));
  155.                 *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
  156.             } else {
  157.                 RetVal = FALSE;
  158.                 dwErr = ERROR_INVALID_PARAMETER;
  159.             }
  160.             
  161.         } break;
  162.         case IOCTL_POWER_GET: 
  163.             if ( !pdwActualOut || !pBufOut || (dwLenOut < sizeof(CEDEVICE_POWER_STATE)) ) {
  164.                 RetVal = FALSE;
  165.                 dwErr = ERROR_INVALID_PARAMETER;
  166.                 break;
  167.             }
  168. CEDEVICE_POWER_STATE Dx;
  169. if (g_BLInfo.m_dwStatus == BL_ON){
  170. Dx = D4;
  171. }
  172. else {
  173. Dx = D0;
  174. }
  175. *(PCEDEVICE_POWER_STATE)pBufOut = Dx;
  176.             RETAILMSG(1, (TEXT("USB_SER: IOCTL_POWER_GET: D%u rn"), Dx));
  177.             *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
  178.         break;
  179. default:
  180.             RetVal = FALSE;
  181.             RETAILMSG(1, (TEXT(" Unsupported ioctl 0x%Xrn"), dwCode));
  182.             break;
  183. }
  184. return(RetVal);
  185. }
  186. BOOL
  187. WINAPI
  188. DllMain(
  189.     HANDLE  hinstDll,
  190.     DWORD   dwReason,
  191.     LPVOID  lpReserved
  192.     )
  193. {
  194. switch(dwReason)
  195. {
  196. case DLL_PROCESS_ATTACH:
  197. // RETAILMSG(1, (TEXT("BAK_DllMain: DLL_PROCESS_ATTACHrn")));
  198. break;
  199. case DLL_PROCESS_DETACH:
  200. // RETAILMSG(1, (TEXT("BAK_DllMain: DLL_PROCESS_DETACHrn")));
  201. break;
  202.     }
  203.     return TRUE;
  204. }