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