📄 chap_9.asm
字号:
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
jump Clear_Feature_Exit;
NotTo_USB_RECIPIENT_DEVICE_ClearFeature:
//if bRequestType==USB_RECIPIENT_ENDPOINT
r1=USB_RECIPIENT_ENDPOINT;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_ENDPOINT_ClearFeature;
//if wValue==USB_FEATURE_ENDPOINT_STALL
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
r1=USB_FEATURE_ENDPOINT_STALL;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_ENDPOINT_ClearFeature;
p0.l=lo(wIndex);
p0.h=hi(wIndex);
r0=[p0];
r1=MAX_ENDPOINTS;
r1=r0&r1;
r2=USB_ENDPOINT_DIRECTION_MASK;
r2=r0&r2;
cc=r2==0;
if !cc jump StallOutEP_ClearFeature;
//Unstall Input EndPoint
r1=r1<<1;
r1+=1;
p0.l=lo(bEndp);
p0.h=hi(bEndp);
[p0]=r1;
p0.l=lo(bStalled);
p0.h=hi(bStalled);
r0=0;
[p0]=r0;
call SetEndpointStatus;
jump StallEPEnd_ClearFeature;
StallOutEP_ClearFeature:
r1=r1<<1;
p0.l=lo(bEndp);
p0.h=hi(bEndp);
[p0]=r1;
p0.l=lo(bStalled);
p0.h=hi(bStalled);
r0=0;
[p0]=r0;
call SetEndpointStatus;
StallEPEnd_ClearFeature:
//call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
jump Clear_Feature_Exit;
NotTo_USB_RECIPIENT_ENDPOINT_ClearFeature:
call Stall_ep0;
Clear_Feature_Exit:
r2=[ SP++ ]; //pop r2
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Clear_Feature.end:
/****************************************
** 函数名称: Set_Feature(void)
** 功能描述: 设置特性
*****************************************/
.global Set_Feature;
Set_Feature:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
[ --SP ]=r2; //push r2
//if bRequestType==USB_RECIPIENT_DEVICE
p0.l=lo(bRequestType);
p0.h=hi(bRequestType);
r0=[p0];
r1=USB_RECIPIENT;
r0=r0&r1;
r1=USB_RECIPIENT_DEVICE;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_DEVICE;
//if wValue==USB_FEATURE_REMOTE_WAKEUP
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
r1=USB_FEATURE_REMOTE_WAKEUP;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_DEVICE;
//set flag Remote_Wakeup=1
p0.l=lo(Remote_Wakeup);
p0.h=hi(Remote_Wakeup);
r0=1;
[p0]=r0;
//call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
jump Set_Feature_Exit;
NotTo_USB_RECIPIENT_DEVICE:
//if bRequestType==USB_RECIPIENT_ENDPOINT
r1=USB_RECIPIENT_ENDPOINT;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_ENDPOINT;
//if wValue==USB_FEATURE_ENDPOINT_STALL
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
r1=USB_FEATURE_ENDPOINT_STALL;
cc=r0==r1;
if !cc jump NotTo_USB_RECIPIENT_ENDPOINT;
p0.l=lo(wIndex);
p0.h=hi(wIndex);
r0=[p0];
r1=MAX_ENDPOINTS;
r1=r0&r1;
r2=USB_ENDPOINT_DIRECTION_MASK;
r2=r0&r2;
cc=r2==0;
if !cc jump StallOutEP;
//Stall Input EndPoint
r1=r1<<1;
r1+=1;
p0.l=lo(bEndp);
p0.h=hi(bEndp);
[p0]=r1;
p0.l=lo(bStalled);
p0.h=hi(bStalled);
r0=1;
[p0]=r0;
call SetEndpointStatus;
jump StallEPEnd;
StallOutEP:
r1=r1<<1;
p0.l=lo(bEndp);
p0.h=hi(bEndp);
[p0]=r1;
p0.l=lo(bStalled);
p0.h=hi(bStalled);
r0=1;
[p0]=r0;
call SetEndpointStatus;
StallEPEnd:
//call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
jump Set_Feature_Exit;
NotTo_USB_RECIPIENT_ENDPOINT:
call Stall_ep0;
Set_Feature_Exit:
r2=[ SP++ ]; //pop r2
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Set_Feature.end:
/****************************************
** 函数名称: Set_Address(void)
** 功能描述: 设置地址
*****************************************/
.global Set_Address;
Set_Address:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
//SetAddressEnable(wValue & DEVICE_ADDRESS_MASK, 1);
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
r1=DEVICE_ADDRESS_MASK;
r0=r0&r1;
p0.l=lo(bAddress);
p0.h=hi(bAddress);
[p0]=r0;
p0.l=lo(bEnable);
p0.h=hi(bEnable);
r0=1;
[p0]=r0;
call SetAddressEnable;
//call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Set_Address.end:
/****************************************
** 函数名称: Get_Descriptor(void)
** 功能描述: 获取描述符
*****************************************/
.global Get_Descriptor;
Get_Descriptor:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
//get wValue High 8bit
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
r0=r0>>8;
r1=0xff;
r0=r0&r1;
r1=USB_DEVICE_DESCRIPTOR_TYPE;
cc=r0==r1;
if !cc jump Not_USB_DEVICE_DESCRIPTOR_TYPE;
//code_transmit((INT8U *)&DeviceDescr, sizeof(USB_DEVICE_DESCRIPTOR);
////pBuf=&DeviceDescTable
r0.l=lo(DeviceDescTable);
r0.h=hi(DeviceDescTable);
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
////bLen=18
p0.l=lo(bLen);
p0.h=hi(bLen);
r0=18;
[p0]=r0;
call Code_transmit;
jump Get_Descriptor_Exit;
Not_USB_DEVICE_DESCRIPTOR_TYPE:
r1=USB_CONFIGURATION_DESCRIPTOR_TYPE;
cc=r0==r1;
if !cc jump Not_USB_CONFIGURATION_DESCRIPTOR_TYPE;
p0.l=lo(ControlDataLength);
p0.h=hi(ControlDataLength);
r0=[p0];
r1=CONFIG_DESCRIPTOR_LENGTH;
cc=r1<r0;
if !cc jump Send_Descriptor;
[p0]=r1;
Send_Descriptor:
//code_transmit((INT8U *)&(usb_descr.ConfigDescr), ControlData.DeviceRequest.wLength);
////pBuf=&DeviceDescTable
r0.l=lo(UsbDescTable);
r0.h=hi(UsbDescTable);
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
////bLen=46
p0.l=lo(bLen);
p0.h=hi(bLen);
r0=ConfigDescritorLen;
[p0]=r0;
call Code_transmit;
jump Get_Descriptor_Exit;
Not_USB_CONFIGURATION_DESCRIPTOR_TYPE:
call Stall_ep0;
Get_Descriptor_Exit:
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Get_Descriptor.end:
/****************************************
** 函数名称: Get_Configuration(void)
** 功能描述: 获取配置
*****************************************/
.global Get_Configuration;
Get_Configuration:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
//Single_transmit(fConfig,1);
r0.l=lo(fConfig);
r0.h=hi(fConfig);
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
r0=1;
[p0]=r0;
call Single_transmit;
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Get_Configuration.end:
/****************************************
** 函数名称: Set_Configuration(void)
** 功能描述: 设置配置
*****************************************/
.global Set_Configuration;
Set_Configuration:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0];
cc=r0==0;
if !cc jump SetConfig;
//if wValue=0
////call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
/////set flag fConfig=0, indicates that device unconfigured
p0.l=lo(fConfig);
p0.h=hi(fConfig);
[p0]=r0;
////disable all endpoints except EP0
p0.l=lo(bEnable);
p0.h=hi(bEnable);
[p0]=r0;
call SetEndpointEnable;
jump Set_Configuration_Exit;
//if wValue=1
SetConfig:
r1=1;
cc=r0==r1;
if !cc jump NotSetConfig;
////call Single_transmit(0,0)
r0=0;
p0.l=lo(pBuf);
p0.h=hi(pBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
////disable all endpoints except EP0
p0.l=lo(bEnable);
p0.h=hi(bEnable);
r0=1;
[p0]=r0;
call SetEndpointEnable;
////enable all endpoints
r0=1;
[p0]=r0;
call SetEndpointEnable;
/////set flag fConfig=1, indicates that device configured
p0.l=lo(fConfig);
p0.h=hi(fConfig);
[p0]=r0;
jump Set_Configuration_Exit;
NotSetConfig:
call Stall_ep0;
Set_Configuration_Exit:
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Set_Configuration.end:
/****************************************
** 函数名称: Get_Interface(void)
** 功能描述: 获取接口信息
*****************************************/
.global Get_Interface;
Get_Interface:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
//this device supports only 1 interface(interface 0)
p0.l=lo(EP0TxBuf);
p0.h=hi(EP0TxBuf);
r0=0;
[p0]=r0;
//call Single_transmit, send 1 byte to PC
p0.l=lo(pBuf);
p0.h=hi(pBuf);
r0.l=lo(EP0TxBuf);
r0.h=hi(EP0TxBuf);
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
r0=1;
[p0]=r0;
call Single_transmit;
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Get_Interface.end:
/****************************************
** 函数名称: Set_Interface(void)
** 功能描述: 设置接口信息
*****************************************/
.global Set_Interface;
Set_Interface:
[ --SP ] = RETS;
[ --SP ]=p0; //push p0
[ --SP ]=r0; //push r0
[ --SP ]=r1; //push r1
p0.l=lo(wValue);
p0.h=hi(wValue);
r0=[p0]; //read device request value(32 bit)
cc=r0==0;
if !cc jump Not_Set_Interface;
p0.l=lo(wIndex);
p0.h=hi(wIndex);
r0=[p0]; //read device request index(32 bit)
cc=r0==0;
if !cc jump Not_Set_Interface;
//call Single_transmit
p0.l=lo(pBuf);
p0.h=hi(pBuf);
r0=0;
[p0]=r0;
p0.l=lo(bLen);
p0.h=hi(bLen);
[p0]=r0;
call Single_transmit;
jump Set_Interface_Exit;
Not_Set_Interface:
call Stall_ep0;
Set_Interface_Exit:
r1=[ SP++ ]; //pop r1
r0=[ SP++ ]; //pop r0
p0=[ SP++ ]; //pop p0
RETS = [ SP++ ];
rts;
Set_Interface.end:
/*************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -