示例#1
0
/*******************************************************************************
  MASS_Reset: Mass Storage reset routine.
*******************************************************************************/
void MASS_Reset()
{
  Device_Info.Current_Configuration = 0; // Set the device as not configured
  pInformation->Current_Feature = MASS_ConfigDescriptor[7]; // Current Feature initialization
  SetBTABLE(BTABLE_ADDRESS);
  // Initialize Endpoint 0
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);
  //Initialize Endpoint 1
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);
  // Initialize Endpoint 2
  SetEPType(ENDP2, EP_BULK);
  SetEPRxAddr(ENDP2, ENDP2_RXADDR);
  SetEPRxCount(ENDP2, Device_Property.MaxPacketSize);
  SetEPRxStatus(ENDP2, EP_RX_VALID);
  SetEPTxStatus(ENDP2, EP_TX_DIS);

  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);
  // Set the device to response on default address
  SetDeviceAddress(0);

  bDeviceState = ATTACHED;

  CBW.dSignature = BOT_CBW_SIGNATURE;
  Bot_State = BOT_IDLE;
}
示例#2
0
/*******************************************************************************
* Function Name  : HID_Reset.
* Description    : HID reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void HID_Reset(void)
{
  /* Set HID_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/

  /* Current Feature initialization */
  pInformation->Current_Feature = RHID_ConfigDescriptor[7];
  SetBTABLE(BTABLE_ADDRESS);
  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  SetEPTxCount(ENDP1, EP1TxCount);
  SetEPRxCount(ENDP1, EP1RxCount);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);

  /* Set this device to response on default address */
  SetDeviceAddress(0);
  bDeviceState = ATTACHED;
}
示例#3
0
文件: usb_prop.c 项目: x893/OpenBLT
/************************************************************************************//**
** \brief     USB device reset routine.
** \return    none.
**
****************************************************************************************/
void Bulk_Reset(void)
{
  /* set device as not configured */
  pInformation->Current_Configuration = 0;
  /* current feature initialization */
  pInformation->Current_Feature = Bulk_ConfigDescriptor[7];
  /* set device's the default Interface*/
  pInformation->Current_Interface = 0;
  /* set based address in USB RAM */
  SetBTABLE(BTABLE_ADDRESS);
  /* initialize endpoint 0 CONTROL (mandatory) */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);
  /* initialize endpoint 1 IN + OUT */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  SetEPTxCount(ENDP1, BULK_DATA_SIZE);
  SetEPRxCount(ENDP1, BULK_DATA_SIZE);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  /* set this device to respond on default address */
  SetDeviceAddress(0);
  /* update device state */
  bDeviceState = ATTACHED;
} /*** end of Bulk_Reset ***/
示例#4
0
/*******************************************************************************
* Function Name  : Virtual_Com_Port_Reset
* Description    : Virtual_Com_Port Mouse reset routine
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Virtual_Com_Port_Reset(void)
{
  /* Set Virtual_Com_Port DEVICE as not configured */
  pInformation->Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];

  /* Set Virtual_Com_Port DEVICE with the default Interface*/
  pInformation->Current_Interface = 0;

#ifdef STM32F10X_CL
  /* EP0 is already configured by USB_SIL_Init() function */

  /* Init EP1 IN as Bulk endpoint */
  OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, VIRTUAL_COM_PORT_DATA_SIZE);

  /* Init EP2 IN as Interrupt endpoint */
  OTG_DEV_EP_Init(EP2_IN, OTG_DEV_EP_TYPE_INT, VIRTUAL_COM_PORT_INT_SIZE);

  /* Init EP3 OUT as Bulk endpoint */
  OTG_DEV_EP_Init(EP3_OUT, OTG_DEV_EP_TYPE_BULK, VIRTUAL_COM_PORT_DATA_SIZE);
#else

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);

  /* Initialize Endpoint 2 */
  SetEPType(ENDP2, EP_INTERRUPT);
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
  SetEPRxStatus(ENDP2, EP_RX_DIS);
  SetEPTxStatus(ENDP2, EP_TX_NAK);

  /* Initialize Endpoint 3 */
  SetEPType(ENDP3, EP_BULK);
  SetEPRxAddr(ENDP3, ENDP3_RXADDR);
  SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
  SetEPRxStatus(ENDP3, EP_RX_VALID);
  SetEPTxStatus(ENDP3, EP_TX_DIS);

  /* Set this device to response on default address */
  SetDeviceAddress(0);
#endif /* STM32F10X_CL */

  bDeviceState = ATTACHED;
}
示例#5
0
/*******************************************************************************
* Function Name  : MASS_Reset
* Description    : Mass Storage reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void MASS_Reset()
{
  /* Set the device as not configured */
  Device_Info.Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = MASS_ConfigDescriptor[7];

#ifdef STM32F10X_CL   
  
  /* EP0 is already configured by USB_SIL_Init() function */

  /* Init EP1 IN as Bulk endpoint */
  OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE);
  
  /* Init EP2 OUT as Bulk endpoint */
  OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); 
  
