usb_glue_nuc980.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**************************************************************************/ /**
  2. *
  3. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2023-8-8 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include "rtthread.h"
  13. #include "NuMicro.h"
  14. #include "rthw.h"
  15. #include "drv_sys.h"
  16. #define LOG_TAG "drv.cherry"
  17. #define DBG_ENABLE
  18. #define DBG_SECTION_NAME LOG_TAG
  19. #define DBG_LEVEL DBG_LOG
  20. #define DBG_COLOR
  21. #include <rtdbg.h>
  22. #if defined(PKG_CHERRYUSB_HOST)
  23. #include "usbh_core.h"
  24. static void nu_ehci_isr(int vector, void *param)
  25. {
  26. extern void USBH_IRQHandler(uint8_t busid);
  27. USBH_IRQHandler(0);
  28. }
  29. void usb_hc_low_level_init(struct usbh_bus *bus)
  30. {
  31. LOG_D("%s %d", __FUNCTION__, __LINE__);
  32. rt_hw_interrupt_mask(IRQ_EHCI);
  33. /* Enable USBH clock */
  34. nu_sys_ipclk_enable(USBHCKEN);
  35. nu_sys_ip_reset(USBHRST);
  36. outpw(0xB0015000 + 0xC4, 0x160); //HSUSBH->USBPCR0 = 0x160; /* enable PHY 0 */
  37. outpw(0xB0015000 + 0xC8, 0x520); //HSUSBH->USBPCR1 = 0x520; /* enable PHY 1 */
  38. //USBH->HcMiscControl |= USBH_HcMiscControl_OCAL_Msk; /* Over-current active low */
  39. //outpw(0xB0017000 + 0x204, inpw(0xB0017000 + 0x204) | (0x1ul << 3));
  40. //USBH->HcMiscControl &= ~USBH_HcMiscControl_OCAL_Msk; /* Over-current active high */
  41. outpw(0xB0017000 + 0x204, inpw(0xB0017000 + 0x204) & (~(0x1ul << 3)));
  42. rt_hw_interrupt_install(IRQ_EHCI, nu_ehci_isr, NULL, "ehci-1");
  43. rt_hw_interrupt_set_priority(IRQ_EHCI, IRQ_LEVEL_1);
  44. rt_hw_interrupt_umask(IRQ_EHCI);
  45. }
  46. uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
  47. {
  48. return USB_SPEED_HIGH;
  49. }
  50. #endif