1 #include "usbh_core.h" 2 #include "hpm_common.h" 3 #include "hpm_soc.h" 4 #include "hpm_usb_drv.h" 5 6 #if !defined(CONFIG_USB_EHCI_HPMICRO) || !CONFIG_USB_EHCI_HPMICRO 7 #error "hpm ehci must set CONFIG_USB_EHCI_HPMICRO=1" 8 #endif 9 10 #if !defined(CONFIG_HPM_USBH_BASE) || !defined(CONFIG_HPM_USBH_IRQn) 11 #error "hpm ehci must config CONFIG_HPM_USBH_BASE and CONFIG_HPM_USBH_IRQn" 12 #endif 13 usb_host_mode_init(USB_Type * ptr)14static void usb_host_mode_init(USB_Type *ptr) 15 { 16 /* Set mode to host, must be set immediately after reset */ 17 ptr->USBMODE &= ~USB_USBMODE_CM_MASK; 18 ptr->USBMODE |= USB_USBMODE_CM_SET(3); 19 20 /* Set the endian */ 21 ptr->USBMODE &= ~USB_USBMODE_ES_MASK; 22 23 /* Set parallel interface signal */ 24 ptr->PORTSC1 &= ~USB_PORTSC1_STS_MASK; 25 26 /* Set parallel transceiver width */ 27 ptr->PORTSC1 &= ~USB_PORTSC1_PTW_MASK; 28 29 /* Not use interrupt threshold. */ 30 ptr->USBCMD &= ~USB_USBCMD_ITC_MASK; 31 } 32 usb_hc_low_level_init(void)33void usb_hc_low_level_init(void) 34 { 35 usb_phy_init((USB_Type *)CONFIG_HPM_USBH_BASE); 36 intc_m_enable_irq(CONFIG_HPM_USBH_IRQn); 37 } 38 usb_hc_low_level2_init(void)39void usb_hc_low_level2_init(void) 40 { 41 usb_host_mode_init((USB_Type *)CONFIG_HPM_USBH_BASE); 42 } 43 usbh_get_port_speed(const uint8_t port)44uint8_t usbh_get_port_speed(const uint8_t port) 45 { 46 (void)port; 47 uint8_t speed; 48 49 speed = usb_get_port_speed((USB_Type *)CONFIG_HPM_USBH_BASE); 50 51 if (speed == 0x00) { 52 return USB_SPEED_FULL; 53 } 54 if (speed == 0x01) { 55 return USB_SPEED_LOW; 56 } 57 if (speed == 0x02) { 58 return USB_SPEED_HIGH; 59 } 60 61 return 0; 62 } 63 64 extern void USBH_IRQHandler(void); 65 isr_usbh(void)66void isr_usbh(void) 67 { 68 USBH_IRQHandler(); 69 } 70 SDK_DECLARE_EXT_ISR_M(CONFIG_HPM_USBH_IRQn, isr_usbh)