bobsky
驱动牛犊
驱动牛犊
  • 注册日期2003-03-13
  • 最后登录2003-06-03
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:981回复:1

请教d12开发的具体程序代码解答??(毕业设计急)30分给予

楼主#
更多 发布于:2003-05-22 22:43
请问只须采用中断读写时d12时,他上面的d2,d3LED灯就会闪烁。那样的话是不是需要写一个底层驱动能识别的URB包通过IOCONTROL发送过去呢?
那这样是不是需与写下层(其他人)的与我定个协议什么的?
我现在作PC机端的USB驱动的毕业设计,现在基本驱动已完成。其中写可以,而读不行(老死机)。目前只希望能让灯闪烁,读写能成功。/
(不管用什么方法)时间非常急。望哪位大侠曾经做过d12的 。且是用driverworks做的,有这个经验的帮兄弟一把。(因为我是用driverworks生成的框架代码)/
以下是读的代码请高手看看有什么不对望指教:
NTSTATUS D12ssDevice::Read(KIrp I)
{
// TODO: Check the incoming request.  Replace \"FALSE\" in the following
// line with a check that returns TRUE if the request is not valid.

    if (FALSE) // If (Request is invalid)
{
// Invalid parameter in the Read request
I.Information() = 0;
return I.PnpComplete(this, STATUS_INVALID_PARAMETER);
}

// Always ok to read 0 elements.

if (I.ReadSize() == 0)
{
I.Information() = 0;
return I.PnpComplete(this, STATUS_SUCCESS);
}

PUCHAR pBuffer = (PUCHAR) I.BufferedReadDest();

    ULONG dwTotalSize = I.ReadSize(CURRENT);
ULONG dwMaxSize = m_Endpoint2IN.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 = m_Endpoint2IN.BuildBulkTransfer(
    pBuffer,       // 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
NTSTATUS status;
status = m_Endpoint2IN.SubmitUrb(I, pUrb, LinkTo(ReadComplete), pCompInfo, 0);
return status;
}
///////////////////////////////////////////////////////////////////////////////////////
//D12ssDevice::ReadComplete
//
// Routine Description:
// Completion Handler for IRP_MJ_READ
//
// Parameters:
// I - IRP just completed by USB
// pContext - Context structure containing pointer to Urb
//
// Parameters:
// NTSTATUS - STATUS_SUCCESS
//
// Comments:
// This routine is called when USBD completes the read request
//////////////////////////////////////////////////////////////////////////////////////

NTSTATUS D12ssDevice::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;

// Deallocate Urb and context structure
delete pUrb;
delete pContext;

// set returned count
I.Information() = nBytesRead;

// Plug and Play accounting
DecrementOutstandingRequestCount();

// allow IRP completion processing
return STATUS_SUCCESS;
}
//////////////////////////////////////////////////////////
bobsky
驱动牛犊
驱动牛犊
  • 注册日期2003-03-13
  • 最后登录2003-06-03
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-05-22 22:49
补充:
如何我的驱动程序里在写时(这是成功的),为何d2,d3灯不亮?
我用周立功的驱动程序和他的测试程序读写时就能闪烁?
其中我的读写是bulk类型,endpoint2。
游客

返回顶部