usb_misc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. #define ENDIANNESS USB_LITTLE_ENDIAN
  33. #ifndef ENDIANNESS
  34. #error ENDIANNESS should be defined, and then rebulid the project.
  35. #endif
  36. /*******************************************************************************
  37. * Definitions
  38. ******************************************************************************/
  39. /*! @brief Define USB printf */
  40. #if defined(__cplusplus)
  41. extern "C" {
  42. #endif /* __cplusplus */
  43. extern int DbgConsole_Printf(const char *fmt_s, ...);
  44. #if defined(__cplusplus)
  45. }
  46. #endif /* __cplusplus */
  47. #if defined(SDK_DEBUGCONSOLE) && (SDK_DEBUGCONSOLE < 1)
  48. #define usb_echo printf
  49. #else
  50. #define usb_echo DbgConsole_Printf
  51. #endif
  52. #if defined(__ICCARM__)
  53. #ifndef STRUCT_PACKED
  54. #define STRUCT_PACKED __packed
  55. #endif
  56. #ifndef STRUCT_UNPACKED
  57. #define STRUCT_UNPACKED
  58. #endif
  59. #elif defined(__GNUC__)
  60. #ifndef STRUCT_PACKED
  61. #define STRUCT_PACKED
  62. #endif
  63. #ifndef STRUCT_UNPACKED
  64. #define STRUCT_UNPACKED __attribute__((__packed__))
  65. #endif
  66. #elif defined(__CC_ARM)
  67. #ifndef STRUCT_PACKED
  68. #define STRUCT_PACKED _Pragma("pack(1U)")
  69. #endif
  70. #ifndef STRUCT_UNPACKED
  71. #define STRUCT_UNPACKED _Pragma("pack()")
  72. #endif
  73. #endif
  74. #define USB_SHORT_GET_LOW(x) (((uint16_t)x) & 0xFFU)
  75. #define USB_SHORT_GET_HIGH(x) ((uint8_t)(((uint16_t)x) >> 8U) & 0xFFU)
  76. #define USB_LONG_GET_BYTE0(x) ((uint8_t)(((uint32_t)(x))) & 0xFFU)
  77. #define USB_LONG_GET_BYTE1(x) ((uint8_t)(((uint32_t)(x)) >> 8U) & 0xFFU)
  78. #define USB_LONG_GET_BYTE2(x) ((uint8_t)(((uint32_t)(x)) >> 16U) & 0xFFU)
  79. #define USB_LONG_GET_BYTE3(x) ((uint8_t)(((uint32_t)(x)) >> 24U) & 0xFFU)
  80. #define USB_MEM4_ALIGN_MASK (0x03U)
  81. /* accessory macro */
  82. #define USB_MEM4_ALIGN(n) ((n + 3U) & (0xFFFFFFFCu))
  83. #define USB_MEM32_ALIGN(n) ((n + 31U) & (0xFFFFFFE0u))
  84. #define USB_MEM64_ALIGN(n) ((n + 63U) & (0xFFFFFFC0u))
  85. /* big/little endian */
  86. #define SWAP2BYTE_CONST(n) ((((n)&0x00FFU) << 8U) | (((n)&0xFF00U) >> 8U))
  87. #define SWAP4BYTE_CONST(n) \
  88. ((((n)&0x000000FFU) << 24U) | (((n)&0x0000FF00U) << 8U) | (((n)&0x00FF0000U) >> 8U) | (((n)&0xFF000000U) >> 24U))
  89. #define USB_ASSIGN_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
  90. { \
  91. *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
  92. *((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
  93. *((uint8_t *)&(n) + 2) = *((uint8_t *)&(m) + 2); \
  94. *((uint8_t *)&(n) + 3) = *((uint8_t *)&(m) + 3); \
  95. }
  96. #define USB_ASSIGN_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
  97. { \
  98. *((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
  99. *((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
  100. }
  101. #define USB_ASSIGN_MACRO_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
  102. { \
  103. *((uint8_t *)&(n)) = (uint8_t)m; \
  104. *((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
  105. *((uint8_t *)&(n) + 2) = (uint8_t)(m >> 16); \
  106. *((uint8_t *)&(n) + 3) = (uint8_t)(m >> 24); \
  107. }
  108. #define USB_ASSIGN_MACRO_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
  109. { \
  110. *((uint8_t *)&(n)) = (uint8_t)m; \
  111. *((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
  112. }
  113. //#if (ENDIANNESS == USB_BIG_ENDIAN)
  114. #if 0
  115. #define USB_SHORT_TO_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  116. #define USB_LONG_TO_LITTLE_ENDIAN(n) SWAP4BYTE_CONST(n)
  117. #define USB_SHORT_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  118. #define USB_LONG_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
  119. #define USB_SHORT_TO_BIG_ENDIAN(n) (n)
  120. #define USB_LONG_TO_BIG_ENDIAN(n) (n)
  121. #define USB_SHORT_FROM_BIG_ENDIAN(n) (n)
  122. #define USB_LONG_FROM_BIG_ENDIAN(n) (n)
  123. #define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  124. { \
  125. m[3] = ((n >> 24U) & 0xFFU); \
  126. m[2] = ((n >> 16U) & 0xFFU); \
  127. m[1] = ((n >> 8U) & 0xFFU); \
  128. m[0] = (n & 0xFFU); \
  129. }
  130. #define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
  131. ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
  132. (((uint8_t)n[0]) << 0U)))
  133. #define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
  134. { \
  135. m[0] = ((n >> 24U) & 0xFFU); \
  136. m[1] = ((n >> 16U) & 0xFFU); \
  137. m[2] = ((n >> 8U) & 0xFFU); \
  138. m[3] = (n & 0xFFU); \
  139. }
  140. #define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
  141. ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
  142. (((uint8_t)n[3]) << 0U)))
  143. #define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  144. { \
  145. m[1] = ((n >> 8U) & 0xFFU); \
  146. m[0] = (n & 0xFFU); \
  147. }
  148. #define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
  149. #define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
  150. { \
  151. m[0] = ((n >> 8U) & 0xFFU); \
  152. m[1] = (n & 0xFFU); \
  153. }
  154. #define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
  155. #define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
  156. { \
  157. *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
  158. *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
  159. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  160. *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
  161. }
  162. #define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
  163. ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
  164. ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
  165. #define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
  166. { \
  167. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  168. *((uint8_t *)&(m)) = ((n)&0xFFU); \
  169. }
  170. #define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
  171. #else
  172. #define USB_SHORT_TO_LITTLE_ENDIAN(n) (n)
  173. #define USB_LONG_TO_LITTLE_ENDIAN(n) (n)
  174. #define USB_SHORT_FROM_LITTLE_ENDIAN(n) (n)
  175. #define USB_LONG_FROM_LITTLE_ENDIAN(n) (n)
  176. #define USB_SHORT_TO_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
  177. #define USB_LONG_TO_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
  178. #define USB_SHORT_FROM_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
  179. #define USB_LONG_FROM_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
  180. #define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  181. { \
  182. m[3] = ((n >> 24U) & 0xFFU); \
  183. m[2] = ((n >> 16U) & 0xFFU); \
  184. m[1] = ((n >> 8U) & 0xFFU); \
  185. m[0] = (n & 0xFFU); \
  186. }
  187. #define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
  188. ((uint32_t)((((uint8_t)n[3]) << 24U) | (((uint8_t)n[2]) << 16U) | (((uint8_t)n[1]) << 8U) | \
  189. (((uint8_t)n[0]) << 0U)))
  190. #define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
  191. { \
  192. m[0] = ((n >> 24U) & 0xFFU); \
  193. m[1] = ((n >> 16U) & 0xFFU); \
  194. m[2] = ((n >> 8U) & 0xFFU); \
  195. m[3] = (n & 0xFFU); \
  196. }
  197. #define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
  198. ((uint32_t)((((uint8_t)n[0]) << 24U) | (((uint8_t)n[1]) << 16U) | (((uint8_t)n[2]) << 8U) | \
  199. (((uint8_t)n[3]) << 0U)))
  200. #define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
  201. { \
  202. m[1] = ((n >> 8U) & 0xFFU); \
  203. m[0] = (n & 0xFFU); \
  204. }
  205. #define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[1]) << 8U) | (((uint8_t)n[0]) << 0U)))
  206. #define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
  207. { \
  208. m[0] = ((n >> 8U) & 0xFFU); \
  209. m[1] = (n & 0xFFU); \
  210. }
  211. #define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint32_t)((((uint8_t)n[0]) << 8U) | (((uint8_t)n[1]) << 0U)))
  212. #define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
  213. { \
  214. *((uint8_t *)&(m) + 3) = ((n >> 24U) & 0xFFU); \
  215. *((uint8_t *)&(m) + 2) = ((n >> 16U) & 0xFFU); \
  216. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  217. *((uint8_t *)&(m) + 0) = (n & 0xFFU); \
  218. }
  219. #define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
  220. ((uint32_t)(((*((uint8_t *)&(n) + 3)) << 24U) | ((*((uint8_t *)&(n) + 2)) << 16U) | \
  221. ((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))) << 0U)))
  222. #define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
  223. { \
  224. *((uint8_t *)&(m) + 1) = ((n >> 8U) & 0xFFU); \
  225. *((uint8_t *)&(m)) = ((n)&0xFFU); \
  226. }
  227. #define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) ((uint32_t)(((*((uint8_t *)&(n) + 1)) << 8U) | ((*((uint8_t *)&(n))))))
  228. #endif
  229. /*
  230. * The following MACROs (USB_GLOBAL, USB_BDT, USB_RAM_ADDRESS_ALIGNMENT, etc) are only used for USB device stack.
  231. * The USB device global variables are put into the section m_usb_global and m_usb_bdt or the section
  232. * .bss.m_usb_global and .bss.m_usb_bdt by using the MACRO USB_GLOBAL and USB_BDT. In this way, the USB device
  233. * global variables can be linked into USB dedicated RAM by USB_STACK_USE_DEDICATED_RAM.
  234. * The MACRO USB_STACK_USE_DEDICATED_RAM is used to decide the USB stack uses dedicated RAM or not. The value of
  235. * the marco can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT.
  236. * The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL means USB device global variables, including USB_BDT and
  237. * USB_GLOBAL, are put into the USB dedicated RAM. This feature can only be enabled when the USB dedicated RAM
  238. * is not less than 2K Bytes.
  239. * The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT means USB device global variables, only including USB_BDT, are put
  240. * into the USB dedicated RAM, the USB_GLOBAL will be put into .bss section. This feature is used for some SOCs,
  241. * the USB dedicated RAM size is not more than 512 Bytes.
  242. */
  243. #define USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL 1
  244. #define USB_STACK_DEDICATED_RAM_TYPE_BDT 2
  245. #if defined(__ICCARM__)
  246. #define USB_WEAK_VAR __attribute__((weak))
  247. #define USB_WEAK_FUN __attribute__((weak))
  248. /* disable misra 19.13 */
  249. _Pragma("diag_suppress=Pm120")
  250. #define USB_ALIGN_PRAGMA(x) _Pragma(#x)
  251. _Pragma("diag_default=Pm120")
  252. #define USB_RAM_ADDRESS_ALIGNMENT(n) USB_ALIGN_PRAGMA(data_alignment = n)
  253. _Pragma("diag_suppress=Pm120")
  254. #define USB_LINK_SECTION_PART(str) _Pragma(#str)
  255. #define USB_LINK_SECTION_SUB(sec) USB_LINK_SECTION_PART(location = #sec)
  256. #define USB_LINK_USB_GLOBAL _Pragma("location = \"m_usb_global\"")
  257. #define USB_LINK_USB_BDT _Pragma("location = \"m_usb_bdt\"")
  258. #define USB_LINK_USB_GLOBAL_BSS _Pragma("location = \".bss.m_usb_global\"")
  259. #define USB_LINK_USB_BDT_BSS _Pragma("location = \".bss.m_usb_bdt\"")
  260. _Pragma("diag_default=Pm120")
  261. #define USB_LINK_DMA_NONINIT_DATA _Pragma("location = \"m_usb_dma_noninit_data\"")
  262. #define USB_LINK_NONCACHE_NONINIT_DATA _Pragma("location = \"NonCacheable\"")
  263. #elif defined(__CC_ARM)
  264. #define USB_WEAK_VAR __attribute__((weak))
  265. #define USB_WEAK_FUN __weak
  266. #define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
  267. #define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
  268. #define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global"))) __attribute__((zero_init))
  269. #define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt"))) __attribute__((zero_init))
  270. #define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global"))) __attribute__((zero_init))
  271. #define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt"))) __attribute__((zero_init))
  272. #define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data"))) __attribute__((zero_init))
  273. #define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable"))) __attribute__((zero_init))
  274. #elif defined(__GNUC__)
  275. #define USB_WEAK_VAR __attribute__((weak))
  276. #define USB_WEAK_FUN __attribute__((weak))
  277. #define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
  278. #define USB_LINK_SECTION_SUB(sec) __attribute__((section(#sec)))
  279. #define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global, \"aw\", %nobits @")))
  280. #define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt, \"aw\", %nobits @")))
  281. #define USB_LINK_USB_GLOBAL_BSS __attribute__((section(".bss.m_usb_global, \"aw\", %nobits @")))
  282. #define USB_LINK_USB_BDT_BSS __attribute__((section(".bss.m_usb_bdt, \"aw\", %nobits @")))
  283. #define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data, \"aw\", %nobits @")))
  284. #define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable, \"aw\", %nobits @")))
  285. #else
  286. #error The tool-chain is not supported.
  287. #endif
  288. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  289. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  290. #if ((defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)) && (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
  291. #define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
  292. #elif(defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))
  293. #define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, 0)
  294. #elif(defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))
  295. #define USB_CACHE_LINESIZE MAX(0, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
  296. #else
  297. #define USB_CACHE_LINESIZE 4
  298. #endif
  299. #else
  300. #define USB_CACHE_LINESIZE 4
  301. #endif
  302. #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
  303. ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
  304. #define USB_DATA_ALIGN 64
  305. #else
  306. #define USB_DATA_ALIGN 4
  307. #endif
  308. #define USB_DATA_ALIGN_SIZE MAX(USB_CACHE_LINESIZE, USB_DATA_ALIGN)
  309. #define USB_DATA_ALIGN_SIZE_MULTIPLE(n) ((n + USB_DATA_ALIGN_SIZE - 1) & (~(USB_DATA_ALIGN_SIZE - 1)))
  310. #if defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL)
  311. #define USB_GLOBAL USB_LINK_USB_GLOBAL
  312. #define USB_BDT USB_LINK_USB_BDT
  313. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  314. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  315. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  316. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  317. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  318. #else
  319. #define USB_DMA_DATA_NONINIT_SUB
  320. #define USB_DMA_DATA_INIT_SUB
  321. #define USB_CONTROLLER_DATA USB_LINK_USB_GLOBAL
  322. #endif
  323. #elif defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT)
  324. #define USB_BDT USB_LINK_USB_BDT
  325. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  326. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  327. #define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
  328. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  329. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  330. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  331. #else
  332. #define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
  333. #define USB_DMA_DATA_NONINIT_SUB
  334. #define USB_DMA_DATA_INIT_SUB
  335. #define USB_CONTROLLER_DATA
  336. #endif
  337. #else
  338. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  339. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  340. #define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
  341. #define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
  342. #define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
  343. #define USB_DMA_DATA_INIT_SUB USB_LINK_SECTION_SUB(m_usb_dma_init_data)
  344. #define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
  345. #else
  346. #define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
  347. #define USB_BDT USB_LINK_USB_BDT_BSS
  348. #define USB_DMA_DATA_NONINIT_SUB
  349. #define USB_DMA_DATA_INIT_SUB
  350. #define USB_CONTROLLER_DATA
  351. #endif
  352. #endif
  353. #define USB_DMA_NONINIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_NONINIT_SUB
  354. #define USB_DMA_INIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_INIT_SUB
  355. #if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
  356. (defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
  357. #define USB_DMA_DATA_NONCACHEABLE USB_LINK_NONCACHE_NONINIT_DATA
  358. #else
  359. #define USB_DMA_DATA_NONCACHEABLE
  360. #endif
  361. #define USB_GLOBAL_DEDICATED_RAM USB_LINK_USB_GLOBAL
  362. /* #define USB_RAM_ADDRESS_NONCACHEREG_ALIGNMENT(n, var) AT_NONCACHEABLE_SECTION_ALIGN(var, n) */
  363. /* #define USB_RAM_ADDRESS_NONCACHEREG(var) AT_NONCACHEABLE_SECTION(var) */
  364. #endif /* __USB_MISC_H__ */