📄 03.htm
字号:
get_max_LUN(void) //获取磁盘最大逻辑单元号<BR>{<BR>unsigned
char
max_LUN=MAX_LUN; //只有一个逻辑单元<BR>UEPNUM=0;<BR>UEPSTAX=(UEPSTAX
|
0x80); //数据阶段的输入<BR>write_endpoint_buff(0,1,&(max_LUN));<BR>UEPSTAX=(UEPSTAX
& (~0x80));<BR>USB_usb_endp0_in=0;<BR>}<BR><BR>void
mass_storage_reset(void) //USB大容量存储设备复位<BR>{<BR>write_endpoint_buff(0,0,0);<BR>USB_usb_endp0_in=0;<BR>USB_setup_packet_out=0;<BR>SCSI_Command=1;<BR>SCSI_Data=0;<BR>}<BR><BR><BR>void
get_descriptor(void) //获取描述符<BR>{<BR>if(!USB_not_end)<BR> {<BR> switch(MSB(Control_Data.DeviceRequest.wValue))<BR> {<BR> case
DEVICE_DESCRIPTOR:<BR> Control_Data.wCount=sizeof(DEVICE_DESCRIPTOR_STRUCT);<BR> Control_Data.pData=(unsigned
char
*)(&device_descriptor);<BR> break;<BR> case
CONFIGURATION_DESCRIPTOR:<BR> Control_Data.wCount=SWAP(con_int_endp_descriptor.configuration_descriptor.wTotalLength);<BR> Control_Data.pData=(unsigned
char
*)(&con_int_endp_descriptor);<BR> if(Control_Data.wLength<Control_Data.wCount)Control_Data.wCount=Control_Data.wLength;<BR> break;<BR> case
STRING_DESCRIPTOR:<BR> if(LSB(Control_Data.DeviceRequest.wValue)==0)<BR> {<BR> Control_Data.wCount=LANGUAGE_ID[0];<BR> Control_Data.pData=LANGUAGE_ID;<BR> }<BR> if(LSB(Control_Data.DeviceRequest.wValue)==2)<BR> {<BR> Control_Data.wCount=device_serial_number[0];<BR> Control_Data.pData=device_serial_number;<BR> }<BR> break;<BR> }<BR> if(Control_Data.wLength<Control_Data.wCount)Control_Data.wCount=Control_Data.wLength;<BR> }<BR>if(Control_Data.wCount>=MAX_CONTROL_DATA_SIZE)<BR> {<BR> UEPNUM=0;<BR> UEPSTAX=(UEPSTAX
|
0x80); //数据阶段的输入<BR> write_endpoint_buff(0,MAX_CONTROL_DATA_SIZE,Control_Data.pData);<BR> UEPSTAX=(UEPSTAX
&
(~0x80));<BR> Control_Data.pData+=MAX_CONTROL_DATA_SIZE;<BR> Control_Data.wCount-=MAX_CONTROL_DATA_SIZE;<BR> if(USB_set_addr)USB_not_end=1;<BR> else
USB_usb_endp0_in=0;<BR> return;<BR> }<BR>else<BR> {<BR> UEPNUM=0;<BR> UEPSTAX=(UEPSTAX
|
0x80); //数据阶段的输入<BR> write_endpoint_buff(0,Control_Data.wCount,Control_Data.pData);<BR> UEPSTAX=(UEPSTAX
&
(~0x80));<BR> USB_setup_packet_in=0;<BR> USB_usb_endp0_in=0;<BR> return;<BR> } <BR>}<BR><BR>void
endp0_out(void) //终端点0输出中断处理<BR>{<BR>if(status_setup_packet)<BR> {<BR> Control_Data.wLength=0;<BR> Control_Data.wCount=0;<BR> if(read_endpoint_buff(0,sizeof(Control_Data.DeviceRequest),(unsigned
char
*)(&(Control_Data.DeviceRequest)))!=sizeof(REQUESTCMD))<BR> {<BR> error(1);<BR> return;<BR> }<BR> UEPNUM=0;<BR> UEPSTAX=
UEPSTAX &
(~0x04); //清除SETUP标记<BR> Control_Data.DeviceRequest.wValue=SWAP(Control_Data.DeviceRequest.wValue);<BR> Control_Data.DeviceRequest.wIndex=SWAP(Control_Data.DeviceRequest.wIndex);<BR> Control_Data.DeviceRequest.wLength=SWAP(Control_Data.DeviceRequest.wLength);<BR> Control_Data.wLength=Control_Data.DeviceRequest.wLength;<BR> USB_not_end=0;<BR> USB_usb_endp0_in=1;<BR> USB_setup_packet_in=0;<BR> USB_setup_packet_out=0;<BR> if(Control_Data.DeviceRequest.bmRequestType&0x80){USB_setup_packet_in=1;return;}<BR> else
{USB_setup_packet_out=1;return;}<BR>}<BR>else<BR> {<BR> read_endpoint_buff(0,0,0);<BR> }<BR>}<BR><BR>void
endp0_in(void) //终端点0输入处理<BR>{<BR>if(USB_setup_packet_in||USB_not_end)<BR> {<BR> if((Control_Data.DeviceRequest.bmRequestType==0xA1)&&(Control_Data.DeviceRequest.bRequest==0xFE))get_max_LUN();<BR> switch(Control_Data.DeviceRequest.bmRequestType&0x7B)<BR> {<BR> case
0:<BR> switch
(Control_Data.DeviceRequest.bRequest)<BR> {<BR> case
0:
get_status(0);break;<BR> case
6:
get_descriptor();break;<BR> case
8:
get_configuration();break;<BR> default:break;<BR> }<BR> case
1:<BR> switch
(Control_Data.DeviceRequest.bRequest)<BR> {<BR> case 0:
get_status(1);break;<BR> case
10:
get_interface();break;<BR> default:
break;<BR> }<BR> case
2:<BR> {<BR> if(Control_Data.DeviceRequest.bRequest==0)get_status(2); <BR> }<BR> default:
break;<BR> }<BR> return;<BR> }<BR>if(USB_setup_packet_out)<BR> {<BR> if((Control_Data.DeviceRequest.bmRequestType==0x21)&&(Control_Data.DeviceRequest.bRequest==0xFF))<BR> mass_storage_reset();<BR><BR> switch(Control_Data.DeviceRequest.bmRequestType&0x03)<BR> {<BR> case
0:<BR> switch
(Control_Data.DeviceRequest.bRequest)<BR> {<BR> case CLEAR_FEATURE:
clear_feature(0);break;<BR> case SET_FEATURE:
set_feature(0);break;<BR> case SET_ADDRESS:
set_usb_address();break; //set_address <BR> case SET_DESCRIPTOR:
set_descriptor();break; //set_descriptor<BR> case
SET_CONFIGURATION: set_configuration();
break; //set_configurat <BR> default:
break;<BR> }break;<BR> case
1:<BR> switch
(Control_Data.DeviceRequest.bRequest)<BR> {<BR> case
CLEAR_FEATURE: clear_feature(1);break;<BR> case SET_FEATURE: set_feature(1);
break;<BR> case
SET_INTERFACE:
set_interface();break;<BR> default:
break;<BR> }break;<BR> case
2:<BR> switch
(Control_Data.DeviceRequest.bRequest)<BR> {<BR> case
CLEAR_FEATURE:
clear_feature(2);break;<BR> case SET_FEATURE:
set_feature(2);break;<BR> default:
break; <BR> }break;<BR> default:
break;<BR> }<BR> }<BR>}<BR><BR><BR>void
Return_CSW(unsigned long int DataResidue,unsigned char
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -