keil_examples/USBHostLite/UsbHost/Host/usbhost_lpc17xx.c
/*
**************************************************************************************************************
*                                         INITIALIZE THE HOST CONTROLLER
*
* Description: This function initializes lpc17xx host controller
*
* Arguments  : None
*
* Returns    : 
*
**************************************************************************************************************
*/
INITIALIZE THE HOST CONTROLLER
Description: This function initializes lpc17xx host controller

Arguments  : None

Returns    .
INITIALIZE THE HOST CONTROLLER Description : This function initializes lpc17xx host controller Arguments : None Returns .
void  Host_Init (void)
{
	uint32_t HostBaseAddr;
    LPC_SC->PCONP   |= 0x80000000;
    LPC_USB->USBClkCtrl   = 0x0000001F;  
    while ((LPC_USB->USBClkSt & 0x0000001F) != 0x1F);
	LPC_USB->StCtrl = 0x3;
	LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22));  
	LPC_PINCON->PINSEL3 |=  ((1<<4)|(2<<6) | (2<<12) | (2<<22));   
	LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28));  
	LPC_PINCON->PINSEL1 |=  ((1<<26)|(1<<28)); 	
	PRINT_Log("Initializing Host Stack\n");
	HostBaseAddr = HOST_BASE_ADDR;
    Hcca       = (volatile  HCCA       *)(HostBaseAddr+0x000);
    TDHead     = (volatile  HCTD       *)(HostBaseAddr+0x100);
    TDTail     = (volatile  HCTD       *)(HostBaseAddr+0x110);
    EDCtrl     = (volatile  HCED       *)(HostBaseAddr+0x120); 
    EDBulkIn   = (volatile  HCED       *)(HostBaseAddr+0x130);
    EDBulkOut  = (volatile  HCED       *)(HostBaseAddr+0x140);
    TDBuffer   = (volatile  uint8_t *)(HostBaseAddr+0x150);
    FATBuffer  = (volatile  uint8_t *)(HostBaseAddr+0x1D0);
    UserBuffer = (volatile  uint8_t *)(HostBaseAddr+0x1000);
    Host_EDInit(EDCtrl);
    Host_EDInit(EDBulkIn);
    Host_EDInit(EDBulkOut);
    Host_TDInit(TDHead);
    Host_TDInit(TDTail);
    Host_HCCAInit(Hcca);
    Host_DelayMS(50);                
    LPC_USB->Control       = 0;    
    LPC_USB->ControlHeadED = 0;    
    LPC_USB->BulkHeadED    = 0;    
    LPC_USB->CommandStatus = OR_CMD_STATUS_HCR;
    LPC_USB->FmInterval    = DEFAULT_FMINTERVAL;  
    LPC_USB->Control  = (LPC_USB->Control & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER;
    LPC_USB->RhStatus = OR_RH_STATUS_LPSC;        
    LPC_USB->HCCA = (uint32_t)Hcca;
    LPC_USB->InterruptStatus |= LPC_USB->InterruptStatus;                   
    LPC_USB->InterruptEnable  = OR_INTR_ENABLE_MIE |
                         OR_INTR_ENABLE_WDH |
                         OR_INTR_ENABLE_RHSC |
                         OR_INTR_ENABLE_UE;
	NVIC_EnableIRQ(USB_IRQn);               
	NVIC_SetPriority (USB_IRQn, 0);			
    PRINT_Log("Host Initialized\n");
}
void Host_Init ( void ) { uint32_t HostBaseAddr ; LPC_SC -> PCONP |= 0x80000000 ; LPC_USB -> USBClkCtrl = 0x0000001F ; while ( ( LPC_USB -> USBClkSt & 0x0000001F ) != 0x1F ) ; LPC_USB -> StCtrl = 0x3 ; LPC_PINCON -> PINSEL3 &= ~ ( ( 3 << 4 ) | ( 3 << 6 ) | ( 3 << 12 ) | ( 3 << 22 ) ) ; LPC_PINCON -> PINSEL3 |= ( ( 1 << 4 ) | ( 2 << 6 ) | ( 2 << 12 ) | ( 2 << 22 ) ) ; LPC_PINCON -> PINSEL1 &= ~ ( ( 3 << 26 ) | ( 3 << 28 ) ) ; LPC_PINCON -> PINSEL1 |= ( ( 1 << 26 ) | ( 1 << 28 ) ) ; PRINT_Log ( " \n " ) ; HostBaseAddr = HOST_BASE_ADDR ; Hcca = ( volatile HCCA * ) ( HostBaseAddr + 0x000 ) ; TDHead = ( volatile HCTD * ) ( HostBaseAddr + 0x100 ) ; TDTail = ( volatile HCTD * ) ( HostBaseAddr + 0x110 ) ; EDCtrl = ( volatile HCED * ) ( HostBaseAddr + 0x120 ) ; EDBulkIn = ( volatile HCED * ) ( HostBaseAddr + 0x130 ) ; EDBulkOut = ( volatile HCED * ) ( HostBaseAddr + 0x140 ) ; TDBuffer = ( volatile uint8_t * ) ( HostBaseAddr + 0x150 ) ; FATBuffer = ( volatile uint8_t * ) ( HostBaseAddr + 0x1D0 ) ; UserBuffer = ( volatile uint8_t * ) ( HostBaseAddr + 0x1000 ) ; Host_EDInit ( EDCtrl ) ; Host_EDInit ( EDBulkIn ) ; Host_EDInit ( EDBulkOut ) ; Host_TDInit ( TDHead ) ; Host_TDInit ( TDTail ) ; Host_HCCAInit ( Hcca ) ; Host_DelayMS ( 50 ) ; LPC_USB -> Control = 0 ; LPC_USB -> ControlHeadED = 0 ; LPC_USB -> BulkHeadED = 0 ; LPC_USB -> CommandStatus = OR_CMD_STATUS_HCR ; LPC_USB -> FmInterval = DEFAULT_FMINTERVAL ; LPC_USB -> Control = ( LPC_USB -> Control & ( ~ OR_CONTROL_HCFS ) ) | OR_CONTROL_HC_OPER ; LPC_USB -> RhStatus = OR_RH_STATUS_LPSC ; LPC_USB -> HCCA = ( uint32_t ) Hcca ; LPC_USB -> InterruptStatus |= LPC_USB -> InterruptStatus ; LPC_USB -> InterruptEnable = OR_INTR_ENABLE_MIE | OR_INTR_ENABLE_WDH | OR_INTR_ENABLE_RHSC | OR_INTR_ENABLE_UE ; NVIC_EnableIRQ ( USB_IRQn ) ; NVIC_SetPriority ( USB_IRQn , 0 ) ; PRINT_Log ( " \n " ) ; }
INITIALIZE THE HOST CONTROLLER
Description: This function initializes lpc17xx host controller
INITIALIZE THE HOST CONTROLLER Description : This function initializes lpc17xx host controller
/* Enable USB host clock                      */ /* P1[18] = USB_UP_LED, 01 */ /* P1[19] = /USB_PPWR, 	10 */ /* P1[22] = USB_PWRD, 10 */ /* P1[27] = /USB_OVRCR, 10 */ // 0x00802080 /* P0[29] = USB_D+, 01 */ /* P0[30] = USB_D-, 01 */ // 0x14000000 /* Set up host base address and TD and ED descriptors */ /* Initialize all the TDs, EDs and HCCA to 0  */ /* Wait 50 ms before apply reset              */ /* HARDWARE RESET                             */ /* Initialize Control list head to Zero       */ /* Initialize Bulk list head to Zero          */ /* SOFTWARE RESET                             */ /* Write Fm Interval and Largest Data Packet Counter */ /* Put HC in operational state                */ /* Set Global Power                           */ /* Clear Interrrupt Status                    */ /* Enable the USB Interrupt */ /* enable USB interrupt */ /* highest priority */