keil_examples/USBHostLite/UsbHost/Host/usbhost_lpc17xx.c
/*
**************************************************************************************************************
*                                       ENUMERATE THE DEVICE
*
* Description: This function is used to enumerate the device connected
*
* Arguments  : None
*
* Returns    : None
*
**************************************************************************************************************
*/
ENUMERATE THE DEVICE
Description: This function is used to enumerate the device connected

Arguments  : None

Returns    : None
ENUMERATE THE DEVICE Description : This function is used to enumerate the device connected Arguments : None Returns : None
int32_t  Host_EnumDev (void)
{
    int32_t  rc;
    PRINT_Log("Connect a Mass Storage device\n");
    while (!HOST_RhscIntr);
    Host_DelayMS(100);                             
	if ( HOST_RhscIntr & 0x01 )
	{
	  LPC_USB->RhPortStatus1 = OR_RH_PORT_PRS; 
	  while (LPC_USB->RhPortStatus1 & OR_RH_PORT_PRS)
		; 
	  LPC_USB->RhPortStatus1 = OR_RH_PORT_PRSC; 
	}
	if ( HOST_RhscIntr & 0x02 )
	{
	  LPC_USB->RhPortStatus2 = OR_RH_PORT_PRS; 
	  while (LPC_USB->RhPortStatus2 & OR_RH_PORT_PRS)
		; 
	  LPC_USB->RhPortStatus2 = OR_RH_PORT_PRSC; 
	}
    Host_DelayMS(200);                                                 
    EDCtrl->Control = 8 << 16;                                         
    rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 8);
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }
    EDCtrl->Control = TDBuffer[7] << 16;                               
    rc = HOST_SET_ADDRESS(1);                                          
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }
    Host_DelayMS(2);
    EDCtrl->Control = (EDCtrl->Control) | 1;                          
    rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9);
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }
    rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2]));
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }
    rc = MS_ParseConfiguration();                                      
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }
    rc = USBH_SET_CONFIGURATION(1);                                    
    if (rc != OK) {
        PRINT_Err(rc);
    }
    Host_DelayMS(100);                                               
    return (rc);
}
int32_t Host_EnumDev ( void ) { int32_t rc ; PRINT_Log ( " \n " ) ; while ( ! HOST_RhscIntr ) ; Host_DelayMS ( 100 ) ; if ( HOST_RhscIntr & 0x01 ) { LPC_USB -> RhPortStatus1 = OR_RH_PORT_PRS ; while ( LPC_USB -> RhPortStatus1 & OR_RH_PORT_PRS ) ; LPC_USB -> RhPortStatus1 = OR_RH_PORT_PRSC ; } if ( HOST_RhscIntr & 0x02 ) { LPC_USB -> RhPortStatus2 = OR_RH_PORT_PRS ; while ( LPC_USB -> RhPortStatus2 & OR_RH_PORT_PRS ) ; LPC_USB -> RhPortStatus2 = OR_RH_PORT_PRSC ; } Host_DelayMS ( 200 ) ; EDCtrl -> Control = 8 << 16 ; rc = HOST_GET_DESCRIPTOR ( USB_DESCRIPTOR_TYPE_DEVICE , 0 , TDBuffer , 8 ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; return ( rc ) ; } EDCtrl -> Control = TDBuffer [ 7 ] << 16 ; rc = HOST_SET_ADDRESS ( 1 ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; return ( rc ) ; } Host_DelayMS ( 2 ) ; EDCtrl -> Control = ( EDCtrl -> Control ) | 1 ; rc = HOST_GET_DESCRIPTOR ( USB_DESCRIPTOR_TYPE_CONFIGURATION , 0 , TDBuffer , 9 ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; return ( rc ) ; } rc = HOST_GET_DESCRIPTOR ( USB_DESCRIPTOR_TYPE_CONFIGURATION , 0 , TDBuffer , ReadLE16U ( & TDBuffer [ 2 ] ) ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; return ( rc ) ; } rc = MS_ParseConfiguration ( ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; return ( rc ) ; } rc = USBH_SET_CONFIGURATION ( 1 ) ; if ( rc != OK ) { PRINT_Err ( rc ) ; } Host_DelayMS ( 100 ) ; return ( rc ) ; }
ENUMERATE THE DEVICE
Description: This function is used to enumerate the device connected
ENUMERATE THE DEVICE Description : This function is used to enumerate the device connected
/* USB 2.0 spec says atleast 50ms delay beore port reset */ // Initiate port reset // Wait for port reset to complete... // ...and clear port reset signal // Initiate port reset // Wait for port reset to complete... // ...and clear port reset signal /* Wait for 100 MS after port reset  */ /* Put max pkt size = 8              */ /* Read first 8 bytes of device desc */ /* Get max pkt size of endpoint 0    */ /* Set the device address to 1       */ /* Modify control pipe with address 1 */ /* Get the configuration descriptor   */ /* Get the first configuration data  */ /* Parse the configuration           */ /* Select device configuration 1     */ /* Some devices may require this delay */