|
唉,又来问人了!流驱动的测试程序,最简单的也没搞定
[复制链接]
最近写了一个rtc驱动,驱动加载没问题,而且关机后rtc也能跑起来,但是要对rtc进行读写,所以在RTC_IOControl里实现,但是测试程序能CreateFile打开,但是在调用DeviceIoControl始终返回失败,无法对rtc进行读写。下面对驱动中的RTC_IOControl。
BOOL RTC_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
// int nIndex=0;
BOOL bRet = FALSE;
SYSTEMTIME* st;
BYTE bBufIn[6] ;
BYTE bBufOut[6];
//INT iResult;
// WORD* wData;
// BYTE bySlaveAddr = 0x32;
InitializeCriticalSection(&RTC_critsect);
RETAILMSG(RTC_DEBUG,(TEXT("ioctrl: RTC_IOControl, Code: %x\r\n"), dwCode));
switch(dwCode)
{
case RTC_WRITE_CURRENT_TIME:
EnterCriticalSection(&RTC_critsect);
st = (SYSTEMTIME*)pBufIn;
memset(bBufIn, 0, 6);
TimestoBCD(st, bBufIn);
Write_SD2068(hI2C, RTC_I2C_ADDRESS, bBufIn);
bRet = TRUE;
LeaveCriticalSection(&RTC_critsect);
break;
case RTC_READ_CURRENT_TIME:
//st = (SYSTEMTIME*)pBufOut;
EnterCriticalSection(&RTC_critsect);
st = NULL;
st->wMilliseconds = 0;
memset(bBufOut, 0, 6);
Read_SD2068( hI2C, RTC_I2C_ADDRESS, bBufOut);
BCDtoTimes(bBufOut, st);
pBufOut = (PBYTE)st;
bRet = TRUE;
LeaveCriticalSection(&RTC_critsect);
break;
default:
break;
}
return bRet;
}
以下为DeviceIoControl函数。
void CRTC_testDlg::OnBtnWriteRtc()
{
// TODO: Add your control notification handler code here
BOOL bWrite;
UpdateData(TRUE);
m_sysTime.wYear = m_uYear;
m_sysTime.wMonth = m_uMonth;
m_sysTime.wDay = m_uDay;
m_sysTime.wHour = m_uHour;
m_sysTime.wMinute = m_uMin;
m_sysTime.wSecond = m_uSec;
if(!m_hRTC)
m_hRTC = CreateFile(TEXT("RTC1:"), // name of device
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (ignored)
OPEN_EXISTING, // creation disposition
NULL, // flags/attributes
NULL);
if (m_hRTC == INVALID_HANDLE_VALUE)
{
RETAILMSG(1, (TEXT(" CreateFile for RTC failed!\r\n")));
MessageBox(TEXT("m_hRTC is failed! "), NULL, MB_OK);
}
else
MessageBox(TEXT("m_hRTC is OK! "), NULL, MB_OK);
if(!SetSystemTime(&m_sysTime))
MessageBox(TEXT("SetSystemTime is failed! "), NULL, MB_OK);
if(m_hRTC)
bWrite = DeviceIoControl(m_hRTC, RTC_WRITE_CURRENT_TIME, &m_sysTime, sizeof(SYSTEMTIME), NULL, 0, NULL,NULL);
else
MessageBox(TEXT("m_hRTC is failed! "), NULL, MB_OK);
if(!bWrite)
{
MessageBox(TEXT("bWrite is failed! "), NULL, MB_OK);
RETAILMSG(1,(TEXT("DeviceIoControl Write is error!")));
}
}
|
|