コード例 #1
0
ファイル: usb_core.c プロジェクト: 9zigen/stm32
/*******************************************************************************
* 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;
			vSetEPTxStatus(EP_TX_STALL);
		}
		goto Expect_Status_Out;  // FIXME: <--- ZOMG TEH 'GOTO' !!!!
	}
	Length = pEPinfo->PacketSize;
	ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
	if (Length > save_wLength) Length = save_wLength;
	DataBuffer = (*pEPinfo->CopyData)(Length);
	UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
	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:    // FIXME: <--- ZOMG TEH LABEL !!!!
		pInformation->ControlState = ControlState;
}
コード例 #2
0
ファイル: usb_core.c プロジェクト: Rajesh-Sec-Project/simon
/*******************************************************************************
* Function Name  : Post0_Process
* Description    : Stall the Endpoint 0 in case of error.
* Input          : None.
* Output         : None.
* Return         : - 0 if the control State is in PAUSE
*                  - 1 if not.
*******************************************************************************/
uint8_t Post0_Process(void) {
#ifdef STM32F10X_CL
    USB_OTG_EP* ep;
#endif /* STM32F10X_CL */

    SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);

    if(pInformation->ControlState == STALLED) {
        vSetEPRxStatus(EP_RX_STALL);
        vSetEPTxStatus(EP_TX_STALL);
    }

#ifdef STM32F10X_CL
    else if((pInformation->ControlState == OUT_DATA) || (pInformation->ControlState == WAIT_STATUS_OUT)) {
        ep = PCD_GetInEP(0);
        ep->is_in = 0;
        OTGD_FS_EP0StartXfer(ep);

        vSetEPTxStatus(EP_TX_VALID);
    }

    else if((pInformation->ControlState == IN_DATA) || (pInformation->ControlState == WAIT_STATUS_IN)) {
        ep = PCD_GetInEP(0);
        ep->is_in = 1;
        OTGD_FS_EP0StartXfer(ep);
    }
#endif /* STM32F10X_CL */

    return (pInformation->ControlState == PAUSE);
}
コード例 #3
0
ファイル: usb_core.c プロジェクト: Rajesh-Sec-Project/simon
/*******************************************************************************
* 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;
}
コード例 #4
0
ファイル: usb_core.c プロジェクト: Blue-Design/CNC-STM32
/*******************************************************************************
* 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;
	u32 save_wLength = pEPinfo->Usb_wLength;
	u32 ControlState = pInformation->ControlState;

	u8 *DataBuffer;
	u32 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;
			vSetEPTxStatus(EP_TX_STALL);
		}

		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);

	UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);

	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;
}
コード例 #5
0
ファイル: usb_core.c プロジェクト: 9zigen/stm32
/*******************************************************************************
* 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;
		PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
	}
	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();
		}
	}
}
コード例 #6
0
ファイル: usb_core.c プロジェクト: 9zigen/stm32
/*******************************************************************************
* Function Name  : Post0_Process
* Description    : Stall the Endpoint 0 in case of error.
* Input          : None.
* Output         : None.
* Return         : - 0 if the control State is in PAUSE
*                  - 1 if not.
*******************************************************************************/
uint8_t Post0_Process(void) {
	SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
	if (pInformation->ControlState == STALLED) {
		vSetEPRxStatus(EP_RX_STALL);
		vSetEPTxStatus(EP_TX_STALL);
	}

	return (pInformation->ControlState == PAUSE);
}
コード例 #7
0
ファイル: usb_core.c プロジェクト: 01iv3r/OpenPilot
/*******************************************************************************
* 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->CopyDataOut && save_rLength)
  {
    uint8_t *Buffer;
    uint32_t Length;

    Length = pEPinfo->PacketSize;
    if (Length > save_rLength)
    {
      Length = save_rLength;
    }

    Buffer = (*pEPinfo->CopyDataOut)(Length);
    pEPinfo->Usb_rLength -= Length;
    pEPinfo->Usb_rOffset += Length;

  #ifdef STM32F10X_CL  
    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();
    }
  }
}