📄 pwmmdd.c
字号:
//
// This function restores power to a device.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PWM_PowerUp(void)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_PowerUp\r\n")));
PwmReset();
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_PowerUp\r\n")));
}
//------------------------------------------------------------------------------
//
// Function: PWM_Read
//
// This function reads contents of 6 PWM registers.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// pBuffer
// [out] Pointer to the buffer that stores the data read from the
// device. This buffer should be at least Count bytes long.
//
// Count
// [in] Number of bytes to read from the device into pBuffer.
//
// Returns:
// Returns zero to indicate end-of-file. Returns -1 to indicate an
// error. Returns the number of bytes read to indicate success.
//
//------------------------------------------------------------------------------
DWORD PWM_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Read\r\n")));
if(!PwmReadRegister((UINT32 *)pBuffer, Count))
return (-1);
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Read\r\n")));
return Count;
}
//------------------------------------------------------------------------------
//
// Function: PWM_Write
//
// This function writes data to the device.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// pBuffer
// [out] Pointer to the buffer that contains the data to write.
//
// dwNumBytes
// [in] Number of bytes to write from the pBuffer buffer into the
// device.
//
// Returns:
// The number of bytes written indicates success. A value of -1 indicates
// failure.
//
//------------------------------------------------------------------------------
DWORD PWM_Write(DWORD Handle, LPCVOID pBuffer, DWORD dwNumBytes)
{
DWORD ret = dwNumBytes;
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Write\r\n")));
// dwNumBytes is the number of pwm samples in the buffer
if(!PwmPlaySample((LPCVOID)pBuffer, dwNumBytes))
{
dwNumBytes = 0;
return (-1);
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Write\r\n")));
return ret;
}
//------------------------------------------------------------------------------
//
// Function: PWM_IOControl
//
// This function sends a command to a device.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// dwCode
// [in] I/O control operation to perform. These codes are
// device-specific and are usually exposed to developers through
// a header file.
//
// pBufIn
// [in] Pointer to the buffer containing data to transfer to the
// device.
//
// dwLenIn
// [in] Number of bytes of data in the buffer specified for pBufIn.
//
// pBufOut
// [out] Pointer to the buffer used to transfer the output data
// from the device.
//
// dwLenOut
// [in] Maximum number of bytes in the buffer specified by pBufOut.
//
// pdwActualOut
// [out] Pointer to the DWORD buffer that this function uses to
// return the actual number of bytes received from the device.
//
// Returns:
// The new data pointer for the device indicates success. A value of -1
// indicates failure.
//
//------------------------------------------------------------------------------
BOOL PWM_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut,
PDWORD pdwActualOut)
{
BOOL bRet = FALSE;
switch(dwCode)
{
case PWM_IOCTL_RESET:
PwmReset();
bRet = TRUE;
DEBUGMSG(ZONE_IOCTL, (TEXT("PWM_IOControl: PWM_IOCTL_RESET occurred\r\n")));
break;
case IOCTL_POWER_CAPABILITIES:
if (!pBufOut || dwLenOut < sizeof(POWER_CAPABILITIES) || !pdwActualOut)
{
SetLastError(ERROR_INVALID_PARAMETER);
bRet = FALSE;
}
else
{
PPOWER_CAPABILITIES power = (PPOWER_CAPABILITIES)pBufOut;
memset(power, 0, sizeof(POWER_CAPABILITIES));
SetPwmPower(power); // get configurations from PDD layer
*pdwActualOut = sizeof(POWER_CAPABILITIES);
bRet = TRUE;
}
break;
case IOCTL_POWER_GET:
if(pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE))
{
*(PCEDEVICE_POWER_STATE)pBufOut = CurrentDx;
bRet = TRUE;
}
break;
case IOCTL_POWER_SET:
if(pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE))
{
CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
if(VALID_DX(NewDx))
{
if(NewDx == D1)
{
NewDx = D0;
}
if(NewDx == D3)
{
NewDx = D4; // turn off
}
if(NewDx == D0)
{
if (!BSPPwmSetClockGatingMode(TRUE))
{
DEBUGMSG(ZONE_ERROR, (TEXT("Error enabling PWM clock mode.\r\n")));
}
}
if(NewDx == D4)
{
if (!BSPPwmSetClockGatingMode(FALSE))
{
DEBUGMSG(ZONE_ERROR, (TEXT("Error disabling PWM clock mode.\r\n")));
}
}
CurrentDx = NewDx;
bRet = TRUE;
}
else
{
DEBUGMSG(ZONE_WARN, (TEXT("DUM_IOControl: IOCTL_POWER_SET: invalid state request %u\r\n"), NewDx));
}
}
break;
default:
DEBUGMSG(ZONE_WARN, (TEXT("PWM_IOControl: No matching IOCTL.\r\n")));
break;
}
return bRet;
}
BOOL WINAPI PWM_DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
//Register Debug Zones
DEBUGREGISTER((HINSTANCE) hInstDll);
DEBUGMSG(ZONE_INFO, (TEXT("PWM_DllEntry: DLL_PROCESS_ATTACH lpvReserved(0x%x)\r\n"),lpvReserved));
DisableThreadLibraryCalls((HMODULE) hInstDll);
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_INFO, (TEXT("PWM_DllEntry: DLL_PROCESS_DETACH lpvReserved(0x%x)\r\n"),lpvReserved));
break;
}
// Return TRUE for success
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -