示例#1
0
/*******************************************************************************
* 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
            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
    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;
}
/*******************************************************************************
* Function Name  : USB_SIL_Write
* Description    : Write a buffer of data to a selected endpoint.
* Input          : - bEpAddr: The address of the non control endpoint.
*                  - pBufferPointer: The pointer to the buffer of data to be written
*                    to the endpoint.
*                  - wBufferSize: Number of data to be written (in bytes).
* Output         : None.
* Return         : Status.
*******************************************************************************/
uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
{
#ifndef STM32F10X_CL

  /* Use the memory interface function to write to the selected endpoint */
  UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);

  /* Update the data length in the control register */
  SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
  
#else
  
   /* Use the PCD interface layer function to write to the selected endpoint */
   PCD_EP_Write (bEpAddr, pBufferPointer, wBufferSize); 
   
#endif /* STM32F10X_CL */

  return 0;
}