阅读:1256回复:3
请教:一启用USB驱动程序就死机
编写的USB驱动程序,主要的例程是Read(KIrp)和Write(KIrp)以及读写完成例程,打开应用程序,写数据ok,但一读数据电脑就黑屏重启,我的读写数据都是通过端点2,一个pipein一个pipeout, 请教各位大侠是什么原因,我想用 softIce调试,一设置好它,重启电脑就启动不起来,好郁闷
|
|
沙发#
发布于:2007-03-28 21:52
代码如下,一从USB设备读数据就死机,写数据ok,请各位大侠帮忙分析分析原因,先谢谢各位大侠了
NTSTATUS Test11Device::Read(KIrp I) { T.Trace(TraceInfo, __FUNCTION__"++. IRP %p\n", I); NTSTATUS status = STATUS_SUCCESS; // TODO: Validate the parameters of the IRP. Replace "FALSE" // in the following line with error checking code that // evaulates to TRUE if the request is not valid. if (FALSE) { status = STATUS_INVALID_PARAMETER; I.Information() = 0; I.PnpComplete(status); T.Trace(TraceWarning, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } // Always ok to read 0 elements if (I.ReadSize() == 0) { I.Information() = 0; I.PnpComplete(this, status); T.Trace(TraceInfo, __FUNCTION__"--. IRP %p, STATUS %x\n", I, status); return status; } KMemory Mem(I.Mdl()); ULONG dwTotalSize = I.ReadSize(CURRENT); ULONG dwMaxSize = PipeIn.MaximumTransferSize(); // If the total requested read size is greater than the Maximum Transfer // Size for the Pipe, request to read only the Maximum Transfer Size since // the bus driver will fail an URB with a TransferBufferLength of greater // than the Maximum Transfer Size. if (dwTotalSize > dwMaxSize) { ASSERT(dwMaxSize); dwTotalSize = dwMaxSize; } // Allocate a new context structure for Irp completion USB_COMPLETION_INFO* pCompInfo = new (NonPagedPool) USB_COMPLETION_INFO; if (pCompInfo == NULL) { I.Information() = 0; return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES); } // TODO: Select the correct pipe to read from // Create an URB to do actual Bulk read from the pipe PURB pUrb = PipeIn.BuildBulkTransfer( Mem, // Where is data coming from? dwTotalSize, // How much data to read? TRUE, // direction (TRUE = IN) NULL, // Link to next URB TRUE // Allow a short transfer ); if (pUrb == NULL) { delete pCompInfo; I.Information() = 0; return I.PnpComplete(this, STATUS_INSUFFICIENT_RESOURCES); } // Initialize context structure pCompInfo->m_pClass = this; pCompInfo->m_pUrb = pUrb; // Submit the URB to our USB device status = PipeIn.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, 0); return status; } NTSTATUS Test11Device::ReadComplete(KIrp I, USB_COMPLETION_INFO* pContext) { // Normal completion routine code to propagate pending flag if (I->PendingReturned) { I.MarkPending(); } NTSTATUS status = I.Status(); PURB pUrb = pContext->m_pUrb; ULONG nBytesRead = 0; if ( NT_SUCCESS(status) ) { nBytesRead = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength; if (nBytesRead > 0) T << "Read() got " << nBytesRead<< " bytes from USB\n"; } // Deallocate Urb and context structure delete pUrb; delete pContext; // set returned count I.Information() = nBytesRead; // I.PnpComplete(this, STATUS_SUCCESS); // Plug and Play accounting DecrementOutstandingRequestCount(); // allow IRP completion processing return STATUS_SUCCESS; } |
|
板凳#
发布于:2007-03-29 09:45
你在DRIVERSTDIO的SETTING里把softice设置一下,如果死机重起请按ESC进入DRIVERSTDIO设置环境按D键就可以进去了
|
|
地板#
发布于:2007-03-29 12:21
我设置好softIce后重新启动计算机,就黑屏,按什么都没反应,设置好不重起按ctrl+d就黑屏,再按ctrl+d就推出,一调试就黑屏或花屏,我装的是ds3.2,系统是XP Professional,sp2
|
|