#else 

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);

  /* Initialize Endpoint 2 */
  SetEPType(ENDP2, EP_BULK);
  SetEPRxAddr(ENDP2, ENDP2_RXADDR);
  SetEPRxCount(ENDP2, Device_Property.MaxPacketSize);
  SetEPRxStatus(ENDP2, EP_RX_VALID);
  SetEPTxStatus(ENDP2, EP_TX_DIS);


  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Set the device to response on default address */
  SetDeviceAddress(0);
#endif /* STM32F10X_CL */

  bDeviceState = ATTACHED;

  CBW.dSignature = BOT_CBW_SIGNATURE;
  Bot_State = BOT_IDLE;

  //USB_NotConfigured_LED();
}
示例#6
0
// Ресет USB
void SomeDev_Reset()
{
	// Установка девайса в несконфигурированное состояние
	Device_Info.Current_Configuration = 0;
	
	// Инициализация CurrentFeature
	pInformation->Current_Feature = SomeDev_ConfigDescriptor[7];
	
#ifdef STM32F10X_CL   
	
	// EP0 уже сконфигурирован в USB_SIL_Init()
	
	// $USBCONFIG - инициализация ендпойнтов
	
	// EP1 IN - Bulk endpoint 
	OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE);
	
	// EP2 OUT - Bulk endpoint 
	OTG_DEV_EP_Init(EP2_OUT, OTG_DEV_EP_TYPE_BULK, BULK_MAX_PACKET_SIZE); 
	
	
#else 
	
	// $USBCONFIG - инициализация ендпойнтов
	
	SetBTABLE(BTABLE_ADDRESS);
	
	// Инициализация Endpoint 0
	SetEPType(ENDP0, EP_CONTROL);
	SetEPTxStatus(ENDP0, EP_TX_NAK);
	SetEPRxAddr(ENDP0, ENDP0_RXADDR);
	SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
	SetEPTxAddr(ENDP0, ENDP0_TXADDR);
	Clear_Status_Out(ENDP0);
	SetEPRxValid(ENDP0);
	
	// Инициализация Endpoint 1
	SetEPType(ENDP1, EP_BULK);
	SetEPTxAddr(ENDP1, ENDP1_TXADDR);
	SetEPTxStatus(ENDP1, EP_TX_NAK);
	SetEPRxStatus(ENDP1, EP_RX_DIS);
	
	// Инициализация Endpoint 2
	SetEPType(ENDP2, EP_BULK);
	SetEPRxAddr(ENDP2, ENDP2_RXADDR);
	SetEPRxCount(ENDP2, Device_Property.MaxPacketSize);
	SetEPRxStatus(ENDP2, EP_RX_VALID);
	SetEPTxStatus(ENDP2, EP_TX_DIS);
	
	
	SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
	SetEPRxValid(ENDP0);
	
	// Установка дефолтного адреса
	SetDeviceAddress(0);
#endif /}
	
	bDeviceState = ATTACHED;
}
示例#7
0
void usbReset(void) {
    pInformation->Current_Configuration = 0;

    /* current feature is current bmAttributes */
    pInformation->Current_Feature = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELF_POWERED);

    _SetBTABLE(USB_BTABLE_ADDRESS);

    /* setup control endpoint 0 */
    _SetEPType(ENDP0, EP_CONTROL);
    _SetEPTxStatus(ENDP0, EP_TX_STALL);
    _SetEPRxAddr(ENDP0,VCOM_CTRL_RX_ADDR);
    _SetEPTxAddr(ENDP0,VCOM_CTRL_TX_ADDR);
    Clear_Status_Out(ENDP0);

    SetEPRxCount(ENDP0, pProperty->MaxPacketSize);
    SetEPRxValid(ENDP0);

    /* setup management endpoint 1  */
    SetEPType     (VCOM_NOTIFICATION_ENDP,     EP_INTERRUPT);
    SetEPTxAddr   (VCOM_NOTIFICATION_ENDP,     VCOM_NOTIFICATION_ADDR);
    SetEPTxStatus (VCOM_NOTIFICATION_ENDP,     EP_TX_NAK);
    SetEPRxStatus (VCOM_NOTIFICATION_ENDP,     EP_RX_DIS);

    /* setup data endpoint OUT (rx) */
    /*   SetEPType     (VCOM_RX_ENDP, EP_BULK); */
    /*   SetEPRxAddr   (VCOM_RX_ENDP, VCOM_RX_ADDR); */
    /*   SetEPRxCount  (VCOM_RX_ENDP, VCOM_RX_EPSIZE); */
    /*   // SetEPTxStatus (VCOM_RX_ENDP, EP_TX_DIS); */
    /*   SetEPRxStatus (VCOM_RX_ENDP, EP_RX_VALID); */

    SetEPType     (3, EP_BULK);
    SetEPRxAddr   (3, 0x110);
    SetEPRxCount  (3,64);
    // SetEPTxStatus (VCOM_RX_ENDP, EP_TX_DIS);
    SetEPRxStatus (3, EP_RX_VALID);

    /* setup data endpoint IN (tx)  */
    SetEPType     (VCOM_TX_ENDP, EP_BULK);
    SetEPTxAddr   (VCOM_TX_ENDP, VCOM_TX_ADDR);
    SetEPTxStatus (VCOM_TX_ENDP, EP_TX_NAK);
    SetEPRxStatus (VCOM_TX_ENDP, EP_RX_DIS);

    bDeviceState = ATTACHED;
    SetDeviceAddress(0);

    /* reset the rx fifo */
    recvBufIn   = 0;
    recvBufOut  = 0;
    maxNewBytes = VCOM_RX_EPSIZE;
    countTx     = 0;
}
示例#8
0
/*******************************************************************************
* Function Name  : DFU_Reset
* Description    :
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void DFU_Reset(void)
{
	/* Set DFU_DEVICE as not configured */
	Device_Info.Current_Configuration = 0;

	_SetBTABLE(BTABLE_ADDRESS);

	/* Initialize Endpoint 0 */
	_SetEPType(ENDP0, EP_CONTROL);
	_SetEPTxStatus(ENDP0, EP_TX_NAK);
	_SetEPRxAddr(ENDP0, ENDP0_RXADDR);
	SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
	_SetEPTxAddr(ENDP0, ENDP0_TXADDR);
	SetEPTxCount(ENDP0, Device_Property.MaxPacketSize);
	Clear_Status_Out(ENDP0);
	SetEPRxValid(ENDP0);
	
	/* Set this device to response on default address */
	SetDeviceAddress(0);

       /* if(!DFU_Button_Read())
	{
		DeviceState=STATE_dfuIDLE;
		DeviceStatus[4]=DeviceState;
		DeviceStatus[1]=0;
        	DeviceStatus[2]=0;
        	DeviceStatus[3]=0;
	}*/

} /* DFU_Reset() */
示例#9
0
vsf_err_t stm32_usbd_ep_set_OUT_epsize(uint8_t idx, uint16_t epsize)
{
	bool ep0;
	int8_t index;
	
	index = stm32_usbd_get_ep(idx);
	if (index < 0)
	{
		return VSFERR_FAIL;
	}
	ep0 = 0 == idx;
	idx = (uint8_t)index;
	
	if ((EP_Cfg_Ptr - epsize) < STM32_USBD_EP_NUM * 8)
	{
		return VSFERR_NOT_ENOUGH_RESOURCES;
	}
	
	stm32_usbd_OUT_epsize[idx] = epsize;
	SetEPRxCount(idx, epsize);
	// fix for 16-bit aligned memory
	EP_Cfg_Ptr -= epsize & 1 ? epsize + 1 : epsize;
	SetEPRxAddr(idx, EP_Cfg_Ptr);
	if (ep0)
	{
		SetEPRxStatus(idx, EP_RX_VALID);
	}
	else
	{
		SetEPRxStatus(idx, EP_RX_NAK);
	}
	return VSFERR_NONE;
}
示例#10
0
/*******************************************************************************
* Function Name  : DFU_Reset.
* Description    : DFU reset routine
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DFU_Reset(void)
{
  /* Set DFU_DEVICE as not configured */
  Device_Info.Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = DFU_ConfigDescriptor[7];

#ifdef STM32F10X_CL
  /* EP0 is already configured in DFU_Init by OTG_DEV_Init() function
      No Other endpoints needed for this firmware */
#else
  _SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  _SetEPType(ENDP0, EP_CONTROL);
  _SetEPTxStatus(ENDP0, EP_TX_NAK);
  _SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  _SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  SetEPTxCount(ENDP0, Device_Property.MaxPacketSize);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Set this device to response on default address */
  SetDeviceAddress(0);
#endif /* STM32F10X_CL */

  /* Set the new control state of the device to Attached */
  bDeviceState = ATTACHED;
}
示例#11
0
/*******************************************************************************
* 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);
}
示例#12
0
/*******************************************************************************
* Function Name  : Joystick_Reset.
* Description    : Joystick Mouse reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Joystick_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/
  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxCount(ENDP1, 4);
  SetEPRxStatus(ENDP1, EP_RX_DIS);
  SetEPTxStatus(ENDP1, EP_TX_NAK);

  /* Set this device to response on default address */
  SetDeviceAddress(0);
}
示例#13
0
/*******************************************************************************
* Function Name  : DFU_Reset.
* Description    : DFU reset routine
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DFU_Reset(void)
{
  /* Set DFU_DEVICE as not configured */
  Device_Info.Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = DFU_ConfigDescriptor[7];

  _SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  _SetEPType(ENDP0, EP_CONTROL);
  _SetEPTxStatus(ENDP0, EP_TX_NAK);
  _SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  _SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  SetEPTxCount(ENDP0, Device_Property.MaxPacketSize);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Set this device to response on default address */
  SetDeviceAddress(0);

  /* Set the new control state of the device to Attached */
  bDeviceState = ATTACHED;
}
示例#14
0
文件: usb_prop.c 项目: flipback/arm
/*******************************************************************************
* Function Name  : Virtual_Com_Port_Reset
* Description    : Virtual_Com_Port Mouse reset routine
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Virtual_Com_Port_Reset(void)
{
  /* Set Virtual_Com_Port DEVICE as not configured */
  pInformation->Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];

  /* Set Virtual_Com_Port DEVICE with the default Interface*/
  pInformation->Current_Interface = 0;


  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);

  /* Initialize Endpoint 2 */
  SetEPType(ENDP2, EP_INTERRUPT);
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
  SetEPRxStatus(ENDP2, EP_RX_DIS);
  SetEPTxStatus(ENDP2, EP_TX_NAK);

  /* Initialize Endpoint 3 */
  SetEPType(ENDP3, EP_BULK);
  SetEPRxAddr(ENDP3, ENDP3_RXADDR);
  SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
  SetEPRxStatus(ENDP3, EP_RX_VALID);
  SetEPTxStatus(ENDP3, EP_TX_DIS);

  /* Set this device to response on default address */
  SetDeviceAddress(0);

  bDeviceState = ATTACHED;
}
示例#15
0
文件: usb_prop.c 项目: 9zigen/stm32
/*******************************************************************************
    Function Name  : USBdev_Reset.
    Description    : USB device reset routine.
    Input          : None.
    Output         : None.
    Return         : None.
*******************************************************************************/
void USBdev_Reset() {
	// Set DEVICE as not configured
	pInformation->Current_Configuration = 0;

	// Current Feature initialization
	pInformation->Current_Feature = VCOM_ConfigDescriptor[7];

	// Set DEVICE with the default Interface
	pInformation->Current_Interface = 0;

	// BTABLE_ADDRESS = 0
	USB->BTABLE = BTABLE_ADDRESS;

	// Initialize Endpoint 0
	SetEPType(ENDP0,EP_CONTROL);
	SetEPTxStatus(ENDP0,EP_TX_STALL);
	SetEPRxAddr(ENDP0,ENDP0_RXADDR);
	SetEPTxAddr(ENDP0,ENDP0_TXADDR);
	Clear_Status_Out(ENDP0);
	SetEPRxCount(ENDP0,Device_Property.MaxPacketSize);
	SetEPRxValid(ENDP0);

	// Initialize Endpoint 1
	SetEPType(ENDP1,EP_BULK);
	SetEPTxAddr(ENDP1,ENDP1_TXADDR);
	SetEPTxStatus(ENDP1,EP_TX_NAK);
	SetEPRxStatus(ENDP1,EP_RX_DIS);

	// Initialize Endpoint 2
	SetEPType(ENDP2,EP_INTERRUPT);
	SetEPTxAddr(ENDP2,ENDP2_TXADDR);
	SetEPRxStatus(ENDP2,EP_RX_DIS);
	SetEPTxStatus(ENDP2,EP_TX_NAK);

	// Initialize Endpoint 3
	SetEPType(ENDP3,EP_BULK);
	SetEPRxAddr(ENDP3,ENDP3_RXADDR);
	SetEPRxCount(ENDP3,VCOM_INT_SIZE);
	SetEPRxStatus(ENDP3,EP_RX_VALID);
	SetEPTxStatus(ENDP3,EP_TX_DIS);

	// Set this device to response on default address
	SetDeviceAddress(0);

	bDeviceState = ATTACHED;
}
示例#16
0
void Device_Reset(void) {
  /* Set the device as not configured */
  pInformation->Current_Configuration = 0;

  /* Current feature initialization */
  pInformation->Current_Feature = ConfigDescriptor[7];

  /* Set the device with the default Interface*/
  pInformation->Current_Interface = 0;

  SetBTABLE(0x00);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);

  /* Initialize Endpoint 2 */
  SetEPType(ENDP2, EP_INTERRUPT);
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
  SetEPRxStatus(ENDP2, EP_RX_DIS);
  SetEPTxStatus(ENDP2, EP_TX_NAK);

  /* Initialize Endpoint 3 */
  SetEPType(ENDP3, EP_BULK);
  SetEPRxAddr(ENDP3, ENDP3_RXADDR);
  SetEPRxCount(ENDP3, VCP_DATA_SIZE);
  SetEPRxStatus(ENDP3, EP_RX_VALID);
  SetEPTxStatus(ENDP3, EP_TX_DIS);

  /* Set this device to response on default address */
  SetDeviceAddress(0);

  /* Device attached */
  led_off();
}
示例#17
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);
}
示例#18
0
文件: usb_core.c 项目: 9zigen/stm32
/*******************************************************************************
* Function Name  : Standard_ClearFeature.
* Description    : Clear or disable a specific feature.
* Input          : None.
* Output         : None.
* Return         : - Return USB_SUCCESS, if the request is performed.
*                  - Return USB_UNSUPPORT, if the request is invalid.
*******************************************************************************/
RESULT Standard_ClearFeature(void) {
	uint32_t Type_Rec = Type_Recipient;
	uint32_t Status;

	if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {
		// Device Clear Feature
		ClrBit(pInformation->Current_Feature, 5);
		return USB_SUCCESS;
	} else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {
		// EndPoint Clear Feature
		DEVICE* pDev;
		uint32_t Related_Endpoint;
		uint32_t wIndex0;
		uint32_t rEP;

		if ((pInformation->USBwValue != ENDPOINT_STALL) || (pInformation->USBwIndex1 != 0)) {
			return USB_UNSUPPORT;
		}
		pDev = &Device_Table;
		wIndex0 = pInformation->USBwIndex0;
		rEP = wIndex0 & ~0x80;
		Related_Endpoint = ENDP0 + rEP;
		if (ValBit(pInformation->USBwIndex0, 7)) {
			// Get Status of endpoint & stall the request if the related_ENdpoint is Disabled
			Status = GetEPTxStatus(Related_Endpoint);
		} else {
			Status = GetEPRxStatus(Related_Endpoint);
		}
		if ((rEP >= pDev->Total_Endpoint) || (Status == 0) || (pInformation->Current_Configuration == 0)) {
			return USB_UNSUPPORT;
		}
		if (wIndex0 & 0x80) {
			// IN endpoint
			if (GetTxStallStatus(Related_Endpoint )) {
				ClearDTOG_TX(Related_Endpoint);
				SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
			}
		} else {
			// OUT endpoint
			if (GetRxStallStatus(Related_Endpoint)) {
				if (Related_Endpoint == ENDP0) {
					// After clear the STALL, enable the default endpoint receiver
					SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
					SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
				} else {
					ClearDTOG_RX(Related_Endpoint);
					SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
				}
			}
		}
		pUser_Standard_Requests->User_ClearFeature();

		return USB_SUCCESS;
	}

	return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name  : PIOS_HID_Reset.
* Description    : Custom HID reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void PIOS_HID_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/
  
  /* Current Feature initialization */
  pInformation->Current_Feature = PIOS_HID_ConfigDescriptor[7];
  
#ifdef STM32F10X_CL   
  /* EP0 is already configured in DFU_Init() by USB_SIL_Init() function */
  
  /* Init EP1 IN as Interrupt endpoint */
  OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_INT, 2);
  
  /* Init EP1 OUT as Interrupt endpoint */
  OTG_DEV_EP_Init(EP1_OUT, OTG_DEV_EP_TYPE_INT, 2);
#else 
  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  SetEPTxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH+2);  /* add two for indicating report id and valid data length */
  SetEPRxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH+2);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);

  /* Set this device to response on default address */
  SetDeviceAddress(0);
#endif /* STM32F10X_CL */

  bDeviceState = ATTACHED;
}
示例#20
0
/*******************************************************************************
* Function Name  : CustomHID_Reset.
* Description    : Custom HID reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void CustomHID_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/
  
  /* Current Feature initialization */
  pInformation->Current_Feature = CustomHID_ConfigDescriptor[7];
  
  *(volatile unsigned *)(0x40005C50L)=(0x00&0xFFF8);//设置USB分组缓冲区描述表起始地址:0

  /* Initialize Endpoint 0 */
  //设置EP0控制端点	 ENDP0   ((u8)0)   EP_CONTROL     (0x0200)
  *(((volatile unsigned *)(0x40005C00L)) + ENDP0)=((_GetENDPOINT(ENDP0) & 0x898f) | EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);	  //设置EP0端点发送延迟
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);		  //设置EP0的接受地址  ENDP0_RXADDR        (0x18)
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);		  //设置EP0的发送地址  ENDP0_TXADDR        (0x58)
  _ClearEP_KIND(ENDP0);					  //设置端点EP0的类型DBL_BUF 双缓冲端点
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);	//设置EP0的计数器的值
  _SetEPRxStatus(ENDP0, EP_RX_VALID);					  //设置端点接受有效 EP_RX_VALID=0x3000

  /* Initialize Endpoint 1 */
     SetEPType(ENDP1, EP_INTERRUPT);
     SetEPRxAddr(ENDP1, ENDP1_RXADDR);	//ADDR内部寄存器被用作当前缓冲区的指针 ENDP1_RXADDR=(0x98)
     SetEPRxCount(ENDP1, 22);			//COUNT寄存器用于记录剩下未传输的字节数
     SetEPRxStatus(ENDP1, EP_RX_VALID);	//设置端点接受有效 EP_RX_VALID=0x3000

  /* Initialize Endpoint 2 */
     SetEPType(ENDP2, EP_INTERRUPT);
     SetEPTxAddr(ENDP2, ENDP2_TXADDR);
     SetEPTxCount(ENDP2, 22);
     SetEPTxStatus(ENDP2, EP_TX_NAK);//设置端点发送不应答 EP_TX_NAK=(0x0020)

  bDeviceState = ATTACHED;	//ATTACHED=1
  
  /* Set this device to response on default address */
  SetDeviceAddress(0);
}
示例#21
0
/*******************************************************************************
* Function Name  : MASS_Reset
* Description    : Mass Storage reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void MASS_Reset()
{
  /* Set the device as not configured */
  Device_Info.Current_Configuration = 0;

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_BULK);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPTxStatus(ENDP1, EP_TX_NAK);
  SetEPRxStatus(ENDP1, EP_RX_DIS);

  /* Initialize Endpoint 2 */
  SetEPType(ENDP2, EP_BULK);
  SetEPRxAddr(ENDP2, ENDP2_RXADDR);
  SetEPRxCount(ENDP2, Device_Property.MaxPacketSize);
  SetEPRxStatus(ENDP2, EP_RX_VALID);
  SetEPTxStatus(ENDP2, EP_TX_DIS);


  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Set the device to response on default address */
  SetDeviceAddress(0);
  CBW.dSignature = BOT_CBW_SIGNATURE;
  Bot_State = BOT_IDLE;
}
示例#22
0
/*******************************************************************************
* Function Name  : Speaker_Reset.
* Description    : Speaker reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Speaker_Reset()
{
  /* Set Speaker device as not configured state */
  pInformation->Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = Speaker_ConfigDescriptor[7];

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_ISOCHRONOUS);
  SetEPDoubleBuff(ENDP4);
  SetEPDblBuffAddr(ENDP1, ENDP1_BUF0Addr, ENDP1_BUF1Addr);
  SetEPDblBuffCount(ENDP1, EP_DBUF_IN, PACKET_SIZE);
  ClearDTOG_RX(ENDP1);
  ClearDTOG_TX(ENDP1);
  SetEPRxStatus(ENDP1, EP_RX_DIS);
  SetEPTxStatus(ENDP1, EP_TX_VALID);

  SetEPType(ENDP2, EP_INTERRUPT);
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
  SetEPTxCount(ENDP2, 0x40);
  SetEPRxStatus(ENDP2, EP_RX_DIS);
  SetEPTxStatus(ENDP2, EP_TX_NAK);
  
  SetEPType(ENDP3, EP_INTERRUPT);
  SetEPTxAddr(ENDP3, ENDP3_TXADDR);
  SetEPTxCount(ENDP3, 0x40);
  SetEPRxStatus(ENDP3, EP_RX_DIS);
  SetEPTxStatus(ENDP3, EP_TX_NAK);
  
  SetEPRxValid(ENDP0);
  /* Set this device to response on default address */
  SetDeviceAddress(0);

  bDeviceState = ATTACHED;
}
示例#23
0
/**
  * @brief DCD_EP_PrepareRx
  * @param  pdev: device instance
  * @param  ep_addr: endpoint address
  * @param  pbuf: pointer to Rx buffer
  * @param  buf_len: data length
  * @retval : status
  */
