usb_misc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __USB_MISC_H__
  31. #define __USB_MISC_H__
  32. #ifndef ENDIANNESS
  33. #error ENDIANNESS should be defined, and then rebulid the project.
  34. #endif
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /*! @brief Define USB printf */
  39. #if defined(__cplusplus)
  40. extern "C" {
  41. #endif /* __cplusplus */
  42. extern int DbgConsole_Printf(const char *fmt_s, ...);
  43. #if defined(__cplusplus)
  44. }
  45. #endif /* __cplusplus */
  46. #if defined(SDK_DEBUGCONSOLE) && (SDK_DEBUGCONSOLE < 1)
  47. #define usb_echo printf
  48. #else
  49. #define usb_echo DbgConsole_Printf
  50. #endif
  51. #if defined(__ICCARM__)
  52. #ifndef STRUCT_PACKED
  53. #define STRUCT_PACKED __packed
  54. #endif
  55. #ifndef STRUCT_UNPACKED
  56. #define STRUCT_UNPACKED
  57. #endif
  58. #elif defined(__GNUC__)
  59. #ifndef STRUCT_PACKED
  60. #define STRUCT_PACKED
  61. #endif
  62. #ifndef STRUCT_UNPACKED
  63. #define STRUCT_UNPACKED __attribute__((__packed__))
  64. #endif
  65. #elif defined(__CC_ARM)
  66. #ifndef STRUCT_PACKED
  67. #define STRUCT_PACKED _Pragma("pack(1U)")
  68. #endif
  69. #ifndef STRUCT_UNPACKED
  70. #define STRUCT_UNPACKED _Pragma("pack()")
  71. #endif
  72. #endif
  73. #define USB_SHORT_GET_LOW(x) (((uint16_t)x) & 0xFFU)
  74. #define USB_SHORT_GET_HIGH(x) ((uint8_t)(((uint16_t)x) >> 8U) & 0xFFU)
  75. #define USB_LONG_GET_BYTE0(x) ((uint8_t)(((uint32_t)(x))) & 0xFFU)
  76. #define USB_LONG_GET_BYTE1(x) ((uint8_t)(((uint32_t)(x)) >> 8U) & 0xFFU)
  77. #define USB_LONG_GET_BYTE2(x) ((uint8_t)(((uint32_t)(x)) >> 16U) & 0xFFU)
  78. #define USB_LONG_GET_BYTE3(x) ((uint8_t)(((uint32_t)(x)) >> 24U) & 0xFFU)
  79. #define USB_MEM4_ALIGN_MASK (0x03U)
  80. /* accessory macro */
  81. #define USB_MEM4_ALIGN(n) ((n + 3U) & (0xFFFFFFFCu))
  82. #define USB_MEM32_ALIGN(n) ((n + 31U) & (0xFFFFFFE0u))
  83. #define USB_MEM64_ALIGN(n) ((n + 63U) & (0xFFFFFFC0u))
  84. /* big/little endian */
  85. #define SWAP2BYTE_CONST(n) ((((n)&0x00FFU) << 8U) | (((n)&0xFF00U) >> 8U))
  86. #define SWAP4BYTE_CONST(n) \
  87. ((((n)&0x000000FFU) << 24U) | (((n)&0x0000FF00U) << 8U) | (((n)&0x00FF0000U) >> 8U) | (((n)&0xFF000000U) >> 24U))
  88. #define USB_ASSIGN_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
  89. { \
  90. *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
  91. *((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
  92. *((uint8_t *)&(n) + 2) = *((uint8_t *)&(m) + 2); \
  93. *((uint8_t *)&(n) + 3) = *((uint8_t *)&(m) + 3); \
  94. }
  95. #define USB_ASSIGN_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
  96. { \
  97. *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
  98. *((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
  99. }
  100. #define USB_ASSIGN_MACRO_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
  101. { \
  102. *((uint8_t *)&(n)) = (uint8_t)m; \
  103. *((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
  104. *((uint8_t *)&(n) + 2) = (uint8_t)(m >> 16); \
  105. *((uint8_t *)&(n) + 3) = (uint8_t)(m >> 24); \
  106. }
  107. #define USB_ASSIGN_MACRO_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
  108. { \
  109. *((uint8_t *)&(n)) = (uint8_t)m; \
  110. *((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
  111. }
  112. #if (ENDIANNESS == USB_BIG_ENDIAN)
  113. #define USB_SHORT_TO_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  114. #define USB_LONG_TO_LITTLE_ENDIAN(n) SWAP4BYTE_CONST(n)
  115. #define USB_SHORT_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  116. #define USB_LONG_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  117. #define USB_SHORT_TO_BIG_ENDIAN(n) (n)
  118. #define USB_LONG_TO_BIG_ENDIAN(n) (n)
  119. #define USB_SHORT_FROM_BIG_ENDIAN(n) (n)
  120. #define USB_LONG_FROM_BIG_ENDIAN(n) (n)
  121. #define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  122. { \
  123. m[3] = ((n >> 24U) & 0xFFU); \
  124. m[2] = ((n >> 16U) & 0xFFU); \
  125. m[1] = ((n >> 8U) & 0xFFU); \
  126. m[0] = (n & 0xFFU); \
  127. }
  128. #define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
  129. ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
  130. (((uint8_t)n[0]) << 0U)))
  131. #define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
  132. { \
  133. m[0] = ((n >> 24U) & 0xFFU); \
  134. m[1] = ((n >> 16U) & 0xFFU); \
  135. m[2] = ((n >> 8U) & 0xFFU); \
  136. m[3] = (n & 0xFFU); \
  137. }
  138. #define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
  139. ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
  140. (((uint8_t)n[3]) << 0U)))
  141. #define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  142. { \
  143. m[1] = ((n >> 8U) & 0xFFU); \
  144. m[0] = (n & 0xFFU); \
  145. }
  146. #define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
  147. #define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
  148. { \
  149. m[0] = ((n >> 8U) & 0xFFU); \
  150. m[1] = (n & 0xFFU); \
  151. }
  152. #define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
  153. #define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
  154. { \
  155. *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
  156. *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
  157. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  158. *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
  159. }
  160. #define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
  161. ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
  162. ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
  163. #define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
  164. { \
  165. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  166. *((uint8_t *)&(m)) = ((n)&0xFFU); \
  167. }
  168. #define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
  169. #else
  170. #define USB_SHORT_TO_LITTLE_ENDIAN(n) (n)
  171. #define USB_LONG_TO_LITTLE_ENDIAN(n) (n)
  172. #define USB_SHORT_FROM_LITTLE_ENDIAN(n) (n)
  173. #define USB_LONG_FROM_LITTLE_ENDIAN(n) (n)
  174. #define USB_SHORT_TO_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
  175. #define USB_LONG_TO_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
  176. #define USB_SHORT_FROM_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
  177. #define USB_LONG_FROM_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
  178. #define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  179. { \
  180. m[3] = ((n >> 24U) & 0xFFU); \
  181. m[2] = ((n >> 16U) & 0xFFU); \
  182. m[1] = ((n >> 8U) & 0xFFU); \
  183. m[0] = (n & 0xFFU); \
  184. }
  185. #define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
  186. ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
  187. (((uint8_t)n[0]) << 0U)))
  188. #define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
  189. { \
  190. m[0] = ((n >> 24U) & 0xFFU); \
  191. m[1] = ((n >> 16U) & 0xFFU); \
  192. m[2] = ((n >> 8U) & 0xFFU); \
  193. m[3] = (n & 0xFFU); \
  194. }
  195. #define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
  196. ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
  197. (((uint8_t)n[3]) << 0U)))
  198. #define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  199. { \
  200. m[1] = ((n >> 8U) & 0xFFU); \
  201. m[0] = (n & 0xFFU); \
  202. }
  203. #define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
  204. #define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
  205. { \
  206. m[0] = ((n >> 8U) & 0xFFU); \
  207. m[1] = (n & 0xFFU); \
  208. }
  209. #define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
  210. #define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
  211. { \
  212. *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
  213. *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
  214. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  215. *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
  216. }
  217. #define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
  218. ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
  219. ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
  220. #define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
  221. { \
  222. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  223. *((uint8_t *)&(m)) = ((n)&0xFFU); \
  224. }
  225. #define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
  226. #endif
  227. /*
  228. * The following MACROs (USB_GLOBAL, USB_BDT, USB_RAM_ADDRESS_ALIGNMENT, etc) are only used for USB device stack.
  229. * The USB device global variables are put into the section m_usb_global and m_usb_bdt or the section
  230. * .bss.m_usb_global and .bss.m_usb_bdt by using the MACRO USB_GLOBAL and USB_BDT. In this way, the USB device
  231. * global variables can be linked into USB dedicated RAM by USB_STACK_USE_DEDICATED_RAM.
  232. * The MACRO USB_STACK_USE_DEDICATED_RAM is used to decide the USB stack uses dedicated RAM or not. The value of
  233. * the marco can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT.
  234. * The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL means USB device global variables, including USB_BDT and
  235. * USB_GLOBAL, are put into the USB dedicated RAM. This feature can only be enabled when the USB dedicated RAM
  236. * is not less than 2K Bytes.
  237. * The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT means USB device global variables, only including USB_BDT, are put
  238. * into the USB dedicated RAM, the USB_GLOBAL will be put into .bss section. This feature is used for some SOCs,
  239. * the USB dedicated RAM size is not more than 512 Bytes.
  240. */
  241. #define USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL 1
  242. #define USB_STACK_DEDICATED_RAM_TYPE_BDT 2
  243. #if defined(__ICCARM__)
  244. #define USB_WEAK_VAR __attribute__((weak))
  245. #define USB_WEAK_FUN __attribute__((weak))
  246. /* disable misra 19.13 */
  247. _Pragma("diag_suppress=Pm120")
  248. #define USB_ALIGN_PRAGMA(x) _Pragma(#x)
  249. _Pragma("diag_default=Pm120")
  250. #define USB_RAM_ADDRESS_ALIGNMENT(n) USB_ALIGN_PRAGMA(data_alignment = n)
  251. _Pragma("diag_suppress=Pm120")
  252. #define USB_LINK_SECTION_PART(str) _Pragma(#str)
  253. #define USB_LINK_SECTION_SUB(sec) USB_LINK_SECTION_PART(location = #sec)
  254. #define USB_LINK_USB_GLOBAL _Pragma("location = \"m_usb_global\"")
  255. #define USB_LINK_USB_BDT _Pragma("location = \"m_usb_bdt\"")
  256. #define USB_LINK_USB_GLOBAL_BSS _Pragma("location = \".bss.m_usb_global\"")
  257. #define USB_LINK_USB_BDT_BSS _Pragma("location = \".bss.m_usb_bdt\"")
  258. _Pragma("diag_default=Pm120")
  259. #define USB_LINK_DMA_NONINIT_DATA _Pragma("location = \"m_usb_dma_noninit_data\"")
  260. #define USB_LINK_NONCACHE_NONINIT_DATA _Pragma("location = \"NonCacheable\"")
  261. #elif defined(__CC_ARM)
  262. #define USB_WEAK_VAR __attribute__((weak))
  263. #define USB_WEAK_FUN __weak
  264. #define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
  265. #define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
  266. #define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global"))) __attribute__((zero_init))
  267. #define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt"))) __attribute__((zero_init))
  268. #define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global"))) __attribute__((zero_init))
  269. #define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt"))) __attribute__((zero_init))
  270. #define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data"))) __attribute__((zero_init))
  271. #define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable"))) __attribute__((zero_init))
  272. #elif defined(__GNUC__)
  273. #define USB_WEAK_VAR __attribute__((weak))
  274. #define USB_WEAK_FUN __attribute__((weak))
  275. #define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
  276. #define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
  277. #define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global, \"aw\", %nobits @")))
  278. #define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt, \"aw\", %nobits @")))
  279. #define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global, \"aw\", %nobits @")))
  280. #define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt, \"aw\", %nobits @")))
  281. #define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data, \"aw\", %nobits @")))
  282. #define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable, \"aw\", %nobits @")))
  283. #else
  284. #error The tool-chain is not supported.
  285. #endif
  286. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  287. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  288. #if ((defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)) && (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
  289. #define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
  290. #elif(defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))
  291. #define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, 0)
  292. #elif(defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))
  293. #define USB_CACHE_LINESIZE MAX(0, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
  294. #else
  295. #define USB_CACHE_LINESIZE 4
  296. #endif
  297. #else
  298. #define USB_CACHE_LINESIZE 4
  299. #endif
  300. #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
  301. ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
  302. #define USB_DATA_ALIGN 64
  303. #else
  304. #define USB_DATA_ALIGN 4
  305. #endif
  306. #define USB_DATA_ALIGN_SIZE MAX(USB_CACHE_LINESIZE, USB_DATA_ALIGN)
  307. #define USB_DATA_ALIGN_SIZE_MULTIPLE(n) ((n + USB_DATA_ALIGN_SIZE - 1) & (~(USB_DATA_ALIGN_SIZE - 1)))
  308. #if defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL)
  309. #define USB_GLOBAL USB_LINK_USB_GLOBAL
  310. #define USB_BDT USB_LINK_USB_BDT
  311. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  312. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  313. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  314. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  315. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  316. #else
  317. #define USB_DMA_DATA_NONINIT_SUB
  318. #define USB_DMA_DATA_INIT_SUB
  319. #define USB_CONTROLLER_DATA USB_LINK_USB_GLOBAL
  320. #endif
  321. #elif defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT)
  322. #define USB_BDT USB_LINK_USB_BDT
  323. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  324. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  325. #define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
  326. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  327. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  328. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  329. #else
  330. #define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
  331. #define USB_DMA_DATA_NONINIT_SUB
  332. #define USB_DMA_DATA_INIT_SUB
  333. #define USB_CONTROLLER_DATA
  334. #endif
  335. #else
  336. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  337. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  338. #define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
  339. #define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
  340. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  341. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  342. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  343. #else
  344. #define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
  345. #define USB_BDT USB_LINK_USB_BDT_BSS
  346. #define USB_DMA_DATA_NONINIT_SUB
  347. #define USB_DMA_DATA_INIT_SUB
  348. #define USB_CONTROLLER_DATA
  349. #endif
  350. #endif
  351. #define USB_DMA_NONINIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_NONINIT_SUB
  352. #define USB_DMA_INIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_INIT_SUB
  353. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  354. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  355. #define USB_DMA_DATA_NONCACHEABLE USB_LINK_NONCACHE_NONINIT_DATA
  356. #else
  357. #define USB_DMA_DATA_NONCACHEABLE
  358. #endif
  359. #define USB_GLOBAL_DEDICATED_RAM USB_LINK_USB_GLOBAL
  360. /* #define USB_RAM_ADDRESS_NONCACHEREG_ALIGNMENT(n, var) AT_NONCACHEABLE_SECTION_ALIGN(var, n) */
  361. /* #define USB_RAM_ADDRESS_NONCACHEREG(var) AT_NONCACHEABLE_SECTION(var) */
  362. #endif /* __USB_MISC_H__ */