/******************************************************************************* * Function Name : USB_SIL_Read * Description : Write a buffer of data to a selected endpoint. * Input : - bEpAddr: The address of the non control endpoint. * - pBufferPointer: The pointer to which will be saved the * received data buffer. * Output : None. * Return : Number of received data (in Bytes). *******************************************************************************/ u32 USB_SIL_Read(u8 bEpAddr, u8* pBufferPointer) { u32 DataLength = 0; #ifndef STM32F10X_CL /* Get the number of received data on the selected Endpoint */ DataLength = GetEPRxCount(bEpAddr & 0x7F); /* Use the memory interface function to write to the selected endpoint */ PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength); #else USB_OTG_EP *ep; /* Get the structure pointer of the selected Endpoint */ ep = OTGD_FS_PCD_GetOutEP(bEpAddr); /* Get the number of received data */ DataLength = ep->xfer_len; /* Use the PCD interface layer function to read the selected endpoint */ OTGD_FS_PCD_EP_Read (bEpAddr, pBufferPointer, DataLength); #endif /* STM32F10X_CL */ /* Return the number of received data */ return DataLength; }
/******************************************************************************* * Function Name : DataStageOut. * Description : Data stage of a Control Write Transfer. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void DataStageOut(void) { ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; uint32_t save_rLength; save_rLength = pEPinfo->Usb_rLength; if (pEPinfo->CopyData && save_rLength) { uint8_t *Buffer; uint32_t Length; Length = pEPinfo->PacketSize; if (Length > save_rLength) { Length = save_rLength; } Buffer = (*pEPinfo->CopyData)(Length); pEPinfo->Usb_rLength -= Length; pEPinfo->Usb_rOffset += Length; #ifdef STM32F10X_CL OTGD_FS_PCD_EP_Read(ENDP0, Buffer, Length); #else PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length); #endif /* STM32F10X_CL */ } if (pEPinfo->Usb_rLength != 0) { vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */ SetEPTxCount(ENDP0, 0); vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */ } /* Set the next State*/ if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize) { pInformation->ControlState = OUT_DATA; } else { if (pEPinfo->Usb_rLength > 0) { pInformation->ControlState = LAST_OUT_DATA; } else if (pEPinfo->Usb_rLength == 0) { pInformation->ControlState = WAIT_STATUS_IN; USB_StatusIn(); } } }
/******************************************************************************* * Function Name : DataStageIn. * Description : Data stage of a Control Read Transfer. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void DataStageIn(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)) { if(Data_Mul_MaxPacketSize == true) { /* No more data to send and empty packet */ Send0LengthData(); ControlState = LAST_IN_DATA; Data_Mul_MaxPacketSize = false; } else { /* No more data to send so STALL the TX Status*/ ControlState = WAIT_STATUS_OUT; #ifdef STM32F10X_CL OTGD_FS_PCD_EP_Read (ENDP0, 0, 0); #endif /* STM32F10X_CL */ #ifndef STM32F10X_CL vSetEPTxStatus(EP_TX_STALL); #endif /* STM32F10X_CL */ } goto Expect_Status_Out; } Length = pEPinfo->PacketSize; ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA; if (Length > save_wLength) { Length = save_wLength; } DataBuffer = (*pEPinfo->CopyData)(Length); #ifdef STM32F10X_CL OTGD_FS_PCD_EP_Write (ENDP0, DataBuffer, Length); #else UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length); #endif /* STM32F10X_CL */ SetEPTxCount(ENDP0, Length); pEPinfo->Usb_wLength -= Length; pEPinfo->Usb_wOffset += Length; vSetEPTxStatus(EP_TX_VALID); USB_StatusOut();/* Expect the host to abort the data IN stage */ Expect_Status_Out: pInformation->ControlState = ControlState; }