uint32_t DCD_EP_PrepareRx( USB_CORE_HANDLE *pdev,
                          uint8_t   ep_addr,
                          uint8_t *pbuf,                        
                          uint16_t  buf_len)
{
  __IO uint32_t len = 0; 
  USB_EP *ep;
  
  ep = &pdev->dev.out_ep[ep_addr & 0x7F];
  
  /*setup and start the Xfer */
  ep->xfer_buff = pbuf;  
  ep->xfer_len = buf_len;
  ep->xfer_count = 0; 
  
  /*Multi packet transfer*/
  if (ep->xfer_len > ep->maxpacket)
  {
    len=ep->maxpacket;
    ep->xfer_len-=len; 
  }
  else
  {
    len=ep->xfer_len;
    ep->xfer_len =0;
  }
  
  /* configure and validate Rx endpoint */
  if (ep->doublebuffer == 0) 
  {
    /*Set RX buffer count*/
    SetEPRxCount(ep->num, len);
  }
  else
  {
    /*Set the Double buffer counter*/
    SetEPDblBuffCount(ep->num, ep->is_in, len);
  } 
  
  SetEPRxStatus(ep->num, EP_RX_VALID);
  
  return USB_OK;
}
示例#24
0
void monkey_ep_reset(void) {
  int i;

  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/

  /* Current Feature initialization */
  pInformation->Current_Feature = config1_descriptor[7];

  for(i=0; i<8; ++i) {
    if(ep_conf_list[i].direct==0) continue;
    
		switch(ep_conf_list[i].attr) {
			case 0x00:
        SetEPType(i, EP_BULK);
        ClearEPDoubleBuff(i);
        break;
			case 0x01:
        SetEPType(i, EP_CONTROL);
        Clear_Status_Out(i);
        break;
			case 0x02:
        SetEPType(i, EP_ISOCHRONOUS);
        break;
			case 0x03:
        SetEPType(i, EP_INTERRUPT);
        break;
		}

    if(ep_conf_list[i].direct & EP_IN) {
      SetEPTxStatus(i, ep_conf_list[i].tx_status);
      SetEPTxAddr(i, ep_conf_list[i].tx_addr);
      SetEPTxCount(i, ep_conf_list[i].tx_max);
    }
    if(ep_conf_list[i].direct & EP_OUT) {
      SetEPRxAddr(i, ep_conf_list[i].rx_addr);
      SetEPRxCount(i, ep_conf_list[i].rx_max);
      SetEPRxStatus(i, ep_conf_list[i].rx_status);
    }
	}
}
示例#25
0
文件: usb.c 项目: iperry/libmaple
/* copies len bytes from the local recieve FIFO (not
   usb packet buffer) into recvBuf and deq's the fifo.
   will only copy the minimum of len or the available
   bytes. returns the number of bytes copied */
uint32 usbReceiveBytes(uint8* recvBuf, uint32 len) {
  if (len > newBytes) {
      len = newBytes;
  }

  int i;
  for (i=0;i<len;i++) {
    recvBuf[i] = (uint8)(vcomBufferRx[i]);
  }

  newBytes -= len;

  /* re-enable the rx endpoint which we had set to receive 0 bytes */
  if (newBytes == 0) {
    SetEPRxCount(VCOM_RX_ENDP,VCOM_RX_EPSIZE);
    SetEPRxStatus(VCOM_RX_ENDP,EP_RX_VALID);
  }

  return len;
}
示例#26
0
文件: usb.c 项目: adamfeuer/libmaple
/* copies len bytes from the local recieve FIFO (not
   usb packet buffer) into recvBuf and deq's the fifo.
   will only copy the minimum of len or the available
   bytes. returns the number of bytes copied */
uint8 usbReceiveBytes(uint8* recvBuf, uint8 len) {
    if (len > VCOM_RX_EPSIZE - maxNewBytes) {
        len = VCOM_RX_EPSIZE - maxNewBytes;
    }

    int i;
    for (i=0; i<len; i++) {
        recvBuf[i] = (uint8)(vcomBufferRx[recvBufOut]);
        recvBufOut = (recvBufOut + 1) % VCOM_RX_EPSIZE;
    }

    maxNewBytes += len;

    /* re-enable the rx endpoint which we had set to receive 0 bytes */
    if (maxNewBytes - len == 0) {
        SetEPRxCount(VCOM_RX_ENDP,maxNewBytes);
    }

    return len;
}
示例#27
0
文件: usb_prop.c 项目: kitnic/marmote
/*******************************************************************************
* Function Name  : Microphone_Reset.
* Description    : Microphone reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Microphone_Reset()
{
  /* Set Microphone device as not configured state */
  pInformation->Current_Configuration = 0;

  /* Current Feature initialization */
  pInformation->Current_Feature = Microphone_ConfigDescriptor[7];

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_NAK);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_ISOCHRONOUS);
  SetEPDblBuffAddr(ENDP1, ENDP1_BUF0Addr, ENDP1_BUF1Addr);
  //SetEPDblBuffCount(ENDP1, EP_DBUF_IN, 0x40);
  SetEPDblBuffCount(ENDP1, EP_DBUF_IN, 0x60);
  ClearDTOG_RX(ENDP1);
  ClearDTOG_TX(ENDP1);
  ToggleDTOG_TX(ENDP1);
  SetEPRxStatus(ENDP1, EP_RX_DIS);
  SetEPTxStatus(ENDP1, EP_TX_VALID);

  SetEPRxValid(ENDP0);
  /* Set this device to response on default address */
  SetDeviceAddress(0);

  bDeviceState = ATTACHED;

  //In_Data_Offset = 0;
  //Out_Data_Offset = 0;
}
示例#28
0
文件: usb_prop.c 项目: 9zigen/stm32
/*******************************************************************************
    Function Name  : Speaker_Reset.
    Description    : Speaker reset routine.
    Input          : None.
    Output         : None.
    Return         : None.
*******************************************************************************/
void Speaker_Reset() {
	// Set Speaker device as not configured state
	pInformation->Current_Configuration = 0;

	// Current Feature initialization
	pInformation->Current_Feature = Speaker_ConfigDescriptor[7];

//	*BTABLE = BTABLE_ADDRESS & 0xFFF8;
	*BTABLE = BTABLE_ADDRESS; // BTABLE_ADDRESS = 0

	// Initialize Endpoint 0
	SetEPType(ENDP0,EP_CONTROL);
	SetEPTxStatus(ENDP0,EP_TX_NAK);
	SetEPRxAddr(ENDP0,ENDP0_RXADDR);
	SetEPRxCount(ENDP0,Device_Property.MaxPacketSize);
	SetEPTxAddr(ENDP0,ENDP0_TXADDR);
	Clear_Status_Out(ENDP0);
	SetEPRxValid(ENDP0);

	// Initialize Endpoint 1
	SetEPType(ENDP1,EP_ISOCHRONOUS);
	SetEPDblBuffAddr(ENDP1,ENDP1_BUF0Addr,ENDP1_BUF1Addr);
	SetEPDblBuffCount(ENDP1,EP_DBUF_OUT,0x40);
	ClearDTOG_RX(ENDP1);
	ClearDTOG_TX(ENDP1);
	ToggleDTOG_TX(ENDP1);
	SetEPRxStatus(ENDP1,EP_RX_VALID);
	SetEPTxStatus(ENDP1,EP_TX_DIS);
	SetEPRxValid(ENDP0);

	// Set this device to response on default address
	SetDeviceAddress(0);

	bDeviceState = ATTACHED;

	In_Data_Offset  = 0;
	Out_Data_Offset = 0;
}
示例#29
0
void usbReset(void) {
  dfuUpdateByReset();

  pInformation->Current_Configuration = 0;
  pInformation->Current_Feature = usbConfigDescriptorDFU.Descriptor[7];

  _SetBTABLE(BTABLE_ADDRESS);

  /* setup the ctrl endpoint */
  _SetEPType(ENDP0, EP_CONTROL);
  _SetEPTxStatus(ENDP0, EP_TX_STALL);

  _SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  _SetEPTxAddr(ENDP0, ENDP0_TXADDR);

  Clear_Status_Out(ENDP0);

  SetEPRxCount(ENDP0, pProperty->MaxPacketSize);
  //  SetEPTxCount(ENDP0, pProperty->MaxPacketSize);
  SetEPRxValid(ENDP0);

  bDeviceState = ATTACHED;
  SetDeviceAddress(0); /* different than usbSetDeviceAddr! comes from usb_core */
}
示例#30
0
/**
  * @brief Configure an EP
  * @param  pdev : Device instance
  * @param  ep_addr: endpoint address
  * @param  ep_mps: endpoint max packet size
  * @param  ep_type: endpoint Type
  */
uint32_t DCD_EP_Open(USB_CORE_HANDLE *pdev , 
                     uint16_t ep_addr,
                     uint16_t ep_mps,
                     uint8_t ep_type)
{
  
  USB_EP *ep;
  
  /* initialize ep structure*/
  if ((ep_addr & 0x80) == 0x80)
  {
    ep = &pdev->dev.in_ep[ep_addr & 0x7F];
    ep->is_in = 1;
  }
  else
  {
    ep = &pdev->dev.out_ep[ep_addr & 0x7F];
    ep->is_in = 0;
  }
  
  ep->maxpacket = ep_mps;
  ep->type = ep_type;
  ep->num   = ep_addr & 0x7F;
  
  if (ep->num == 0)
  {
    /* Initialize the control transfer variables*/ 
    ep->ctl_data_len =0;
    ep->rem_data_len = 0;
    ep->total_data_len = 0;
  }
  
  /* Initialize the transaction level variables */
  ep->xfer_buff = 0;
  ep->xfer_len = 0;
  ep->xfer_count = 0;
  ep->is_stall = 0;
  
  /* initialize HW */
  switch (ep->type)
  {
  case USB_EP_CONTROL:
    SetEPType(ep->num, EP_CONTROL);
    break;
  case USB_EP_BULK:
    SetEPType(ep->num, EP_BULK);
    break;
  case USB_EP_INT:
    SetEPType(ep->num, EP_INTERRUPT);
    break;
  case USB_EP_ISOC:
    SetEPType(ep->num, EP_ISOCHRONOUS);
    break;
  } 
  
  if (ep->doublebuffer == 0) 
  {
    if (ep->is_in)
    {
      /*Set the endpoint Transmit buffer address */
      SetEPTxAddr(ep->num, ep->pmaadress);
      ClearDTOG_TX(ep->num);
      /* Configure NAK status for the Endpoint*/
      SetEPTxStatus(ep->num, EP_TX_NAK); 
    }
    else
    {
      /*Set the endpoint Receive buffer address */
      SetEPRxAddr(ep->num, ep->pmaadress);
      /*Set the endpoint Receive buffer counter*/
      SetEPRxCount(ep->num, ep->maxpacket);
      ClearDTOG_RX(ep->num);
      /* Configure VALID status for the Endpoint*/
      SetEPRxStatus(ep->num, EP_RX_VALID);
    }
  }
  /*Double Buffer*/
  else
  {
    /*Set the endpoint as double buffered*/
    SetEPDoubleBuff(ep->num);
    /*Set buffer address for double buffered mode*/
    SetEPDblBuffAddr(ep->num,ep->pmaaddr0, ep->pmaaddr1);
    
    if (ep->is_in==0)
    {
      /* Clear the data toggle bits for the endpoint IN/OUT*/
      ClearDTOG_RX(ep->num);
      ClearDTOG_TX(ep->num);
      
      /* Reset value of the data toggle bits for the endpoint out*/
      ToggleDTOG_TX(ep->num);
      
      SetEPRxStatus(ep->num, EP_RX_VALID);
      SetEPTxStatus(ep->num, EP_TX_DIS);
    }
    else
    {
      /* Clear the data toggle bits for the endpoint IN/OUT*/
      ClearDTOG_RX(ep->num);
      ClearDTOG_TX(ep->num);
      ToggleDTOG_RX(ep->num);
      /* Configure DISABLE status for the Endpoint*/
      SetEPTxStatus(ep->num, EP_TX_DIS);
      SetEPRxStatus(ep->num, EP_RX_DIS);
    }
  } 
  return USB_OK; 
}