usb_coer.c的文件里面
voidDataStageIn(void)
{
ENDPOINT_INFO *pEPinfo =&pInformation->Ctrl_Info; //端点信息保存在指针变量中
uint32_t save_wLength =pEPinfo->Usb_wLength; //得到字符的长度
uint32_t ControlState =pInformation->ControlState; //得到当前的状态
uint8_t*DataBuffer;
uint32_t Length;
if((save_wLength == 0) &&(ControlState == LAST_IN_DATA)) //如果字符长度为0 且控制状态是最后输入的数据
{
if(Data_Mul_MaxPacketSize ==TRUE) //如果字符的长度是数据包的整数倍
{
Send0LengthData();
ControlState = LAST_IN_DATA;
Data_Mul_MaxPacketSize =FALSE; //这一次发送0字节状态转为最后输入阶段
}
else //字符的长度比数据包要小
{ //数据已经发送完
ControlState = WAIT_STATUS_OUT;
#ifdefSTM32F10X_CL
PCD_EP_Read (ENDP0, 0, 0);
#endif
#ifndefSTM32F10X_CL
vSetEPTxStatus(EP_TX_STALL); //设置端点的发送状态停止
#endif
}
gotoExpect_Status_Out;
}
Length =pEPinfo->PacketSize; //得到数据包大小 64字节
ControlState = (save_wLength<= Length) ? LAST_IN_DATA :IN_DATA;//比较大小得到是LAST_IN_DATA还是IN_DATA 18字节<64字节 ControlState =LAST_IN_DATA
if (Length> save_wLength)
{
Length =save_wLength;
}
DataBuffer =(*pEPinfo->CopyData)(Length); //DataBuffer指向要复制数据的地址这个地址是随Usb_wOffset变化的
#ifdef STM32F10X_CL
PCD_EP_Write (ENDP0, DataBuffer, Length);
#else
//GetEPTxAddr(ENDP0) 得到发送缓冲区相应端点的地址
//将DataBuffer中的数据复制到相应的发送缓冲区中
UserToPMABufferCopy(DataBuffer,GetEPTxAddr(ENDP0), Length);
#endif
SetEPTxCount(ENDP0, Length); //设置相应的端点要发送的字节数
pEPinfo->Usb_wLength -= Length;//等于0
pEPinfo->Usb_wOffset += Length;//偏移到18
vSetEPTxStatus(EP_TX_VALID); //使能发送端点 只要主机的IN令牌包一来SIE就会将描述符返回给主机
USB_StatusOut();
//设置接收端点有效这个实际上使接受也有效,
Expect_Status_Out:
pInformation->ControlState =ControlState; //保存控制状态
}
***************(4)**************
uint8_tIn0_Process(void)
{
uint32_t ControlState =pInformation->ControlState;
if ((ControlState == IN_DATA)|| (ControlState == LAST_IN_DATA))//进入到这里
{
DataStageIn();//第一次取设备描述符只取一次 当前的状态变为WAIT_STATUS_IN 表明设备等待状态过程主机输出0字节
ControlState = pInformation->ControlState;
}
else if (ControlState ==WAIT_STATUS_IN) //设置地址状态阶段进入这个程序
{
if((pInformation->USBbRequest == SET_ADDRESS)&&
(Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
{
SetDeviceAddress(pInformation->USBwValue0); //设置使用新的地址
pUser_Standard_Requests->User_SetDeviceAddress();
}
(*pProperty->Process_Status_IN)();
ControlState=STALLED; //变为这个状态
}
else
{
ControlState= STALLED;
}
pInformation->ControlState =ControlState;
return Post0_Process();
}
uint8_tOut0_Process(void)
{
uint32_t ControlState =pInformation->ControlState;
if ((ControlState == IN_DATA)|| (ControlState == LAST_IN_DATA))
{
//主机在完成传输前终止传输
ControlState= STALLED;
}
else if ((ControlState == OUT_DATA) ||(ControlState == LAST_OUT_DATA))
{
DataStageOut();
ControlState= pInformation->ControlState;
}
else if (ControlState ==WAIT_STATUS_OUT) //进入到这个里面
{
(*pProperty->Process_Status_OUT)();//这个函数其实什么也没做
#ifndef STM32F10X_CL
ControlState =STALLED; //状态变成了终止发送和接受
#endif
}
else
{
ControlState= STALLED;
}
pInformation->ControlState =ControlState;
return Post0_Process();
} |