📄 pwmmdd.c
字号:
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// Freescale Semiconductor, Inc.
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// File: pwmmdd.c
//
// This module provides a stream interface for the PWM
// driver. Client drivers can use the stream interface to
// configure the PWM driver and run test programs.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include "mxarm11.h"
#include "pwmdefs.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
extern BOOL BSPPwmSetClockGatingMode(BOOL startClocks);
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
#define REG_DEVINDEX_VAL_NAME TEXT("Index")
#define PWM_DEVICE_CONTEXT_HANDLE 0xCAFE
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
_T("PWM"),
{
_T("Init"), _T("DeInit"), _T("Ioctl"), _T(""),
_T(""), _T(""), _T(""), _T(""),
_T(""),_T(""),_T(""),_T(""),
_T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
},
ZONEMASK_ERROR | ZONEMASK_WARN
};
#endif
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
static CEDEVICE_POWER_STATE CurrentDx;
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Function: PWM_Init
//
// The Device Manager calls this function as a result of a call to the
// ActivateDevice() function.
//
// Parameters:
// pContext
// [in] Pointer to a string containing the registry path to the
// active key for the stream interface driver.
//
// Returns:
// Returns a handle to the device context created if successful. Returns
// zero if not successful.
//
//------------------------------------------------------------------------------
DWORD PWM_Init(LPCTSTR pContext)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Init\r\n")));
if (!PwmInitialize())
return 0;
CurrentDx = D4;
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Init\r\n")));
return PWM_DEVICE_CONTEXT_HANDLE;
}
//------------------------------------------------------------------------------
//
// Function: PWM_Deinit
//
// This function uninitializes a device.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL PWM_Deinit(DWORD hDeviceContext)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Deinit\r\n")));
PwmDeinit();
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Deinit\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PWM_Open
//
// This function opens a device for reading, writing, or both.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context. The XXX_Init function creates
// and returns this handle.
//
// AccessCode
// [in] Access code for the device. The access is a combination of
// read and write access from CreateFile.
//
// ShareMode
// [in] File share mode of the device. The share mode is a
// combination of read and write access sharing from CreateFile.
//
// Returns:
// This function returns a handle that identifies the open context of
// the device to the calling application.
//
//------------------------------------------------------------------------------
DWORD PWM_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
DWORD dwStatus;
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Open\r\n")));
dwStatus = DevicePowerNotify(_T("PWM1:"), D0, POWER_NAME);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_WARN, (_T("PWM1: DevicePowerNotify(D0) failed %d.\r\n"), dwStatus));
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Open\r\n")));
return PWM_DEVICE_CONTEXT_HANDLE;
}
//------------------------------------------------------------------------------
//
// Function: PWM_Close
//
// This function closes the PWM for reading and writing.
//
// Parameters:
// hOpenContext
// [in] Handle returned by the XXX_Open function, used to identify
// the open context of the device.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL PWM_Close(DWORD hOpenContext)
{
DWORD dwStatus;
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_Close\r\n")));
dwStatus = DevicePowerNotify(_T("PWM1:"), D4, POWER_NAME);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_WARN, (_T("PWM1: DevicePowerNotify(D4) failed %d.\r\n"), dwStatus));
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_Close\r\n")));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PWM_PowerDown
//
// This function suspends power to the device. It is useful only with
// devices that can power down under software control.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PWM_PowerDown(DWORD hDeviceContext)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("++PWM_PowerDown\r\n")));
DEBUGMSG(ZONE_FUNCTION, (TEXT("--PWM_PowerDown\r\n")));
}
//------------------------------------------------------------------------------
//
// Function: PWM_PowerUp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -