|
#define MAX_DEVICE_NUM 12
typedef struct dev
{
unsigned char address;
unsigned char speed;
std_dev_descriptor dev_descriptor;
std_conf_descriptor conf_descriptor;
std_interface_descriptor interfacef_descriptor;
endpoint_info *epi_ptr[ MAX_ENDPOINT_NUM ];
#ifdef STRING_DESCRIPTOR
unsigned short *string_manufacturer;
unsigned short *string_product;
unsigned short *string_serialNum;
#endif
void *class_instance_ptr;
unsigned char topology_layer;
}device_instance;
main()
{
device_instance * dviPtr;
...
while (1)
{
dviPtr = find_class_interface(MASS_CLASS_INTERFACE,0); // 查找大容量类设备
if(dviPtr) //注释1
{
...
}
}
}
device_instance *find_class_interface( unsigned char InterfaceClassID, unsigned char DeviceIndex )
{
device_instance *dviPtr;
int i;
for ( i = 2; i <( MAX_DEVICE_NUM); i++ )
{
if ( NULL == (dviPtr = find_device( i )) )
continue;
if ( check_interface_class_ID( dviPtr, InterfaceClassID ) )
{
if(DeviceIndex== 0x00)
return ( dviPtr );
else
DeviceIndex --;
}
}
return ( NULL );
}
device_instance *find_device( unsigned char address )
{
return ( device_list[ address ] );//注释2
}
device_instance *device_list[ MAX_DEVICE_NUM ];//注释3
这是一个USB作为主机查找大容量类设备的部分代码,由于太长,不能全部附上.
问题:
1.if(dviPtr)//注释1
if(dviPtr)总是不能返回True,导致不能执行Main函数以下代码;
2.find_device函数中注释2device_list[ address ]的address是一个变量,然而到了注释3device_instance *device_list[
MAX_DEVICE_NUM ]定义的时候address 变成了常量MAX_DEVICE_NUM,这个又何解?
补充:以上是运行成功的可执行代码移植过来的!
[ 本帖最后由 2010husion 于 2010-12-16 08:31 编辑 ] |
|