6410SPI驱动中SPI_IOControl参数的意义
在6410SPI的驱动中函数SPI_IOControl有以下几个参数:
BOOL SPI_IOControl(
DWORD dwInst,
DWORD dwIoControlCode,
PBYTE lpInBuf,
DWORD nInBufSize,
PBYTE lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesRetruned)
而在6410的ADC驱动中,ADC_IOControl有以下的几个参数:
BOOL ADC_IOControl(DWORD Handle,
DWORD dwIoControlCode,
PDWORD pInBuf,
DWORD nInBufSize,
PDWORD pOutBuf,
DWORD nOutBufSize,
PDWORD pBytesReturned)
SPI_IOControl中的DWORD dwInst和ADC_IOControl中的DWORD Handle是什么意思呀?DeviceIoControl怎么传递参数给这个参数?谁能指导一下呀?
[解决办法]
BOOL XXX_IOControl(
DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut
);
hOpenContext
[in] Handle to the open context of the device. The XXX_Open (Device Manager) 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.
[解决办法]
BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped
);
hDevice
[in] Handle to the device that is to perform the operation. To obtain a device handle, call the CreateFile function.
dwIoControlCode
[in] IOCTL for the operation. This value identifies the specific operation to perform and the type of device on which to perform the operation. There are no specific values defined for the dwIoControlCode parameter. However, you can define custom IOCTL_XXX IOCTLs with the CTL_CODE macro. You can then advertise these IOCTLs and an application can use these IOCTLs with DeviceIoControl to perform the driver-specific functions.
For more information on the CTL_CODE macro, see CTL_CODE.
lpInBuffer
[in] Long pointer to a buffer that contains the data required to perform the operation. Set to NULL if the dwIoControlCode parameter specifies an operation that does not require input data.
nInBufferSize
[in] Size, in bytes, of the buffer pointed to by lpInBuffer.
lpOutBuffer
[out] Long pointer to a buffer that receives the output data for the operation. Set to NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.
nOutBufferSize
[out] Size, in bytes, of the buffer pointed to by lpOutBuffer.
lpBytesReturned
[out] Long pointer to a variable that receives the size, in bytes, of the data stored in lpOutBuffer. The DeviceIoControl function may unnecessarily use this parameter. For example, if an operation does not produce data for lpOutBuffer and lpOutBuffer is NULL, the value of lpBytesReturned is meaningless.
lpOverlapped
[in] Ignored; set to NULL.
------解决方案--------------------
DeviceIoControl函数原型
BOOL DeviceIoControl(
HANDLE hDevice, //驱动文件句柄,由CreateFile()获得
DWORD dwIoControlCode, //命令码
LPVOID lpInBuffer, //输入缓冲区
DWORD nInBufferSize, //输入缓冲区大小
LPVOID lpOutBuffer, //输出缓冲区
DWORD nOutBufferSize, //输出缓冲区大小
LPDWORD lpBytesReturned, //实际输出的数据数量
LPOVERLAPPED lpOverlapped //I/O重叠操作,Windows CE5.0中取值为NULL
)
其中,hDevice为驱动文件句柄。该句柄取自CreateFile()函数的返回值。其他输入/输出参数根据功能的不同而不同。说明如下:
本项目中,各参数对应如下:
参数实现描述
Hdevicem_hPMICCreateFile//返回的设备句柄
dwIoControlCodeIOCTL_PMU_REGULATOR_ON//自己定义的DCDC/LDO开
lpInBuffer&pmic_data//应用程序传递给驱动程序的数据缓冲区地址
nInBufferSizesizeof(UINT32)//应用程序传递给驱动程序的数据缓冲区大小,字节数
lpOutBuffer&dat//驱动程序返回给应用程序的数据缓冲区地址
nOutBufferSizesizeof(UINT32)//驱动程序返回给应用程序的数据缓冲区大小,字节数
lpBytesReturned&bytes//驱动程序实际返回给应用程序的数据字节数地址
lpOverlappedNULL//I/O重叠操作,Windows CE5.0中取值为NULL
[解决办法]
http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/16.gif