📄 test_hcd.c
字号:
/****************************************************************
* MT View Silicon Tech. Inc.
*
* Copyright 2007, MT View Silicon Tech. Inc., ShangHai, China
* All rights reserved.
*
*
* Filename: test_hcd.c
*
* Programmer: Grey
*
* Created: 12/xx/2007
*
* Description: host controller driver test code
*
*
*****************************************************************/
#include "test_hcd.h"
#include <string.h> /* for NULL */
#ifdef PPP
/*------------------------- u-disk endpoint ------------------------*/
#define UDISK_FUNCADDR 1
#define UDISK_BULK_IN_EPNUM 1
#define UDISK_BULK_OUT_EPNUM 2
#define UDISK_BULK_MAX_PKT_SIZE 64
#define UDISK_BULK_DMA_EN 1
/*------------------------------------------------------------------*/
/*------------------------- control request ------------------------*/
static BYTE CODE GetDevDescriptor1[] = {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x08, 0x00,};
static BYTE XDATA GetDevDescriptor2[] = {0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00,};
static BYTE XDATA SetAddress[] = {0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE GetCfgDescriptor9[] = {0x80, 0x06, 0x00, 0x02, 0x00, 0x00, 0x09, 0x00,};
static BYTE XDATA GetCfgDescriptor[] = {0x80, 0x06, 0x00, 0x02, 0x00, 0x00, 0xFF, 0x00,};
static BYTE CODE SetConfig[] = {0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE GetMaxLUN[] = {0xA1, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,};
static BYTE XDATA GetStrDescriptorLongID[] = {0x80, 0x06, 0x00, 0x03, 0x00, 0x00, 0xFF, 0x00,};
static BYTE CODE GetStrDescriptorLongID2[] = {0x80, 0x06, 0x00, 0x03, 0x00, 0x00, 0x02, 0x00,};
static BYTE XDATA GetStrDescriptorSerialNum[] = {0x80, 0x06, 0x03, 0x03, 0x09, 0x04, 0xFF, 0x00,};
static BYTE CODE GetStrDescriptorSerialNum2[] = {0x80, 0x06, 0x03, 0x03, 0x09, 0x04, 0x02, 0x00,};
static BYTE XDATA GetStrDescriptorProduct[] = {0x80, 0x06, 0x02, 0x03, 0x09, 0x04, 0xFF, 0x00,};
static BYTE CODE GetStrDescriptorProduct2[] = {0x80, 0x06, 0x02, 0x03, 0x09, 0x04, 0x02, 0x00,};
/*-------------------------------------------------------------------*/
/*-------------------------- scsi request ---------------------------*/
static BYTE CODE Inquiry[] = {0x55, 0x53, 0x42, 0x43, 0x68, 0x75, 0x95, 0x82, 0x24, 0x00, 0x00, 0x00,
0x80, 0x00, 0x06, 0x12, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE ReadFmtCapacity[] = {0x55, 0x53, 0x42, 0x43, 0x18, 0xDD, 0xBF, 0x82, 0xFC, 0x00, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE RequsetSense[] = {0x55, 0x53, 0x42, 0x43, 0x08, 0x60, 0xA3, 0x82, 0x12, 0x00, 0x00, 0x00,
0x80, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE ReadCapacity[] = {0x55, 0x53, 0x42, 0x43, 0x28, 0x65, 0x9F, 0x82, 0x08, 0x00, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
/* static BYTE CODE ReadLBA1[] = {0x55, 0x53, 0x42, 0x43, 0x28, 0x65, 0x9F, 0x82, 0x00, 0x02, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};*/
static BYTE CODE ReadLBA16[] = {0x55, 0x53, 0x42, 0x43, 0x28, 0x65, 0x9F, 0x82, 0x00, 0x20, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE ModeSense[] = {0x55, 0x53, 0x42, 0x43, 0x08, 0x20, 0xBD, 0x82, 0xC0, 0x00, 0x00, 0x00,
0x80, 0x00, 0x06, 0x1A, 0x00, 0x1C, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
static BYTE CODE TestUnitReady[] = {0x55, 0x53, 0x42, 0x43, 0x08, 0x90, 0x91, 0x82, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
/* static BYTE CODE WriteLBA1[] = {0x55, 0x53, 0x42, 0x43, 0x28, 0x65, 0x9F, 0x82, 0x00, 0x02, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};*/
static BYTE CODE WriteLBA16[] = {0x55, 0x53, 0x42, 0x43, 0x28, 0x65, 0x9F, 0x82, 0x00, 0x20, 0x00, 0x00,
0x80, 0x00, 0x0A, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};
/*------------------------------------------------------------------*/
extern BOOL
TestUdiskCtrl(
URB *urb
)
{
BYTE XDATA val[10][64];
urb->FuncAddr = 0;
urb->EndPointNum = 0;
urb->TransferType = USB_ENDPOINT_XFER_CONTROL;
urb->Direction = USB_DIR_IN;
urb->MaxPacketSize = 8;
urb->Interval = 0;
/* get device descriptor1 */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetDevDescriptor1;
urb->DataBuffer = val[0];
urb->DataLength = 8;
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
urb->MaxPacketSize = val[0][7];
GetDevDescriptor2[6] = val[0][0]; /* descripter length */
/* reset USB bus */
HciResetUsb(urb->HcPriv);
/* set address */
SetAddress[2] = UDISK_FUNCADDR;
urb->Direction = USB_DIR_OUT;
urb->SetupPacket = SetAddress;
urb->DataBuffer = NULL;
urb->DataLength = 0;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
urb->FuncAddr = UDISK_FUNCADDR;
/* get device descriptor2 */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetDevDescriptor2;
urb->DataBuffer = val[1];
urb->DataLength = GetDevDescriptor2[6];
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* get configuration descriptor9 */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetCfgDescriptor9;
urb->DataBuffer = val[2];
urb->DataLength = 9;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
GetCfgDescriptor[6] = val[2][2];
/* get configuration descriptor */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetCfgDescriptor;
urb->DataBuffer = val[3];
urb->DataLength = GetCfgDescriptor[6];
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* get string descriptor long ID 2 bytes */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorLongID2;
urb->DataBuffer = val[4];
urb->DataLength = 2;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
GetStrDescriptorLongID[6] = val[4][0];
/* get string descriptor long ID */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorLongID;
urb->DataBuffer = val[4];
urb->DataLength = GetStrDescriptorLongID[6];
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* get string descriptor serial number 2 bytes */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorSerialNum2;
urb->DataBuffer = val[5];
urb->DataLength = 2;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
GetStrDescriptorSerialNum[6] = val[5][0];
/* get string descriptor serial number */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorSerialNum;
urb->DataBuffer = val[5];
urb->DataLength = GetStrDescriptorSerialNum[6];
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* get string descriptor product 2 bytes */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorProduct2;
urb->DataBuffer = val[6];
urb->DataLength = 2;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
GetStrDescriptorProduct[6] = val[6][0];
/* get string descriptor product */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetStrDescriptorProduct;
urb->DataBuffer = val[6];
urb->DataLength = GetStrDescriptorProduct[6];
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* set configuration */
urb->Direction = USB_DIR_OUT;
urb->SetupPacket = SetConfig;
urb->DataBuffer = NULL;
urb->DataLength = 0;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* get max LUN */
urb->Direction = USB_DIR_IN;
urb->SetupPacket = GetMaxLUN;
urb->DataBuffer = val[7];
urb->DataLength = 1;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
return TRUE;
}
extern BOOL
TestUdiskBulk(
URB *urb,
BYTE *buffer
)
{
// URB XDATA urb;
// HC_ED XDATA *bulkInEd, *bulkOutEd;
BYTE XDATA val[20][64];
// urb->Hci = hci;
// bulkInEd = HciAllocED(hci);
// bulkInEd->FuncAddr = UDISK_FUNCADDR;
// bulkInEd->EndPointNum = UDISK_BULK_IN_EPNUM;
// bulkInEd->TransferType = USB_ENDPOINT_XFER_BULK;
// bulkInEd->Direction = USB_DIR_IN;
// bulkInEd->MaxPacketSize = UDISK_BULK_MAX_PKT_SIZE;
// bulkInEd->Interval = 0;
// HciCreateDevEndpoint(hci, bulkInEd);
// bulkOutEd = HciAllocED(hci);
// bulkOutEd->FuncAddr = UDISK_FUNCADDR;
// bulkOutEd->EndPointNum = UDISK_BULK_OUT_EPNUM;
// bulkOutEd->TransferType = USB_ENDPOINT_XFER_BULK;
// bulkOutEd->Direction = USB_DIR_OUT;
// bulkOutEd->MaxPacketSize = UDISK_BULK_MAX_PKT_SIZE;
// bulkOutEd->Interval = 0;
// HciCreateDevEndpoint(hci, bulkOutEd);
urb->FuncAddr = UDISK_FUNCADDR;
urb->EndPointNum = UDISK_BULK_IN_EPNUM;
urb->TransferType = USB_ENDPOINT_XFER_BULK;
urb->Direction = USB_DIR_IN;
urb->MaxPacketSize = UDISK_BULK_MAX_PKT_SIZE;
urb->Interval = 0;
/* inquiry */
/* CBW */
// urb->Ed = bulkOutEd;
urb->EndPointNum = UDISK_BULK_OUT_EPNUM;
urb->Direction = USB_DIR_OUT;
urb->SetupPacket = NULL;
urb->DataBuffer = Inquiry;
urb->DataLength = 31;
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* DATA */
// urb->Ed = bulkInEd;
urb->EndPointNum = UDISK_BULK_IN_EPNUM;
urb->Direction = USB_DIR_IN;
urb->SetupPacket = NULL;
urb->DataBuffer = val[0];
urb->DataLength = Inquiry[19];
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* CSW */
// urb->Ed = bulkInEd;
urb->EndPointNum = UDISK_BULK_IN_EPNUM;
urb->Direction = USB_DIR_IN;
urb->SetupPacket = NULL;
urb->DataBuffer = val[1];
urb->DataLength = 13;
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* read fmt capacity */
/* CBW */
// urb->Ed = bulkOutEd;
urb->EndPointNum = UDISK_BULK_OUT_EPNUM;
urb->Direction = USB_DIR_OUT;
urb->SetupPacket = NULL;
urb->DataBuffer = ReadFmtCapacity;
urb->DataLength = 31;
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* DATA */
// urb->Ed = bulkInEd;
urb->EndPointNum = UDISK_BULK_IN_EPNUM;
urb->Direction = USB_DIR_IN;
urb->SetupPacket = NULL;
urb->DataBuffer = val[2];
urb->DataLength = 12;
urb->IsUseDMA = 0;
urb->Err = NO_ERROR;
if (HciSendUrb(urb) != NO_ERROR)
return FALSE;
/* CSW */
// urb->Ed = bulkInEd;
urb->EndPointNum = UDISK_BULK_IN_EPNUM;
urb->Direction = USB_DIR_IN;
urb->SetupPacket = NULL;
urb->DataBuffer = val[3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -