config.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**************************************************************************//**
  2. * @file config.h
  3. * @version V1.00
  4. * @brief This header file defines the configuration of USB Host library.
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef _USBH_CONFIG_H_
  10. #define _USBH_CONFIG_H_
  11. /// @cond HIDDEN_SYMBOLS
  12. #include <rtthread.h>
  13. #include "NuMicro.h"
  14. #include "nu_sys.h"
  15. #include "drv_sys.h"
  16. /*----------------------------------------------------------------------------------------*/
  17. /* Hardware settings */
  18. /*----------------------------------------------------------------------------------------*/
  19. #define HCLK_MHZ 700 /* used for loop-delay. must be larger than
  20. true HCLK clock MHz */
  21. static __inline void ENABLE_OHCI_IRQ(void)
  22. {
  23. rt_hw_interrupt_umask(USBH0_IRQn);
  24. rt_hw_interrupt_umask(USBH1_IRQn);
  25. }
  26. static __inline void DISABLE_OHCI_IRQ(void)
  27. {
  28. rt_hw_interrupt_mask(USBH0_IRQn);
  29. rt_hw_interrupt_mask(USBH1_IRQn);
  30. }
  31. static __inline void ENABLE_EHCI_IRQ(void)
  32. {
  33. rt_hw_interrupt_umask(HSUSBH0_IRQn);
  34. rt_hw_interrupt_umask(HSUSBH1_IRQn);
  35. }
  36. static __inline void DISABLE_EHCI_IRQ(void)
  37. {
  38. rt_hw_interrupt_mask(HSUSBH0_IRQn);
  39. rt_hw_interrupt_mask(HSUSBH1_IRQn);
  40. }
  41. #if defined(BSP_USING_HSUSBH0)
  42. #define ENABLE_EHCI0
  43. #define ENABLE_OHCI0
  44. #endif
  45. #if defined(BSP_USING_HSUSBH1)
  46. #define ENABLE_EHCI1
  47. #define ENABLE_OHCI1
  48. #endif
  49. #define EHCI_PORT_CNT 1 /* Number of EHCI roothub ports */
  50. #define OHCI_PORT_CNT 1 /* Number of OHCI roothub ports */
  51. #define OHCI_PER_PORT_POWER /* OHCI root hub per port powered */
  52. #define OHCI_ISO_DELAY 4 /* preserved number frames while scheduling
  53. OHCI isochronous transfer */
  54. #define EHCI_ISO_DELAY 2 /* preserved number of frames while
  55. scheduling EHCI isochronous transfer */
  56. #define EHCI_ISO_RCLM_RANGE 32 /* When inspecting activated iTD/siTD,
  57. unconditionally reclaim iTD/isTD scheduled
  58. in just elapsed EHCI_ISO_RCLM_RANGE ms. */
  59. #define MAX_DESC_BUFF_SIZE 4096 /* To hold the configuration descriptor, USB
  60. core will allocate a buffer with this size
  61. for each connected device. USB core does
  62. not release it until device disconnected. */
  63. /*----------------------------------------------------------------------------------------*/
  64. /* Memory allocation settings */
  65. /*----------------------------------------------------------------------------------------*/
  66. #define STATIC_MEMORY_ALLOC 0 /* pre-allocate static memory blocks. No dynamic memory aloocation.
  67. But the maximum number of connected devices and transfers are
  68. limited. */
  69. #define MAX_UDEV_DRIVER 8 /*!< Maximum number of registered drivers */
  70. #define MAX_ALT_PER_IFACE 32 /*!< maximum number of alternative interfaces per interface */
  71. #define MAX_EP_PER_IFACE 6 /*!< maximum number of endpoints per interface */
  72. #define MAX_HUB_DEVICE 8 /*!< Maximum number of hub devices */
  73. /* Host controller hardware transfer descriptors memory pool. ED/TD/ITD of OHCI and QH/QTD of EHCI
  74. are all allocated from this pool. Allocated unit size is determined by MEM_POOL_UNIT_SIZE.
  75. May allocate one or more units depend on hardware descriptor type. */
  76. #define MEM_POOL_UNIT_SIZE 256 /*!< A fixed hard coding setting. Do not change it! */
  77. #define MEM_POOL_UNIT_NUM 64 /*!< Increase this or heap size if memory allocate failed. */
  78. /*----------------------------------------------------------------------------------------*/
  79. /* Re-defined staff for various compiler */
  80. /*----------------------------------------------------------------------------------------*/
  81. #ifdef __ICCARM__
  82. #define __inline inline
  83. #endif
  84. /*----------------------------------------------------------------------------------------*/
  85. /* Debug settings */
  86. /*----------------------------------------------------------------------------------------*/
  87. //#define ENABLE_ERROR_MSG /* enable debug messages */
  88. //#define ENABLE_DEBUG_MSG /* enable debug messages */
  89. //#define ENABLE_VERBOSE_DEBUG /* verbos debug messages */
  90. //#define DUMP_DESCRIPTOR /* dump descriptors */
  91. #ifdef ENABLE_ERROR_MSG
  92. #define USB_error rt_kprintf
  93. #else
  94. #define USB_error(...)
  95. #endif
  96. #ifdef ENABLE_DEBUG_MSG
  97. #define USB_debug rt_kprintf
  98. #ifdef ENABLE_VERBOSE_DEBUG
  99. #define USB_vdebug rt_kprintf
  100. #else
  101. #define USB_vdebug(...)
  102. #endif
  103. #else
  104. #define USB_debug(...)
  105. #define USB_vdebug(...)
  106. #endif
  107. #define ptr_to_u32(x) ((uint32_t)(x))
  108. /// @endcond HIDDEN_SYMBOLS
  109. #endif /* _USBH_CONFIG_H_ */
  110. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/