PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
usb.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
64 #ifndef __USB_H__
65 #define __USB_H__
66 
67 /******************************************************************************/
68 /* Include files */
69 /******************************************************************************/
70 #include "mcu.h"
71 
72 #include "usbconfig.h"
73 #include "string.h"
74 #if (USB_USE_L3 == 1)
75  #include "l3.h"
76  #include "base_types.h"
77 #elif (USB_USE_PDL == 1)
78  #include "pdl.h"
79  #include "base_types.h"
80 #elif defined(FM4_USB0)
81  #include "base_types.h"
82 #elif defined(FM3_USB0)
83  #include "base_types.h"
84 #else
85  #error Not supported configuration
86 #endif
87 
88 
89 /* C binding of definitions if building with C++ compiler */
90 #ifdef __cplusplus
91 extern "C"
92 {
93 #endif
94 
95 
96 
132 
133 /*****************************************************************************/
134 /* Global pre-processor symbols/macros ('#define') */
135 /*****************************************************************************/
136 #if !defined(OFF)
137  #define OFF 0U
138 #endif
139 #if !defined(ON)
140  #define ON 1U
141 #endif
142 
143 #if !defined(USB_USE_PDL)
144 #define USB_USE_PDL 0
145 #endif
146 
147 #if !defined(USB_USE_L3)
148 #define USB_USE_L3 0
149 #endif
150 
151 #if !defined(USB_USES_DMA)
152  #define USB_USES_DMA OFF
153 #endif
154 
155 #if !defined(USB_USE_STANDALONE)
156  #if (USB_USE_PDL == OFF) && (USB_USE_L3 == OFF)
157  #define USB_USE_STANDALONE ON
158  #else
159  #define USB_USE_STANDALONE OFF
160  #endif
161 #endif
162 
163 
164 #if (USB_USE_STANDALONE == ON)
165  #if defined(FM4_USB0_BASE)
166  #define USB0 (*((volatile stc_usbn_t *) FM4_USB0_BASE))
167  #endif
168  #if defined(FM4_USB0_BASE)
169  #define USB1 (*((volatile stc_usbn_t *) FM4_USB1_BASE))
170  #endif
171  #if defined(FM3_USB_BASE)
172  #define USB0 (*((volatile stc_usbn_t *) FM3_USB_BASE))
173  #endif
174  #if defined(FM3_USB0_BASE)
175  #define USB0 (*((volatile stc_usbn_t *) FM3_USB0_BASE))
176  #endif
177  #if defined(FM3_USB0_BASE)
178  #define USB1 (*((volatile stc_usbn_t *) FM3_USB1_BASE))
179  #endif
180 
181  #ifndef USB0_DEVICE_IRQ_ENABLED
182  #define USB0_DEVICE_IRQ_ENABLED 1
183  #endif
184  #ifndef USB0_HOST_IRQ_ENABLED
185  #define USB0_HOST_IRQ_ENABLED 1
186  #endif
187  #ifndef USB1_DEVICE_IRQ_ENABLED
188  #define USB1_DEVICE_IRQ_ENABLED 1
189  #endif
190  #ifndef USB1_HOST_IRQ_ENABLED
191  #define USB1_HOST_IRQ_ENABLED 1
192  #endif
193 
194  #define FM_PERIPHERAL_ENABLE_USB0_HOST USB0_HOST_ENABLED
195  #define FM_PERIPHERAL_ENABLE_USB1_HOST USB1_HOST_ENABLED
196  #define FM_PERIPHERAL_ENABLE_USB0_DEVICE USB0_DEVICE_ENABLED
197  #define FM_PERIPHERAL_ENABLE_USB1_DEVICE USB1_DEVICE_ENABLED
198 #elif (USB_USE_L3 == ON)
199  #if defined(FM4_USB0)
200  #error L3 library is not available for FM4!
201  #endif
202  #define USB0 (*((volatile stc_usbn_t *) L3_USB0_BASE))
203  #define USB1 (*((volatile stc_usbn_t *) L3_USB1_BASE))
204  #if USB_USES_DMA != OFF
205  #undef USB_USES_DMA
206  #define USB_USES_DMA OFF
207  #endif
208  #if defined(L3_IRQ_LEVEL_USB0)
209  #undef IRQ_LEVEL_USB0
210  #define IRQ_LEVEL_USB0 L3_IRQ_LEVEL_USB0
211  #endif
212  #if defined(L3_IRQ_LEVEL_USB1)
213  #undef IRQ_LEVEL_USB1
214  #define IRQ_LEVEL_USB1 L3_IRQ_LEVEL_USB1
215  #endif
216  #ifndef USB0_DEVICE_IRQ_ENABLED
217  #define USB0_DEVICE_IRQ_ENABLED 1
218  #endif
219  #ifndef USB0_HOST_IRQ_ENABLED
220  #define USB0_HOST_IRQ_ENABLED 1
221  #endif
222  #ifndef USB1_DEVICE_IRQ_ENABLED
223  #define USB1_DEVICE_IRQ_ENABLED 1
224  #endif
225  #ifndef USB1_HOST_IRQ_ENABLED
226  #define USB1_HOST_IRQ_ENABLED 1
227  #endif
228  #define FM_PERIPHERAL_ENABLE_USB0_HOST L3_PERIPHERAL_ENABLE_USB0_HOST
229  #define FM_PERIPHERAL_ENABLE_USB0_DEVICE L3_PERIPHERAL_ENABLE_USB0_DEVICE
230  #define FM_PERIPHERAL_ENABLE_USB1_HOST L3_PERIPHERAL_ENABLE_USB1_HOST
231  #define FM_PERIPHERAL_ENABLE_USB1_DEVICE L3_PERIPHERAL_ENABLE_USB1_DEVICE
232 #elif (USB_USE_PDL == ON)
233  #if defined(FM3_USB0) || defined(FM3_USB)
234  #error PDL library is not available for FM3!
235  #endif
236  #if defined(FM4_USB0_BASE)
237  #define USB0 (*((volatile stc_usbn_t *) FM4_USB0_BASE))
238  #endif
239  #if defined(FM4_USB0_BASE)
240  #define USB1 (*((volatile stc_usbn_t *) FM4_USB1_BASE))
241  #endif
242  #if USB_USES_DMA != OFF
243  #undef USB_USES_DMA
244  #define USB_USES_DMA OFF
245  #endif
246 
247  #if defined(PDL_IRQ_LEVEL_USB0)
248  #undef IRQ_LEVEL_USB0
249  #define IRQ_LEVEL_USB0 PDL_IRQ_LEVEL_USB0
250  #endif
251  #if defined(PDL_IRQ_LEVEL_USB1)
252  #undef IRQ_LEVEL_USB1
253  #define IRQ_LEVEL_USB1 PDL_IRQ_LEVEL_USB1
254  #endif
255  #if defined(USB0_DEVICE_IRQ_ENABLED)
256  #undef USB0_DEVICE_IRQ_ENABLED
257  #endif
258  #if defined(USB0_HOST_IRQ_ENABLED)
259  #undef USB0_HOST_IRQ_ENABLED
260  #endif
261  #if defined(USB1_DEVICE_IRQ_ENABLED)
262  #undef USB1_DEVICE_IRQ_ENABLED
263  #endif
264  #if defined(USB1_HOST_IRQ_ENABLED)
265  #undef USB1_HOST_IRQ_ENABLED
266  #endif
267 
268  #define USB0_DEVICE_IRQ_ENABLED PDL_INTERRUPT_ENABLE_USB0_DEVICE
269  #define USB0_HOST_IRQ_ENABLED PDL_INTERRUPT_ENABLE_USB0_HOST
270  #define USB1_DEVICE_IRQ_ENABLED PDL_INTERRUPT_ENABLE_USB1_DEVICE
271  #define USB1_HOST_IRQ_ENABLED PDL_INTERRUPT_ENABLE_USB1_HOST
272 
273  #define FM_PERIPHERAL_ENABLE_USB0_HOST PDL_PERIPHERAL_ENABLE_USB0_HOST
274  #define FM_PERIPHERAL_ENABLE_USB0_DEVICE PDL_PERIPHERAL_ENABLE_USB0_DEVICE
275  #define FM_PERIPHERAL_ENABLE_USB1_HOST PDL_PERIPHERAL_ENABLE_USB1_HOST
276  #define FM_PERIPHERAL_ENABLE_USB1_DEVICE PDL_PERIPHERAL_ENABLE_USB1_DEVICE
277 
278  #ifdef USBDEVICECDCCOM_ENABLED
279  #undef USBDEVICECDCCOM_ENABLED
280  #endif
281  #ifdef USBDEVICEHIDJOYSTICK_ENABLED
282  #undef USBDEVICEHIDJOYSTICK_ENABLED
283  #endif
284  #ifdef USBDEVICEHIDKEYBOARD_ENABLED
285  #undef USBDEVICEHIDKEYBOARD_ENABLED
286  #endif
287  #ifdef USBDEVICEHIDMOUSE_ENABLED
288  #undef USBDEVICEHIDMOUSE_ENABLED
289  #endif
290  #ifdef USBDEVICELIBUSB_ENABLED
291  #undef USBDEVICELIBUSB_ENABLED
292  #endif
293  #ifdef USBDEVICEPRINTER_ENABLED
294  #undef USBDEVICEPRINTER_ENABLED
295  #endif
296 
297 
298  #ifdef USBHOSTHIDCOM_ENABLED
299  #undef USBHOSTHIDCOM_ENABLED
300  #endif
301  #ifdef USBHOSTHIDKEYBOARD_ENABLED
302  #undef USBHOSTHIDKEYBOARD_ENABLED
303  #endif
304  #ifdef USBHOSTHIDMOUSE_ENABLED
305  #undef USBHOSTHIDMOUSE_ENABLED
306  #endif
307  #ifdef USBHOSTMASSSTORAGE_ENABLED
308  #undef USBHOSTMASSSTORAGE_ENABLED
309  #endif
310 
311  #define USBDEVICECDCCOM_ENABLED PDL_USBDEVICECDCCOM_ENABLED
312  #define USBDEVICEHIDCOM_ENABLED PDL_USBDEVICEHIDCOM_ENABLED
313  #define USBDEVICEHIDJOYSTICK_ENABLED PDL_USBDEVICEHIDJOYSTICK_ENABLED
314  #define USBDEVICEHIDKEYBOARD_ENABLED PDL_USBDEVICEHIDKEYBOARD_ENABLED
315  #define USBDEVICEHIDMOUSE_ENABLED PDL_USBDEVICEHIDMOUSE_ENABLED
316  #define USBDEVICELIBUSB_ENABLED PDL_USBDEVICELIBUSB_ENABLED
317  #define USBDEVICEPRINTER_ENABLED PDL_USBDEVICEPRINTER_ENABLED
318 
319  #define USBHOSTHIDCOM_ENABLED PDL_USBHOSTHIDCOM_ENABLED
320  #define USBHOSTHIDKEYBOARD_ENABLED PDL_USBHOSTHIDKEYBOARD_ENABLED
321  #define USBHOSTHIDMOUSE_ENABLED PDL_USBHOSTHIDMOUSE_ENABLED
322  #define USBHOSTMASSSTORAGE_ENABLED PDL_USBHOSTMASSSTORAGE_ENABLED
323 
324 #else
325  #error USB low level driver must be used standalone, with L3 or with PDL
326 #endif
327 
328 #if !defined(FM_PERIPHERAL_ENABLE_USB0_DEVICE)
329  #define FM_PERIPHERAL_ENABLE_USB0_DEVICE OFF
330 #endif
331 
332 #if !defined(FM_PERIPHERAL_ENABLE_USB1_DEVICE)
333  #define FM_PERIPHERAL_ENABLE_USB1_DEVICE OFF
334 #endif
335 
336 #if !defined(FM_PERIPHERAL_ENABLE_USB0_HOST)
337  #define FM_PERIPHERAL_ENABLE_USB0_HOST OFF
338 #endif
339 
340 #if !defined(FM_PERIPHERAL_ENABLE_USB1_HOST)
341  #define FM_PERIPHERAL_ENABLE_USB1_HOST OFF
342 #endif
343 
344 #if (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON) || (FM_PERIPHERAL_ENABLE_USB0_HOST == ON)
345  #define FM_PERIPHERAL_ENABLE_USB0 ON
346 #else
347  #define FM_PERIPHERAL_ENABLE_USB0 OFF
348 #endif
349 
350 #if (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON) || (FM_PERIPHERAL_ENABLE_USB1_HOST == ON)
351  #define FM_PERIPHERAL_ENABLE_USB1 ON
352 #else
353  #define FM_PERIPHERAL_ENABLE_USB1 OFF
354 #endif
355 
356 #if (FM_PERIPHERAL_ENABLE_USB0_HOST == ON) || (FM_PERIPHERAL_ENABLE_USB1_HOST == ON)
357  #define FM_PERIPHERAL_USB_HOST_ENABLED ON
358 #else
359  #define FM_PERIPHERAL_USB_HOST_ENABLED OFF
360  #define USB_DISBALE_HOST_FUNCTIONALITY OFF
361 #endif
362 
363 #if (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON) || (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON)
364  #define FM_PERIPHERAL_USB_DEVICE_ENABLED ON
365 #else
366  #define FM_PERIPHERAL_USB_DEVICE_ENABLED OFF
367  #define USB_DISBALE_DEVICE_FUNCTIONALITY OFF
368 #endif
369 
370 #define USB_ENABLED ((FM_PERIPHERAL_ENABLE_USB0 == ON) || (FM_PERIPHERAL_ENABLE_USB1 == ON))
371 #define USB_INTERFACES_COUNT ((FM_PERIPHERAL_ENABLE_USB0) + (FM_PERIPHERAL_ENABLE_USB1))
372 #define USB_INSTANCE_COUNT ((FM_PERIPHERAL_ENABLE_USB0) + (FM_PERIPHERAL_ENABLE_USB1))
373 #define USB_DEVICE_INTERFACES_COUNT ((FM_PERIPHERAL_ENABLE_USB0_DEVICE) + (FM_PERIPHERAL_ENABLE_USB1_DEVICE))
374 #define USB_HOST_INTERFACES_COUNT ((FM_PERIPHERAL_ENABLE_USB0_HOST) + (FM_PERIPHERAL_ENABLE_USB1_HOST))
375 
376 
377 #if (USEUSBDBG == 1)
378 #include "uart.h"
379 #define USBDBG(x) DBGSPACES(u8DebugDepth); puts(x)
380 #define USBDBGVAL8(x,y) DBGSPACES(u8DebugDepth); puts(x); puthex((uint32_t)y,2); puts("\n")
381 #define USBDBGVAL16(x,y) DBGSPACES(u8DebugDepth); puts(x); puthex((uint32_t)y,4); puts("\n")
382 #define USBDBGVAL32(x,y) DBGSPACES(u8DebugDepth); puts(x); puthex((uint32_t)y,8); puts("\n")
383 #define DBGPROCENTER(x) DBGSPACES(u8DebugDepth); u8DebugDepth++; puts(">"); puts(x);puts("\n");
384 #define DBGPROCRETURN(x) if (u8DebugDepth > 0) u8DebugDepth--;DBGSPACES(u8DebugDepth);puts("<"); puts(x);puts("\n");
385 #define DBGSPACES(x) for(u8Dbgi = 0;u8Dbgi < x*2;u8Dbgi++) putch(' ')
386 volatile extern uint8_t u8DebugDepth;
387 volatile extern uint8_t u8Dbgi;
388 #else
389 #define USBDBG(x)
390 #define USBDBGVAL8(x,y)
391 #define USBDBGVAL16(x,y)
392 #define USBDBGVAL32(x,y)
393 #define DBGPROCENTER(x)
394 #define DBGPROCRETURN(x)
395 #define DBGSPACES(x)
396 #endif
397 
398 #define SETACTIVEFLAG(x) while((x) == FALSE) (x) = TRUE;
399 #define CLEARACTIVEFLAG(x) while((x) == TRUE) (x) = FALSE;
400 
401 #define USB_ZERO_STRUCT(x) memset(&x,0,sizeof(x))
402 #define ZERO_STRUCT(x) memset(&x,0,sizeof(x))
403 
404 #if defined(__USB_C__)
405  #if (USEUSBDBG == 1)
406  volatile uint8_t u8DebugDepth = 0;
407  volatile uint8_t u8Dbgi = 0;
408  #warning USB DEBUG ENABLED
409  #endif
410  #if (USBWARNLEVEL == 2)
411 
412  #warning *************** Library Usage **************************
413  #if (USB_USE_STANDALONE == ON)
414  #warning Info: USB_USE_STANDALONE == ON
415  #else
416  #warning Info: USB_USE_STANDALONE == OFF
417  #endif
418 
419  #if (USB_USE_L3 == ON)
420  #warning Info: USB_USE_L3 == ON
421  #else
422  #warning Info: USB_USE_L3 == OFF
423  #endif
424 
425  #if (USB_USE_PDL == ON)
426  #warning Info: USB_USE_PDL == ON
427  #else
428  #warning Info: USB_USE_PDL == OFF
429  #endif
430 
431  #warning *************** USB Enabled Interfaces *****************
432  #if USB_INTERFACES_COUNT == 0
433  #warning Info: USB_INTERFACES_COUNT == 0
434  #elif USB_INTERFACES_COUNT == 2
435  #warning Info: USB_INTERFACES_COUNT == 2
436  #elif USB_INTERFACES_COUNT == 3
437  #warning Info: USB_INTERFACES_COUNT == 3
438  #elif USB_INTERFACES_COUNT == 4
439  #warning Info: USB_INTERFACES_COUNT == 4
440  #elif USB_INTERFACES_COUNT == 5
441  #warning Info: USB_INTERFACES_COUNT == 5
442  #elif USB_INTERFACES_COUNT == 6
443  #warning Info: USB_INTERFACES_COUNT == 6
444  #endif
445 
446  #if (FM_PERIPHERAL_USB_HOST_ENABLED == OFF)
447  #warning Info: HOST EXCLUDED
448  #endif
449 
450  #if (FM_PERIPHERAL_USB_DEVICE_ENABLED == OFF)
451  #warning Info: DEVICE EXCLUDED
452  #endif
453 
454  #if (FM_PERIPHERAL_ENABLE_USB0_HOST == ON)
455  #warning Info: FM_PERIPHERAL_ENABLE_USB0_HOST == ON
456  #else
457  #warning Info: FM_PERIPHERAL_ENABLE_USB0_HOST == OFF
458  #endif
459 
460  #if (FM_PERIPHERAL_ENABLE_USB1_HOST == ON)
461  #warning Info: FM_PERIPHERAL_ENABLE_USB1_HOST == ON
462  #else
463  #warning Info: FM_PERIPHERAL_ENABLE_USB1_HOST == OFF
464  #endif
465 
466  #if (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON)
467  #warning Info: FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON
468  #else
469  #warning Info: FM_PERIPHERAL_ENABLE_USB0_DEVICE == OFF
470  #endif
471 
472  #if (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON)
473  #warning Info: FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON
474  #else
475  #warning Info: FM_PERIPHERAL_ENABLE_USB1_DEVICE == OFF
476  #endif
477 
478 #warning *************** USB Middleware *************************
479  #if USBDEVICECDCCOM_ENABLED == ON
480  #warning Info: USBDEVICECDCCOM_ENABLED == ON
481  #else
482  #warning Info: USBDEVICECDCCOM_ENABLED == OFF
483  #endif
484 
485  #if USBDEVICEHIDJOYSTICK == ON
486  #warning Info: USBDEVICEHIDJOYSTICK == ON
487  #else
488  #warning Info: USBDEVICEHIDJOYSTICK == OFF
489  #endif
490 
491  #if USBDEVICEHIDKEYBOARD_ENABLED == ON
492  #warning Info: USBDEVICEHIDKEYBOARD_ENABLED == ON
493  #else
494  #warning Info: USBDEVICEHIDKEYBOARD_ENABLED == OFF
495  #endif
496 
497  #if USBDEVICEMOUSE_ENABLED == ON
498  #warning Info: USBDEVICEMOUSE_ENABLED == ON
499  #else
500  #warning Info: USBDEVICEMOUSE_ENABLED == OFF
501  #endif
502 
503  #if USBDEVICELIBUSB_ENABLED == ON
504  #warning Info: USBDEVICELIBUSB_ENABLED == ON
505  #else
506  #warning Info: USBDEVICELIBUSB_ENABLED == OFF
507  #endif
508 
509  #if USBDEVICEPRINTER_ENABLED == ON
510  #warning Info: USBDEVICEPRINTER_ENABLED == ON
511  #else
512  #warning Info: USBDEVICEPRINTER_ENABLED == OFF
513  #endif
514 
515 
516  #if USBHOSTHIDCOM_ENABLED == ON
517  #warning Info: USBHOSTHIDCOM_ENABLED == ON
518  #else
519  #warning Info: USBHOSTHIDCOM_ENABLED == OFF
520  #endif
521 
522  #if USBHOSTHIDKEYBOARD_ENABLED == ON
523  #warning Info: USBHOSTHIDKEYBOARD_ENABLED == ON
524  #else
525  #warning Info: USBHOSTHIDKEYBOARD_ENABLED == OFF
526  #endif
527 
528  #if USBHOSTHIDMOUSE_ENABLED == ON
529  #warning Info: USBHOSTHIDMOUSE_ENABLED == ON
530  #else
531  #warning Info: USBHOSTHIDMOUSE_ENABLED == OFF
532  #endif
533 
534  #if USBHOSTMASSSTORAGE_ENABLED == ON
535  #warning Info: USBHOSTMASSSTORAGE_ENABLED == ON
536  #else
537  #warning Info: USBHOSTMASSSTORAGE_ENABLED == OFF
538  #endif
539 
540  #warning *************** USB IRQ Settings ***********************
541  #if USB0_DEVICE_IRQ_ENABLED == ON
542  #warning Info: USB0_DEVICE_IRQ_ENABLED == ON
543  #else
544  #warning Info: USB0_DEVICE_IRQ_ENABLED == OFF
545  #endif
546  #if USB0_HOST_IRQ_ENABLED == ON
547  #warning Info: USB0_HOST_IRQ_ENABLED == ON
548  #else
549  #warning Info: USB0_HOST_IRQ_ENABLED == OFF
550  #endif
551  #if USB1_DEVICE_IRQ_ENABLED == ON
552  #warning Info: USB1_DEVICE_IRQ_ENABLED == ON
553  #else
554  #warning Info: USB1_DEVICE_IRQ_ENABLED == OFF
555  #endif
556  #if USB1_HOST_IRQ_ENABLED == ON
557  #warning Info: USB1_HOST_IRQ_ENABLED == ON
558  #else
559  #warning Info: USB1_HOST_IRQ_ENABLED == OFF
560  #endif
561  #if IRQ_LEVEL_USB0 == 0
562  #warning Info: IRQ_LEVEL_USB0 == 0
563  #elif IRQ_LEVEL_USB0 == 1
564  #warning Info: IRQ_LEVEL_USB0 == 1
565  #elif IRQ_LEVEL_USB0 == 2
566  #warning Info: IRQ_LEVEL_USB0 == 2
567  #elif IRQ_LEVEL_USB0 == 3
568  #warning Info: IRQ_LEVEL_USB0 == 3
569  #elif IRQ_LEVEL_USB0 == 4
570  #warning Info: IRQ_LEVEL_USB0 == 4
571  #elif IRQ_LEVEL_USB0 == 5
572  #warning Info: IRQ_LEVEL_USB0 == 5
573  #elif IRQ_LEVEL_USB0 == 6
574  #warning Info: IRQ_LEVEL_USB0 == 6
575  #elif IRQ_LEVEL_USB0 == 7
576  #warning Info: IRQ_LEVEL_USB0 == 7
577  #elif IRQ_LEVEL_USB0 == 8
578  #warning Info: IRQ_LEVEL_USB0 == 8
579  #elif IRQ_LEVEL_USB0 == 9
580  #warning Info: IRQ_LEVEL_USB0 == 9
581  #elif IRQ_LEVEL_USB0 == 10
582  #warning Info: IRQ_LEVEL_USB0 == 10
583  #elif IRQ_LEVEL_USB0 == 11
584  #warning Info: IRQ_LEVEL_USB0 == 11
585  #elif IRQ_LEVEL_USB0 == 12
586  #warning Info: IRQ_LEVEL_USB0 == 12
587  #elif IRQ_LEVEL_USB0 == 13
588  #warning Info: IRQ_LEVEL_USB0 == 13
589  #elif IRQ_LEVEL_USB0 == 14
590  #warning Info: IRQ_LEVEL_USB0 == 14
591  #elif IRQ_LEVEL_USB0 == 15
592  #warning Info: IRQ_LEVEL_USB0 == 15
593  #endif
594 
595  #if IRQ_LEVEL_USB1 == 0
596  #warning Info: IRQ_LEVEL_USB1 == 0
597  #elif IRQ_LEVEL_USB1 == 1
598  #warning Info: IRQ_LEVEL_USB1 == 1
599  #elif IRQ_LEVEL_USB1 == 2
600  #warning Info: IRQ_LEVEL_USB1 == 2
601  #elif IRQ_LEVEL_USB1 == 3
602  #warning Info: IRQ_LEVEL_USB1 == 3
603  #elif IRQ_LEVEL_USB1 == 4
604  #warning Info: IRQ_LEVEL_USB1 == 4
605  #elif IRQ_LEVEL_USB1 == 5
606  #warning Info: IRQ_LEVEL_USB1 == 5
607  #elif IRQ_LEVEL_USB1 == 6
608  #warning Info: IRQ_LEVEL_USB1 == 6
609  #elif IRQ_LEVEL_USB1 == 7
610  #warning Info: IRQ_LEVEL_USB1 == 7
611  #elif IRQ_LEVEL_USB1 == 8
612  #warning Info: IRQ_LEVEL_USB1 == 8
613  #elif IRQ_LEVEL_USB1 == 9
614  #warning Info: IRQ_LEVEL_USB1 == 9
615  #elif IRQ_LEVEL_USB1 == 10
616  #warning Info: IRQ_LEVEL_USB1 == 10
617  #elif IRQ_LEVEL_USB1 == 11
618  #warning Info: IRQ_LEVEL_USB1 == 11
619  #elif IRQ_LEVEL_USB1 == 12
620  #warning Info: IRQ_LEVEL_USB1 == 12
621  #elif IRQ_LEVEL_USB1 == 13
622  #warning Info: IRQ_LEVEL_USB1 == 13
623  #elif IRQ_LEVEL_USB1 == 14
624  #warning Info: IRQ_LEVEL_USB1 == 14
625  #elif IRQ_LEVEL_USB1 == 15
626  #warning Info: IRQ_LEVEL_USB1 == 15
627  #endif
628  #endif
629 
630  #if IRQ_LEVEL_USB0 > 15
631  #error IRQ_LEVEL_USB0 must be <= 15
632  #endif
633 
634  #if IRQ_LEVEL_USB1 > 15
635  #error IRQ_LEVEL_USB1 must be <= 15
636  #endif
637 
638 #endif
639 
645 
646 #ifndef FM3MCUTYPE_TYPE0
647  #define FM3MCUTYPE_TYPE0 0
648 #endif
649 #ifndef FM3MCUTYPE_TYPE1
650  #define FM3MCUTYPE_TYPE1 1
651 #endif
652 #ifndef FM3MCUTYPE_TYPE2
653  #define FM3MCUTYPE_TYPE2 2
654 #endif
655 #ifndef FM3MCUTYPE_TYPE3
656  #define FM3MCUTYPE_TYPE3 3
657 #endif
658 #ifndef FM3MCUTYPE_TYPE4
659  #define FM3MCUTYPE_TYPE4 4
660 #endif
661 #ifndef FM3MCUTYPE_TYPE5
662  #define FM3MCUTYPE_TYPE5 5
663 #endif
664 #ifndef FM3MCUTYPE_TYPE6
665  #define FM3MCUTYPE_TYPE6 6
666 #endif
667 #ifndef FM3MCUTYPE_TYPE7
668  #define FM3MCUTYPE_TYPE7 7
669 #endif
670 
671 
672 #ifndef FM4MCUTYPE_TYPE0
673  #define FM4MCUTYPE_TYPE0 0
674 #endif
675 
676 
677 #ifdef FM3_DEVICE_TYPE
678  #ifndef FM3MCUTYPE
679  #define FM3MCUTYPE FM3_DEVICE_TYPE
680  #endif
681 #endif
682 
683 #ifdef FM4_DEVICE_TYPE
684  #ifndef FM4MCUTYPE
685  #define FM4MCUTYPE FM4_DEVICE_TYPE
686  #endif
687 #endif
688 
689 #if (0 == USB_USE_L3)
690  #ifndef FM4MCUTYPE
691  #ifdef _MB9ABXXX_H_
692  #define FM4MCUTYPE FM4MCUTYPE_TYPE0
693  #endif
694  #ifdef _MB9B560R_H_
695  #define FM4MCUTYPE FM4MCUTYPE_TYPE0
696  #endif
697  #endif
698 
699  #ifndef FM3MCUTYPE
700  #ifdef _MB9B120K_H_
701  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
702  #endif
703  #ifdef _MB9B320K_H_
704  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
705  #endif
706  #ifdef _MB9B420K_H_
707  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
708  #endif
709  #ifdef _MB9B520K_H_
710  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
711  #endif
712  #ifdef _MB9B120L_H_
713  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
714  #endif
715  #ifdef _MB9B320L_H_
716  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
717  #endif
718  #ifdef _MB9B420L_H_
719  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
720  #endif
721  #ifdef _MB9B520L_H_
722  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
723  #endif
724  #ifdef _MB9B120M_H_
725  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
726  #endif
727  #ifdef _MB9B320M_H_
728  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
729  #endif
730  #ifdef _MB9B420M_H_
731  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
732  #endif
733  #ifdef _MB9B520M_H_
734  #define FM3MCUTYPE FM3MCUTYPE_TYPE9
735  #endif
736  #ifdef _MB9B500N_H_
737  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
738  #endif
739  #ifdef _MB9B400N_H_
740  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
741  #endif
742  #ifdef _MB9B300N_H_
743  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
744  #endif
745  #ifdef _MB9B100N_H_
746  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
747  #endif
748  #ifdef _MB9B500R_H_
749  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
750  #endif
751  #ifdef _MB9B400R_H_
752  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
753  #endif
754  #ifdef _MB9B300R_H_
755  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
756  #endif
757  #ifdef _MB9B100R_H_
758  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
759  #endif
760  #ifdef _MB9BD10S_H_
761  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
762  #endif
763  #ifdef _MB9B610S_H_
764  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
765  #endif
766  #ifdef _MB9B510S_H_
767  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
768  #endif
769  #ifdef _MB9B410S_H_
770  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
771  #endif
772  #ifdef _MB9B310S_H_
773  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
774  #endif
775  #ifdef _MB9B210S_H_
776  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
777  #endif
778  #ifdef _MB9B110S_H_
779  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
780  #endif
781  #ifdef _MB9BD10T_H_
782  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
783  #endif
784  #ifdef _MB9B610T_H_
785  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
786  #endif
787  #ifdef _MB9B210T_H_
788  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
789  #endif
790  #ifdef _MB9B510T_H_
791  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
792  #endif
793  #ifdef _MB9B410T_H_
794  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
795  #endif
796  #ifdef _MB9B310T_H_
797  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
798  #endif
799  #ifdef _MB9B110T_H_
800  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
801  #endif
802  #ifdef _MB9B510N_H_
803  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
804  #endif
805  #ifdef _MB9B410N_H_
806  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
807  #endif
808  #ifdef _MB9B310N_H_
809  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
810  #endif
811  #ifdef _MB9B110N_H_
812  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
813  #endif
814  #ifdef _MB9B510R_H_
815  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
816  #endif
817  #ifdef _MB9B410R_H_
818  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
819  #endif
820  #ifdef _MB9B310R_H_
821  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
822  #endif
823  #ifdef _MB9B110R_H_
824  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
825  #endif
826  #ifdef _MB9A310K_H_
827  #define FM3MCUTYPE FM3MCUTYPE_TYPE5
828  #endif
829  #ifdef _MB9A110K_H_
830  #define FM3MCUTYPE FM3MCUTYPE_TYPE5
831  #endif
832  #ifdef _MB9A310L_H_
833  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
834  #endif
835  #ifdef _MB9A110L_H_
836  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
837  #endif
838  #ifdef _MB9A310M_H_
839  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
840  #endif
841  #ifdef _MB9A110M_H_
842  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
843  #endif
844  #ifdef _MB9A310N_H_
845  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
846  #endif
847  #ifdef _MB9A100N_H_
848  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
849  #endif
850  #ifdef _MB9A110N_H_
851  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
852  #endif
853  #ifdef _MB9A100R_H_
854  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
855  #endif
856  #ifdef _MB9AB40L_H_
857  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
858  #endif
859  #ifdef _MB9AA40L_H_
860  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
861  #endif
862  #ifdef _MB9A340L_H_
863  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
864  #endif
865  #ifdef _MB9A140L_H_
866  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
867  #endif
868  #ifdef _MB9AB40M_H_
869  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
870  #endif
871  #ifdef _MB9AA40M_H_
872  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
873  #endif
874  #ifdef _MB9A340M_H_
875  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
876  #endif
877  #ifdef _MB9A140M_H_
878  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
879  #endif
880  #ifdef _MB9AB40N_H_
881  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
882  #endif
883  #ifdef _MB9AA40N_H_
884  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
885  #endif
886  #ifdef _MB9A340N_H_
887  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
888  #endif
889  #ifdef _MB9A140N_H_
890  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
891  #endif
892  #ifdef _MB9A150M_H_
893  #define FM3MCUTYPE FM3MCUTYPE_TYPE8
894  #endif
895  #ifdef _MB9A150N_H_
896  #define FM3MCUTYPE FM3MCUTYPE_TYPE8
897  #endif
898  #ifdef _MB9A150R_H_
899  #define FM3MCUTYPE FM3MCUTYPE_TYPE8
900  #endif
901  #ifdef _MB9A130K_H_
902  #define FM3MCUTYPE FM3MCUTYPE_TYPE3
903  #endif
904  #ifdef _MB9A130L_H_
905  #define FM3MCUTYPE FM3MCUTYPE_TYPE3
906  #endif
907  #ifdef _MB9AA30L_H_
908  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
909  #endif
910  #ifdef _MB9AA30M_H_
911  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
912  #endif
913  #ifdef _MB9A130M_H_
914  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
915  #endif
916  #ifdef _MB9AA30N_H_
917  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
918  #endif
919  #ifdef _MB9A130N_H_
920  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
921  #endif
922  #endif
923 #else // (0 == USB_USE_L3)
924  #ifndef FM3MCUTYPE
925  #if (L3_DEVICE_TYPE == L3_TYPE0)
926  #define FM3MCUTYPE FM3MCUTYPE_TYPE0
927  #elif (L3_DEVICE_TYPE == L3_TYPE1)
928  #define FM3MCUTYPE FM3MCUTYPE_TYPE1
929  #elif (L3_DEVICE_TYPE == L3_TYPE2)
930  #define FM3MCUTYPE FM3MCUTYPE_TYPE2
931  #elif (L3_DEVICE_TYPE == L3_TYPE3)
932  #define FM3MCUTYPE FM3MCUTYPE_TYPE3
933  #elif (L3_DEVICE_TYPE == L3_TYPE4)
934  #define FM3MCUTYPE FM3MCUTYPE_TYPE4
935  #elif (L3_DEVICE_TYPE == L3_TYPE5)
936  #define FM3MCUTYPE FM3MCUTYPE_TYPE5
937  #elif (L3_DEVICE_TYPE == L3_TYPE6)
938  #define FM3MCUTYPE FM3MCUTYPE_TYPE6
939  #elif (L3_DEVICE_TYPE == L3_TYPE7)
940  #define FM3MCUTYPE FM3MCUTYPE_TYPE7
941  #endif
942  #endif
943 #endif // (0 == USB_USE_L3)
944 
945 
946 
948 
956 #define USBDESCR_DEVICE 1
957 #define USBDESCR_CONFIG 2
958 #define USBDESCR_STRING 3
959 #define USBDESCR_INTERFACE 4
960 #define USBDESCR_ENDPOINT 5
961 
962 #define USB_DEVREQ_STDTYPE 0x00
963 #define USB_DEVREQ_CLSTYPE 0x20
964 #define USB_DEVREQ_VNDTYPE 0x40
965 
966 #define USB_DEVREQ_GET_DESC 0x06
967 #define USB_DEVREQ_SET_DESC 0x07
968 #define USB_DEVREQ_SET_IDLE 0x0A
969 
970 #define USB_GET_STATUS 0x00
971 #define USB_CLEAR_FEATURE 0x01
972 #define USB_SET_FEATURE 0x03
973 #define USB_SET_ADDRESS 0x05
974 #define USB_GET_DESCRIPTOR 0x06
975 #define USB_SET_DESCRIPTOR 0x07
976 #define USB_GET_CONFIGURATION 0x08
977 #define USB_SET_CONFIGURATION 0x09
978 #define USB_GET_INTERFACE 0x0A
979 #define USB_SET_INTERFACE 0x0B
980 #define USB_SYNCH_FRAME 0x0C
981 
982 #define USBATTR_BUSPOWER 0x80
983 #define USBATTR_SELFPOWER 0xC0
984 #define USBATTR_REMOTEWAKE 0x20
985 
986 #define USB_FUNC_INTR_IN 0xF000
987 #define USB_FUNC_INTR_OUT 0xE000
988 #define USB_FUNC_BULK_IN 0xD000
989 #define USB_FUNC_BULK_OUT 0xC000
990 
991 #define USB_MASK_EPC_PKS 0x007F
992 #define USB_MASK_EPC_PKS1 0x01FF
993 #define USB_MASK_EPC_STAL 0x0200
994 #define USB_MASK_EPC_NULE 0x0400
995 #define USB_MASK_EPC_DMAE 0x0800
996 #define USB_MASK_EPC_DIR 0x1000
997 #define USB_MASK_EPC_TYPE 0x6000
998 #define USB_MASK_EPC_EPEN 0x8000
999 
1000 #define USB_MASK_EPS_DRQIIE 0x4000
1001 #define USB_MASK_EPS_BFINI 0x8000
1002 #define USB_MASK_EPS_SIZE1 0x01FF
1003 #define USB_MASK_EPS_SIZE 0x007F
1004 #define USB_MASK_EPS_SPK 0x0200
1005 #define USB_MASK_EPS_DRQI 0x0400
1006 #define USB_MASK_EPS_DRQO 0x0400
1007 #define USB_MASK_EPS_DRQ 0x0400
1008 #define USB_MASK_EPS_BUSY 0x0800
1009 #define USB_MASK_EPS_SPKIE 0x2000
1010 #define USB_MASK_EPS_DRQIE 0x4000
1011 #define USB_MASK_EPS_DRQOIE 0x4000
1012 #define USB_MASK_EPS_BFINI 0x8000
1013 
1014 #ifndef BITMASK_ISSET
1015 #define BITMASK_ISSET(x,y) ((x & y) > 0)
1016 #endif
1017 
1018 #ifndef BITMASK_ISCLEARED
1019 #define BITMASK_ISCLEARED(x,y) ((x & y) == 0)
1020 #endif
1021 
1022 #ifndef BITMASK_SET
1023 #define BITMASK_SET(x,y) x |= y
1024 #endif
1025 
1026 #ifndef BITMASK_CLEAR
1027 #define BITMASK_CLEAR(x,y) x &= ~y
1028 #endif
1029 
1030 #ifndef __USBBITDEFINITIONS_H__
1031  #define __USBBITDEFINITIONS_H__
1032  #define _UDCC_RST (1 << 7)
1033  #define _UDCC_RESUM (1 << 6)
1034  #define _UDCC_HCONX (1 << 5)
1035  #define _UDCC_USTP (1 << 4)
1036  #define _UDCC_RFBK (1 << 1)
1037  #define _UDCC_PWC (1 << 0)
1038 
1039  #define _EP0C_PKS0 0x7F
1040  #define _EP0C_STAL (1 << 9)
1041 
1042 
1043  #define _EPNC_STAL (1 << 9)
1044  #define _EPNC_NULE (1 << 10)
1045  #define _EPNC_DMAE (1 << 11)
1046  #define _EPNC_DIR (1 << 12)
1047  #define _EPNC_TYPE 0x6000
1048  #define _EPNC_EPEN (1 << 15)
1049 
1050  #define _EP1C_PKS1 0x1FF
1051  #define _EP1C_STAL (1 << 9)
1052  #define _EP1C_NULE (1 << 10)
1053  #define _EP1C_DMAE (1 << 11)
1054  #define _EP1C_DIR (1 << 12)
1055  #define _EP1C_TYPE 0x6000
1056  #define _EP1C_EPEN (1 << 15)
1057 
1058  #define _EP2C_PKS2 0xFF
1059  #define _EP2C_STAL (1 << 9)
1060  #define _EP2C_NULE (1 << 10)
1061  #define _EP2C_DMAE (1 << 11)
1062  #define _EP2C_DIR (1 << 12)
1063  #define _EP2C_TYPE 0x6000
1064  #define _EP2C_EPEN (1 << 15)
1065 
1066  #define _EP3C_PKS3 0xFF
1067  #define _EP3C_STAL (1 << 9)
1068  #define _EP3C_NULE (1 << 10)
1069  #define _EP3C_DMAE (1 << 11)
1070  #define _EP3C_DIR (1 << 12)
1071  #define _EP3C_TYPE 0x6000
1072  #define _EP3C_EPEN (1 << 15)
1073 
1074  #define _EP4C_PKS4 0xFF
1075  #define _EP4C_STAL (1 << 9)
1076  #define _EP4C_NULE (1 << 10)
1077  #define _EP4C_DMAE (1 << 11)
1078  #define _EP4C_DIR (1 << 12)
1079  #define _EP4C_TYPE 0x6000
1080  #define _EP4C_EPEN (1 << 15)
1081 
1082  #define _EP5C_PKS5 0xFF
1083  #define _EP5C_STAL (1 << 9)
1084  #define _EP5C_NULE (1 << 10)
1085  #define _EP5C_DMAE (1 << 11)
1086  #define _EP5C_DIR (1 << 12)
1087  #define _EP5C_TYPE 0x6000
1088  #define _EP5C_EPEN (1 << 15)
1089 
1090  #define _EPC_TYPE_BULK 0x4000
1091  #define _EPC_TYPE_INTERRUPT 0x6000
1092 
1093  #define _UDCS_CONF (1 << 0)
1094  #define _UDCS_SETP (1 << 1)
1095  #define _UDCS_WKUP (1 << 2)
1096  #define _UDCS_BRST (1 << 3)
1097  #define _UDCS_SOF (1 << 4)
1098  #define _UDCS_SUSP (1 << 5)
1099 
1100  #define _UDCIE_CONFIE (1 << 0)
1101  #define _UDCIE_CONFN (1 << 1)
1102  #define _UDCIE_WKUPIE (1 << 2)
1103  #define _UDCIE_BRSTIE (1 << 3)
1104  #define _UDCIE_SOFIE (1 << 4)
1105  #define _UDCIE_SUSPIE (1 << 5)
1106 
1107  #define _EPNS_SPK (1 << 9)
1108  #define _EPNS_DRQ (1 << 10)
1109  #define _EPNS_BUSY (1 << 11)
1110  #define _EPNS_SPKIE (1 << 13)
1111  #define _EPNS_DRQIE (1 << 14)
1112  #define _EPNS_BFINI (1 << 15)
1113 
1114  #define _EP0IS_DRQI (1 << 10)
1115  #define _EP0IS_DRQIIE (1 << 14)
1116  #define _EP0IS_BFINI (1 << 15)
1117 
1118  #define _EP0OS_SIZE 0x7F
1119  #define _EP0OS_SPK (1 << 9)
1120  #define _EP0OS_DRQO (1 << 10)
1121  #define _EP0OS_SPKIE (1 << 13)
1122  #define _EP0OS_DRQOIE (1 << 14)
1123  #define _EP0OS_BFINI (1 << 15)
1124 
1125  #define _EP1S_SIZE 0x1FF
1126  #define _EP1S_SPK (1 << 9)
1127  #define _EP1S_DRQ (1 << 10)
1128  #define _EP1S_BUSY (1 << 11)
1129  #define _EP1S_SPKIE (1 << 13)
1130  #define _EP1S_DRQIE (1 << 14)
1131  #define _EP1S_BFINI (1 << 15)
1132 
1133  #define _EP2S_SIZE 0xFF
1134  #define _EP2S_SPK (1 << 9)
1135  #define _EP2S_DRQ (1 << 10)
1136  #define _EP2S_BUSY (1 << 11)
1137  #define _EP2S_SPKIE (1 << 13)
1138  #define _EP2S_DRQIE (1 << 14)
1139  #define _EP2S_BFINI (1 << 15)
1140 
1141  #define _EP3S_SIZE 0xFF
1142  #define _EP3S_SPK (1 << 9)
1143  #define _EP3S_DRQ (1 << 10)
1144  #define _EP3S_BUSY (1 << 11)
1145  #define _EP3S_SPKIE (1 << 13)
1146  #define _EP3S_DRQIE (1 << 14)
1147  #define _EP3S_BFINI (1 << 15)
1148 
1149  #define _EP4S_SIZE 0xFF
1150  #define _EP4S_SPK (1 << 9)
1151  #define _EP4S_DRQ (1 << 10)
1152  #define _EP4S_BUSY (1 << 11)
1153  #define _EP4S_SPKIE (1 << 13)
1154  #define _EP4S_DRQIE (1 << 14)
1155  #define _EP4S_BFINI (1 << 15)
1156 
1157  #define _EP5S_SIZE 0xFF
1158  #define _EP5S_SPK (1 << 9)
1159  #define _EP5S_DRQ (1 << 10)
1160  #define _EP5S_BUSY (1 << 11)
1161  #define _EP5S_SPKIE (1 << 13)
1162  #define _EP5S_DRQIE (1 << 14)
1163  #define _EP5S_BFINI (1 << 15)
1164 
1165  #define _HCNT_HOST (1 << 0)
1166  #define _HCNT_URST (1 << 1)
1167  #define _HCNT_SOFIRE (1 << 2)
1168  #define _HCNT_DIRE (1 << 3)
1169  #define _HCNT_CNNIRE (1 << 4)
1170  #define _HCNT_CMPIRE (1 << 5)
1171  #define _HCNT_URIRE (1 << 6)
1172  #define _HCNT_RWKIRE (1 << 7)
1173  #define _HCNT_RETRY (1 << 8)
1174  #define _HCNT_CANCEL (1 << 9)
1175  #define _HCNT_SOFSTEP (1 << 10)
1176 
1177  #define _HIRQ_SOFIRQ (1 << 0)
1178  #define _HIRQ_DIRQ (1 << 1)
1179  #define _HIRQ_CNNIRQ (1 << 2)
1180  #define _HIRQ_CMPIRQ (1 << 3)
1181  #define _HIRQ_URIRQ (1 << 4)
1182  #define _HIRQ_RWKIRQ (1 << 5)
1183  #define _HIRQ_TCAN (1 << 7)
1184 
1185  #define _HERR_HS 0x03
1186  #define _HERR_STUFF (1 << 2)
1187  #define _HERR_TGERR (1 << 3)
1188  #define _HERR_CRC (1 << 4)
1189  #define _HERR_TOUT (1 << 5)
1190  #define _HERR_RERR (1 << 6)
1191  #define _HERR_LSTSOF (1 << 7)
1192 
1193  #define _HSTATE_CSTAT (1 << 0)
1194  #define _HSTATE_TMODE (1 << 1)
1195  #define _HSTATE_SUSP (1 << 2)
1196  #define _HSTATE_SOFBUSY (1 << 3)
1197  #define _HSTATE_CLKSEL (1 << 4)
1198  #define _HSTATE_ALIVE (1 << 5)
1199 #endif // __USBBITDEFINITIONS_H__
1200 
1201 #ifndef __IO
1202  #define __IO volatile
1203 #endif
1204 
1205 #ifndef __USBSPEC_H__
1206  #define __USBSPEC_H__
1207 
1208 
1209  #define GET_DESCRIPTOR 0x06
1210  #define USB_DEVICE_DESCRIPTOR_TYPE 0x01
1211  #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
1212  #define USB_STRING_DESCRIPTOR_TYPE 0x03
1213  #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
1214  #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
1215  #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 0x06
1216  #define USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE 0x07
1217  #define USB_HID_DESCRIPTOR_TYPE 0x21
1218 
1219  #define USB_IN_DIRECTION 0x80
1220  #define USB_OUT_DIRECTION 0x00
1221 
1222  #define USB_EP_TYPE_CONTROL 0x00
1223  #define USB_EP_TYPE_ISO 0x01
1224  #define USB_EP_TYPE_BULK 0x02
1225  #define USB_EP_TYPE_INT 0x03
1226 
1227  // Bit-Band alias redefinition for L3 usage
1228  #define bL3_FM3_GPIO_EPFR00_USB0PE *((volatile unsigned int*)(0x4266C024UL))
1229  #define bL3_FM3_GPIO_PFR6_P1 *((volatile unsigned int*)(0x42660304UL))
1230  #define bL3_FM3_GPIO_SPSR_USB0C *((volatile unsigned int*)(0x4266B010UL))
1231  #define bL3_FM3_GPIO_EPFR00_USB1PE *((volatile unsigned int*)(0x4266C034UL))
1232  #define bL3_FM3_GPIO_PFR2_P0 *((volatile unsigned int*)(0x42660100UL))
1233  #define bL3_FM3_GPIO_SPSR_USB1C *((volatile unsigned int*)(0x4266B014UL))
1234 
1235  /******************************************************************************
1236  ** \brief Bitmask USB request type
1237  **
1238  ******************************************************************************/
1239  typedef struct stc_bmRequestType
1240  {
1241  uint8_t Recipient :5;
1242  uint8_t Type :2;
1244 
1246 
1247 
1248  /******************************************************************************
1249  ** \brief USB setup request type
1250  **
1251  ******************************************************************************/
1252  typedef struct stc_usb_request
1253  {
1254  union {
1255  uint8_t bmRequestType;
1257  };
1258  uint8_t bRequest;
1259  uint16_t wValue;
1260  uint16_t wIndex;
1261  uint16_t wLength;
1263 
1264 
1265  /******************************************************************************
1266  ** \brief Setup package
1267  **
1268  ******************************************************************************/
1269  typedef struct stc_usb_setup_package
1270  {
1272  uint8_t* pu8Buffer;
1274 #endif // __USBSPEC_H__
1275 
1276 
1283 
1284 /******************************************************************************
1285  * USB_MODULE
1286  ******************************************************************************/
1287 /* USB_MODULE register bit fields */
1288 typedef struct stc_usbn_hcnt_field
1289 {
1290  __IO uint16_t HOST : 1;
1291  __IO uint16_t URST : 1;
1292  __IO uint16_t SOFIRE : 1;
1293  __IO uint16_t DIRE : 1;
1294  __IO uint16_t CNNIRE : 1;
1295  __IO uint16_t CMPIRE : 1;
1296  __IO uint16_t URIRE : 1;
1297  __IO uint16_t RWKIRE : 1;
1298  __IO uint16_t RETRY : 1;
1299  __IO uint16_t CANCEL : 1;
1300  __IO uint16_t SOFSTEP : 1;
1301 } stc_usbn_hcnt_field_t;
1302 
1303 typedef struct stc_usbn_hcnt0_field
1304 {
1305  __IO uint8_t HOST : 1;
1306  __IO uint8_t URST : 1;
1307  __IO uint8_t SOFIRE : 1;
1308  __IO uint8_t DIRE : 1;
1309  __IO uint8_t CNNIRE : 1;
1310  __IO uint8_t CMPIRE : 1;
1311  __IO uint8_t URIRE : 1;
1312  __IO uint8_t RWKIRE : 1;
1313 } stc_usbn_hcnt0_field_t;
1314 
1315 typedef struct stc_usbn_hcnt1_field
1316 {
1317  __IO uint8_t RETRY : 1;
1318  __IO uint8_t CANCEL : 1;
1319  __IO uint8_t SOFSTEP : 1;
1320 } stc_usbn_hcnt1_field_t;
1321 
1322 typedef struct stc_usbn_hirq_field
1323 {
1324  __IO uint8_t SOFIRQ : 1;
1325  __IO uint8_t DIRQ : 1;
1326  __IO uint8_t CNNIRQ : 1;
1327  __IO uint8_t CMPIRQ : 1;
1328  __IO uint8_t URIRQ : 1;
1329  __IO uint8_t RWKIRQ : 1;
1330  uint8_t RESERVED1 : 1;
1331  __IO uint8_t TCAN : 1;
1332 } stc_usbn_hirq_field_t;
1333 
1334 typedef struct stc_usbn_herr_field
1335 {
1336  __IO uint8_t HS0 : 1;
1337  __IO uint8_t HS1 : 1;
1338  __IO uint8_t STUFF : 1;
1339  __IO uint8_t TGERR : 1;
1340  __IO uint8_t CRC : 1;
1341  __IO uint8_t TOUT : 1;
1342  __IO uint8_t RERR : 1;
1343  __IO uint8_t LSTOF : 1;
1344 } stc_usbn_herr_field_t;
1345 
1346 typedef struct stc_usbn_hstate_field
1347 {
1348  __IO uint8_t CSTAT : 1;
1349  __IO uint8_t TMODE : 1;
1350  __IO uint8_t SUSP : 1;
1351  __IO uint8_t SOFBUSY : 1;
1352  __IO uint8_t CLKSEL : 1;
1353  __IO uint8_t ALIVE : 1;
1354 } stc_usbn_hstate_field_t;
1355 
1356 typedef struct stc_usbn_hfcomp_field
1357 {
1358  __IO uint8_t FRAMECOMP0 : 1;
1359  __IO uint8_t FRAMECOMP1 : 1;
1360  __IO uint8_t FRAMECOMP2 : 1;
1361  __IO uint8_t FRAMECOMP3 : 1;
1362  __IO uint8_t FRAMECOMP4 : 1;
1363  __IO uint8_t FRAMECOMP5 : 1;
1364  __IO uint8_t FRAMECOMP6 : 1;
1365  __IO uint8_t FRAMECOMP7 : 1;
1366 } stc_usbn_hfcomp_field_t;
1367 
1368 typedef struct stc_usbn_hrtimer_field
1369 {
1370  __IO uint16_t RTIMER0 : 1;
1371  __IO uint16_t RTIMER1 : 1;
1372  __IO uint16_t RTIMER2 : 1;
1373  __IO uint16_t RTIMER3 : 1;
1374  __IO uint16_t RTIMER4 : 1;
1375  __IO uint16_t RTIMER5 : 1;
1376  __IO uint16_t RTIMER6 : 1;
1377  __IO uint16_t RTIMER7 : 1;
1378  __IO uint16_t RTIMER8 : 1;
1379  __IO uint16_t RTIMER9 : 1;
1380  __IO uint16_t RTIMER10 : 1;
1381  __IO uint16_t RTIMER11 : 1;
1382  __IO uint16_t RTIMER12 : 1;
1383  __IO uint16_t RTIMER13 : 1;
1384  __IO uint16_t RTIMER14 : 1;
1385  __IO uint16_t RTIMER15 : 1;
1386 } stc_usbn_hrtimer_field_t;
1387 
1388 typedef struct stc_usbn_hrtimer0_field
1389 {
1390  __IO uint8_t RTIMER00 : 1;
1391  __IO uint8_t RTIMER01 : 1;
1392  __IO uint8_t RTIMER02 : 1;
1393  __IO uint8_t RTIMER03 : 1;
1394  __IO uint8_t RTIMER04 : 1;
1395  __IO uint8_t RTIMER05 : 1;
1396  __IO uint8_t RTIMER06 : 1;
1397  __IO uint8_t RTIMER07 : 1;
1398 } stc_usbn_hrtimer0_field_t;
1399 
1400 typedef struct stc_usbn_hrtimer1_field
1401 {
1402  __IO uint8_t RTIMER10 : 1;
1403  __IO uint8_t RTIMER11 : 1;
1404  __IO uint8_t RTIMER12 : 1;
1405  __IO uint8_t RTIMER13 : 1;
1406  __IO uint8_t RTIMER14 : 1;
1407  __IO uint8_t RTIMER15 : 1;
1408  __IO uint8_t RTIMER16 : 1;
1409  __IO uint8_t RTIMER17 : 1;
1410 } stc_usbn_hrtimer1_field_t;
1411 
1412 typedef struct stc_usbn_hrtimer2_field
1413 {
1414  __IO uint8_t RTIMER20 : 1;
1415  __IO uint8_t RTIMER21 : 1;
1416  __IO uint8_t RTIMER22 : 1;
1417 } stc_usbn_hrtimer2_field_t;
1418 
1419 typedef struct stc_usbn_hadr_field
1420 {
1421  __IO uint8_t ADDRESS0 : 1;
1422  __IO uint8_t ADDRESS1 : 1;
1423  __IO uint8_t ADDRESS2 : 1;
1424  __IO uint8_t ADDRESS3 : 1;
1425  __IO uint8_t ADDRESS4 : 1;
1426  __IO uint8_t ADDRESS5 : 1;
1427  __IO uint8_t ADDRESS6 : 1;
1428 } stc_usbn_hadr_field_t;
1429 
1430 typedef struct stc_usbn_heof_field
1431 {
1432  __IO uint16_t EOF0 : 1;
1433  __IO uint16_t EOF1 : 1;
1434  __IO uint16_t EOF2 : 1;
1435  __IO uint16_t EOF3 : 1;
1436  __IO uint16_t EOF4 : 1;
1437  __IO uint16_t EOF5 : 1;
1438  __IO uint16_t EOF6 : 1;
1439  __IO uint16_t EOF7 : 1;
1440  __IO uint16_t EOF8 : 1;
1441  __IO uint16_t EOF9 : 1;
1442  __IO uint16_t EOF10 : 1;
1443  __IO uint16_t EOF11 : 1;
1444  __IO uint16_t EOF12 : 1;
1445  __IO uint16_t EOF13 : 1;
1446  __IO uint16_t EOF14 : 1;
1447  __IO uint16_t EOF15 : 1;
1448 } stc_usbn_heof_field_t;
1449 
1450 typedef struct stc_usbn_heof0_field
1451 {
1452  __IO uint8_t EOF00 : 1;
1453  __IO uint8_t EOF01 : 1;
1454  __IO uint8_t EOF02 : 1;
1455  __IO uint8_t EOF03 : 1;
1456  __IO uint8_t EOF04 : 1;
1457  __IO uint8_t EOF05 : 1;
1458  __IO uint8_t EOF06 : 1;
1459  __IO uint8_t EOF07 : 1;
1460 } stc_usbn_heof0_field_t;
1461 
1462 typedef struct stc_usbn_heof1_field
1463 {
1464  __IO uint8_t EOF10 : 1;
1465  __IO uint8_t EOF11 : 1;
1466  __IO uint8_t EOF12 : 1;
1467  __IO uint8_t EOF13 : 1;
1468  __IO uint8_t EOF14 : 1;
1469  __IO uint8_t EOF15 : 1;
1470 } stc_usbn_heof1_field_t;
1471 
1472 typedef struct stc_usbn_hframe_field
1473 {
1474  __IO uint16_t FRAME0 : 1;
1475  __IO uint16_t FRAME1 : 1;
1476  __IO uint16_t FRAME2 : 1;
1477  __IO uint16_t FRAME3 : 1;
1478  __IO uint16_t FRAME4 : 1;
1479  __IO uint16_t FRAME5 : 1;
1480  __IO uint16_t FRAME6 : 1;
1481  __IO uint16_t FRAME7 : 1;
1482  __IO uint16_t FRAME8 : 1;
1483  __IO uint16_t FRAME9 : 1;
1484  __IO uint16_t FRAME10 : 1;
1485 } stc_usbn_hframe_field_t;
1486 
1487 typedef struct stc_usbn_hframe0_field
1488 {
1489  __IO uint8_t FRAME00 : 1;
1490  __IO uint8_t FRAME01 : 1;
1491  __IO uint8_t FRAME02 : 1;
1492  __IO uint8_t FRAME03 : 1;
1493  __IO uint8_t FRAME04 : 1;
1494  __IO uint8_t FRAME05 : 1;
1495  __IO uint8_t FRAME06 : 1;
1496  __IO uint8_t FRAME07 : 1;
1497 } stc_usbn_hframe0_field_t;
1498 
1499 typedef struct stc_usbn_hframe1_field
1500 {
1501  __IO uint8_t FRAME10 : 1;
1502  __IO uint8_t FRAME11 : 1;
1503  __IO uint8_t FRAME12 : 1;
1504  __IO uint8_t FRAME13 : 1;
1505 } stc_usbn_hframe1_field_t;
1506 
1507 typedef struct stc_usbn_htoken_field
1508 {
1509  __IO uint8_t ENDPT0 : 1;
1510  __IO uint8_t ENDPT1 : 1;
1511  __IO uint8_t ENDPT2 : 1;
1512  __IO uint8_t ENDPT3 : 1;
1513  __IO uint8_t TKNEN0 : 1;
1514  __IO uint8_t TKNEN1 : 1;
1515  __IO uint8_t TKNEN2 : 1;
1516  __IO uint8_t TGGL : 1;
1517 } stc_usbn_htoken_field_t;
1518 
1519 typedef struct stc_usbn_udcc_field
1520 {
1521  __IO uint16_t PWC : 1;
1522  __IO uint16_t RFBK : 1;
1523  uint16_t RESERVED1 : 1;
1524  __IO uint16_t STALCLREN : 1;
1525  __IO uint16_t USTP : 1;
1526  __IO uint16_t HCONX : 1;
1527  __IO uint16_t RESUM : 1;
1528  __IO uint16_t RST : 1;
1529 } stc_usbn_udcc_field_t;
1530 
1531 typedef struct stc_usbn_ep0c_field
1532 {
1533  __IO uint16_t PKS00 : 1;
1534  __IO uint16_t PKS01 : 1;
1535  __IO uint16_t PKS02 : 1;
1536  __IO uint16_t PKS03 : 1;
1537  __IO uint16_t PKS04 : 1;
1538  __IO uint16_t PKS05 : 1;
1539  __IO uint16_t PKS06 : 1;
1540  uint16_t RESERVED1 : 2;
1541  __IO uint16_t STAL : 1;
1542 } stc_usbn_ep0c_field_t;
1543 
1544 typedef struct stc_usbn_ep1c_field
1545 {
1546  __IO uint16_t PKS10 : 1;
1547  __IO uint16_t PKS11 : 1;
1548  __IO uint16_t PKS12 : 1;
1549  __IO uint16_t PKS13 : 1;
1550  __IO uint16_t PKS14 : 1;
1551  __IO uint16_t PKS15 : 1;
1552  __IO uint16_t PKS16 : 1;
1553  __IO uint16_t PKS17 : 1;
1554  __IO uint16_t PKS18 : 1;
1555  __IO uint16_t STAL : 1;
1556  __IO uint16_t NULE : 1;
1557  __IO uint16_t DMAE : 1;
1558  __IO uint16_t DIR : 1;
1559  __IO uint16_t TYPE0 : 1;
1560  __IO uint16_t TYPE1 : 1;
1561  __IO uint16_t EPEN : 1;
1562 } stc_usbn_ep1c_field_t;
1563 
1564 typedef struct stc_usbn_ep2c_field
1565 {
1566  __IO uint16_t PKS20 : 1;
1567  __IO uint16_t PKS21 : 1;
1568  __IO uint16_t PKS22 : 1;
1569  __IO uint16_t PKS23 : 1;
1570  __IO uint16_t PKS24 : 1;
1571  __IO uint16_t PKS25 : 1;
1572  __IO uint16_t PKS26 : 1;
1573  uint16_t RESERVED1 : 2;
1574  __IO uint16_t STAL : 1;
1575  __IO uint16_t NULE : 1;
1576  __IO uint16_t DMAE : 1;
1577  __IO uint16_t DIR : 1;
1578  __IO uint16_t TYPE0 : 1;
1579  __IO uint16_t TYPE1 : 1;
1580  __IO uint16_t EPEN : 1;
1581 } stc_usbn_ep2c_field_t;
1582 
1583 typedef struct stc_usbn_ep3c_field
1584 {
1585  __IO uint16_t PKS30 : 1;
1586  __IO uint16_t PKS31 : 1;
1587  __IO uint16_t PKS32 : 1;
1588  __IO uint16_t PKS33 : 1;
1589  __IO uint16_t PKS34 : 1;
1590  __IO uint16_t PKS35 : 1;
1591  __IO uint16_t PKS36 : 1;
1592  uint16_t RESERVED1 : 2;
1593  __IO uint16_t STAL : 1;
1594  __IO uint16_t NULE : 1;
1595  __IO uint16_t DMAE : 1;
1596  __IO uint16_t DIR : 1;
1597  __IO uint16_t TYPE0 : 1;
1598  __IO uint16_t TYPE1 : 1;
1599  __IO uint16_t EPEN : 1;
1600 } stc_usbn_ep3c_field_t;
1601 
1602 typedef struct stc_usbn_ep4c_field
1603 {
1604  __IO uint16_t PKS40 : 1;
1605  __IO uint16_t PKS41 : 1;
1606  __IO uint16_t PKS42 : 1;
1607  __IO uint16_t PKS43 : 1;
1608  __IO uint16_t PKS44 : 1;
1609  __IO uint16_t PKS45 : 1;
1610  __IO uint16_t PKS46 : 1;
1611  uint16_t RESERVED1 : 2;
1612  __IO uint16_t STAL : 1;
1613  __IO uint16_t NULE : 1;
1614  __IO uint16_t DMAE : 1;
1615  __IO uint16_t DIR : 1;
1616  __IO uint16_t TYPE0 : 1;
1617  __IO uint16_t TYPE1 : 1;
1618  __IO uint16_t EPEN : 1;
1619 } stc_usbn_ep4c_field_t;
1620 
1621 typedef struct stc_usbn_ep5c_field
1622 {
1623  __IO uint16_t PKS50 : 1;
1624  __IO uint16_t PKS51 : 1;
1625  __IO uint16_t PKS52 : 1;
1626  __IO uint16_t PKS53 : 1;
1627  __IO uint16_t PKS54 : 1;
1628  __IO uint16_t PKS55 : 1;
1629  __IO uint16_t PKS56 : 1;
1630  uint16_t RESERVED1 : 2;
1631  __IO uint16_t STAL : 1;
1632  __IO uint16_t NULE : 1;
1633  __IO uint16_t DMAE : 1;
1634  __IO uint16_t DIR : 1;
1635  __IO uint16_t TYPE0 : 1;
1636  __IO uint16_t TYPE1 : 1;
1637  __IO uint16_t EPEN : 1;
1638 } stc_usbn_ep5c_field_t;
1639 
1640 typedef struct stc_usbn_tmsp_field
1641 {
1642  __IO uint16_t TMSP0 : 1;
1643  __IO uint16_t TMSP1 : 1;
1644  __IO uint16_t TMSP2 : 1;
1645  __IO uint16_t TMSP3 : 1;
1646  __IO uint16_t TMSP4 : 1;
1647  __IO uint16_t TMSP5 : 1;
1648  __IO uint16_t TMSP6 : 1;
1649  __IO uint16_t TMSP7 : 1;
1650  __IO uint16_t TMSP8 : 1;
1651  __IO uint16_t TMSP9 : 1;
1652  __IO uint16_t TMSP10 : 1;
1653 } stc_usbn_tmsp_field_t;
1654 
1655 typedef struct stc_usbn_udcs_field
1656 {
1657  __IO uint8_t CONF : 1;
1658  __IO uint8_t SETP : 1;
1659  __IO uint8_t WKUP : 1;
1660  __IO uint8_t BRST : 1;
1661  __IO uint8_t SOF : 1;
1662  __IO uint8_t SUSP : 1;
1663 } stc_usbn_udcs_field_t;
1664 
1665 typedef struct stc_usbn_udcie_field
1666 {
1667  __IO uint8_t CONFIE : 1;
1668  __IO uint8_t CONFN : 1;
1669  __IO uint8_t WKUPIE : 1;
1670  __IO uint8_t BRSTIE : 1;
1671  __IO uint8_t SOFIE : 1;
1672  __IO uint8_t SUSPIE : 1;
1673 } stc_usbn_udcie_field_t;
1674 
1675 typedef struct stc_usbn_ep0is_field
1676 {
1677  uint16_t RESERVED1 : 10;
1678  __IO uint16_t DRQI : 1;
1679  uint16_t RESERVED2 : 3;
1680  __IO uint16_t DRQIIE : 1;
1681  __IO uint16_t BFINI : 1;
1682 } stc_usbn_ep0is_field_t;
1683 
1684 typedef struct stc_usbn_ep0os_field
1685 {
1686  __IO uint16_t SIZE0 : 1;
1687  __IO uint16_t SIZE1 : 1;
1688  __IO uint16_t SIZE2 : 1;
1689  __IO uint16_t SIZE3 : 1;
1690  __IO uint16_t SIZE4 : 1;
1691  __IO uint16_t SIZE5 : 1;
1692  __IO uint16_t SIZE6 : 1;
1693  uint16_t RESERVED1 : 2;
1694  __IO uint16_t SPK : 1;
1695  __IO uint16_t DRQO : 1;
1696  uint16_t RESERVED2 : 2;
1697  __IO uint16_t SPKIE : 1;
1698  __IO uint16_t DRQOIE : 1;
1699  __IO uint16_t BFINI : 1;
1700 } stc_usbn_ep0os_field_t;
1701 
1702 typedef struct stc_usbn_ep1s_field
1703 {
1704  __IO uint16_t SIZE10 : 1;
1705  __IO uint16_t SIZE11 : 1;
1706  __IO uint16_t SIZE12 : 1;
1707  __IO uint16_t SIZE13 : 1;
1708  __IO uint16_t SIZE14 : 1;
1709  __IO uint16_t SIZE15 : 1;
1710  __IO uint16_t SIZE16 : 1;
1711  __IO uint16_t SIZE17 : 1;
1712  __IO uint16_t SIZE18 : 1;
1713  __IO uint16_t SPK : 1;
1714  __IO uint16_t DRQ : 1;
1715  __IO uint16_t BUSY : 1;
1716  uint16_t RESERVED1 : 1;
1717  __IO uint16_t SPKIE : 1;
1718  __IO uint16_t DRQIE : 1;
1719  __IO uint16_t BFINI : 1;
1720 } stc_usbn_ep1s_field_t;
1721 
1722 typedef struct stc_usbn_ep2s_field
1723 {
1724  __IO uint16_t SIZE20 : 1;
1725  __IO uint16_t SIZE21 : 1;
1726  __IO uint16_t SIZE22 : 1;
1727  __IO uint16_t SIZE23 : 1;
1728  __IO uint16_t SIZE24 : 1;
1729  __IO uint16_t SIZE25 : 1;
1730  __IO uint16_t SIZE26 : 1;
1731  uint16_t RESERVED1 : 2;
1732  __IO uint16_t SPK : 1;
1733  __IO uint16_t DRQ : 1;
1734  __IO uint16_t BUSY : 1;
1735  uint16_t RESERVED2 : 1;
1736  __IO uint16_t SPKIE : 1;
1737  __IO uint16_t DRQIE : 1;
1738  __IO uint16_t BFINI : 1;
1739 } stc_usbn_ep2s_field_t;
1740 
1741 typedef struct stc_usbn_ep4s_field
1742 {
1743  __IO uint16_t SIZE40 : 1;
1744  __IO uint16_t SIZE41 : 1;
1745  __IO uint16_t SIZE42 : 1;
1746  __IO uint16_t SIZE43 : 1;
1747  __IO uint16_t SIZE44 : 1;
1748  __IO uint16_t SIZE45 : 1;
1749  __IO uint16_t SIZE46 : 1;
1750  uint16_t RESERVED1 : 2;
1751  __IO uint16_t SPK : 1;
1752  __IO uint16_t DRQ : 1;
1753  __IO uint16_t BUSY : 1;
1754  uint16_t RESERVED2 : 1;
1755  __IO uint16_t SPKIE : 1;
1756  __IO uint16_t DRQIE : 1;
1757  __IO uint16_t BFINI : 1;
1758 } stc_usbn_ep4s_field_t;
1759 
1760 typedef struct stc_usbn_ep5s_field
1761 {
1762  __IO uint16_t SIZE50 : 1;
1763  __IO uint16_t SIZE51 : 1;
1764  __IO uint16_t SIZE52 : 1;
1765  __IO uint16_t SIZE53 : 1;
1766  __IO uint16_t SIZE54 : 1;
1767  __IO uint16_t SIZE55 : 1;
1768  __IO uint16_t SIZE56 : 1;
1769  uint16_t RESERVED1 : 2;
1770  __IO uint16_t SPK : 1;
1771  __IO uint16_t DRQ : 1;
1772  __IO uint16_t BUSY : 1;
1773  uint16_t RESERVED2 : 1;
1774  __IO uint16_t SPKIE : 1;
1775  __IO uint16_t DRQIE : 1;
1776  __IO uint16_t BFINI : 1;
1777 } stc_usbn_ep5s_field_t;
1778 
1779 
1780 typedef struct stc_usbn_epns_field
1781 {
1782  __IO uint16_t SIZE : 8;
1783  __IO uint16_t SPK : 1;
1784  __IO uint16_t DRQ : 1;
1785  __IO uint16_t BUSY : 1;
1786  uint16_t RESERVED1 : 1;
1787  __IO uint16_t SPKIE : 1;
1788  __IO uint16_t DRQIE : 1;
1789  __IO uint16_t BFINI : 1;
1790 } stc_usbn_epns_field_t;
1791 
1792 typedef struct stc_usbn_epns
1793 {
1794  union {
1795  __IO uint16_t EPNS;
1796  stc_usbn_epns_field_t EPNS_f;
1797  };
1798  uint8_t RESERVED[2];
1799 } stc_usbn_epns_t;
1800 
1801 typedef struct stc_usbn_epnc_field
1802 {
1803  __IO uint16_t PKS : 9;
1804  __IO uint16_t STAL : 1;
1805  __IO uint16_t NULE : 1;
1806  __IO uint16_t DMAE : 1;
1807  __IO uint16_t DIR : 1;
1808  __IO uint16_t TYPE0 : 1;
1809  __IO uint16_t TYPE1 : 1;
1810  __IO uint16_t EPEN : 1;
1811 } stc_usbn_epnc_field_t;
1812 
1813 typedef struct stc_usbn_epnc
1814 {
1815  union {
1816  __IO uint16_t EPNC;
1817  stc_usbn_epnc_field_t EPNC_f;
1818  };
1819  uint8_t RESERVED[2];
1820 
1821 } stc_usbn_epnc_t;
1822 
1823 typedef struct stc_usbn_epdt
1824 {
1825  union {
1826  __IO uint16_t EPNDT;
1827  struct {
1828  __IO uint8_t EPNDTL;
1829  __IO uint8_t EPNDTH;
1830  };
1831  };
1832  uint8_t RESERVED[2];
1833 } stc_usbn_epdt_t;
1834 
1835 /******************************************************************************
1836  * USB_MODULE
1837  ******************************************************************************/
1838 /* USB channel 0 registers */
1839 typedef struct stc_usbn
1840 {
1841  union {
1842  union {
1843  __IO uint16_t HCNT;
1844  stc_usbn_hcnt_field_t HCNT_f;
1845  };
1846  struct {
1847  union {
1848  __IO uint8_t HCNT0;
1849  stc_usbn_hcnt0_field_t HCNT0_f;
1850  };
1851  union {
1852  __IO uint8_t HCNT1;
1853  stc_usbn_hcnt1_field_t HCNT1_f;
1854  };
1855  };
1856  };
1857  uint8_t RESERVED0[2];
1858  union {
1859  __IO uint8_t HIRQ;
1860  stc_usbn_hirq_field_t HIRQ_f;
1861  };
1862  union {
1863  __IO uint8_t HERR;
1864  stc_usbn_herr_field_t HERR_f;
1865  };
1866  uint8_t RESERVED1[2];
1867  union {
1868  __IO uint8_t HSTATE;
1869  stc_usbn_hstate_field_t HSTATE_f;
1870  };
1871  union {
1872  __IO uint8_t HFCOMP;
1873  stc_usbn_hfcomp_field_t HFCOMP_f;
1874  };
1875  uint8_t RESERVED2[2];
1876  union {
1877  union {
1878  __IO uint16_t HRTIMER;
1879  stc_usbn_hrtimer_field_t HRTIMER_f;
1880  };
1881  struct {
1882  union {
1883  __IO uint8_t HRTIMER0;
1884  stc_usbn_hrtimer0_field_t HRTIMER0_f;
1885  };
1886  union {
1887  __IO uint8_t HRTIMER1;
1888  stc_usbn_hrtimer1_field_t HRTIMER1_f;
1889  };
1890  };
1891  };
1892  uint8_t RESERVED3[2];
1893  union {
1894  __IO uint8_t HRTIMER2;
1895  stc_usbn_hrtimer2_field_t HRTIMER2_f;
1896  };
1897  union {
1898  __IO uint8_t HADR;
1899  stc_usbn_hadr_field_t HADR_f;
1900  };
1901  uint8_t RESERVED4[2];
1902  union {
1903  union {
1904  __IO uint16_t HEOF;
1905  stc_usbn_heof_field_t HEOF_f;
1906  };
1907  struct {
1908  union {
1909  __IO uint8_t HEOF0;
1910  stc_usbn_heof0_field_t HEOF0_f;
1911  };
1912  union {
1913  __IO uint8_t HEOF1;
1914  stc_usbn_heof1_field_t HEOF1_f;
1915  };
1916  };
1917  };
1918  uint8_t RESERVED5[2];
1919  union {
1920  union {
1921  __IO uint16_t HFRAME;
1922  stc_usbn_hframe_field_t HFRAME_f;
1923  };
1924  struct {
1925  union {
1926  __IO uint8_t HFRAME0;
1927  stc_usbn_hframe0_field_t HFRAME0_f;
1928  };
1929  union {
1930  __IO uint8_t HFRAME1;
1931  stc_usbn_hframe1_field_t HFRAME1_f;
1932  };
1933  };
1934  };
1935  uint8_t RESERVED6[2];
1936  union {
1937  __IO uint8_t HTOKEN;
1938  stc_usbn_htoken_field_t HTOKEN_f;
1939  };
1940  uint8_t RESERVED7[3];
1941  union {
1942  __IO uint16_t UDCC;
1943  stc_usbn_udcc_field_t UDCC_f;
1944  };
1945  uint8_t RESERVED8[2];
1946  union {
1947  __IO uint16_t EP0C;
1948  stc_usbn_ep0c_field_t EP0C_f;
1949  };
1950  uint8_t RESERVED9[2];
1951  union {
1952  __IO uint16_t EP1C;
1953  stc_usbn_ep1c_field_t EP1C_f;
1954  };
1955  uint8_t RESERVED10[2];
1956  union {
1957  __IO uint16_t EP2C;
1958  stc_usbn_ep2c_field_t EP2C_f;
1959  };
1960  uint8_t RESERVED11[2];
1961  union {
1962  __IO uint16_t EP3C;
1963  stc_usbn_ep3c_field_t EP3C_f;
1964  };
1965  uint8_t RESERVED12[2];
1966  union {
1967  __IO uint16_t EP4C;
1968  stc_usbn_ep4c_field_t EP4C_f;
1969  };
1970  uint8_t RESERVED13[2];
1971  union {
1972  __IO uint16_t EP5C;
1973  stc_usbn_ep5c_field_t EP5C_f;
1974  };
1975  uint8_t RESERVED14[2];
1976  union {
1977  __IO uint16_t TMSP;
1978  stc_usbn_tmsp_field_t TMSP_f;
1979  };
1980  uint8_t RESERVED15[2];
1981  union {
1982  __IO uint8_t UDCS;
1983  stc_usbn_udcs_field_t UDCS_f;
1984  };
1985  union {
1986  __IO uint8_t UDCIE;
1987  stc_usbn_udcie_field_t UDCIE_f;
1988  };
1989  uint8_t RESERVED16[2];
1990  union {
1991  __IO uint16_t EP0IS;
1992  stc_usbn_ep0is_field_t EP0IS_f;
1993  };
1994  uint8_t RESERVED17[2];
1995  union {
1996  __IO uint16_t EP0OS;
1997  stc_usbn_ep0os_field_t EP0OS_f;
1998  };
1999  uint8_t RESERVED18[2];
2000  union {
2001  __IO uint16_t EP1S;
2002  stc_usbn_ep1s_field_t EP1S_f;
2003  };
2004  uint8_t RESERVED19[2];
2005  union {
2006  __IO uint16_t EP2S;
2007  stc_usbn_ep2s_field_t EP2S_f;
2008  };
2009  uint8_t RESERVED20[2];
2010  __IO uint16_t EP3S;
2011  uint8_t RESERVED21[2];
2012  union {
2013  __IO uint16_t EP4S;
2014  stc_usbn_ep4s_field_t EP4S_f;
2015  };
2016  uint8_t RESERVED22[2];
2017  union {
2018  __IO uint16_t EP5S;
2019  stc_usbn_ep5s_field_t EP5S_f;
2020  };
2021  uint8_t RESERVED23[2];
2022  union {
2023  __IO uint16_t EP0DT;
2024  struct {
2025  __IO uint8_t EP0DTL;
2026  __IO uint8_t EP0DTH;
2027  };
2028  };
2029  uint8_t RESERVED24[2];
2030  union {
2031  __IO uint16_t EP1DT;
2032  struct {
2033  __IO uint8_t EP1DTL;
2034  __IO uint8_t EP1DTH;
2035  };
2036  };
2037  uint8_t RESERVED25[2];
2038  union {
2039  __IO uint16_t EP2DT;
2040  struct {
2041  __IO uint8_t EP2DTL;
2042  __IO uint8_t EP2DTH;
2043  };
2044  };
2045  uint8_t RESERVED26[2];
2046  union {
2047  __IO uint16_t EP3DT;
2048  struct {
2049  __IO uint8_t EP3DTL;
2050  __IO uint8_t EP3DTH;
2051  };
2052  };
2053  uint8_t RESERVED27[2];
2054  union {
2055  __IO uint16_t EP4DT;
2056  struct {
2057  __IO uint8_t EP4DTL;
2058  __IO uint8_t EP4DTH;
2059  };
2060  };
2061  uint8_t RESERVED28[2];
2062  union {
2063  __IO uint16_t EP5DT;
2064  struct {
2065  __IO uint8_t EP5DTL;
2066  __IO uint8_t EP5DTH;
2067  };
2068  };
2069 } stc_usbn_t;
2070 #define haha123 1
2071 
2072 
2078 /******************************************************************************
2079  ** \brief String Descriptor
2080  **
2081  ******************************************************************************/
2083 {
2084  uint8_t* pu8String;
2085  uint8_t* pu8UniCodeString;
2087 
2088 /******************************************************************************
2089  ** \brief Report Descriptor
2090  **
2091  ******************************************************************************/
2093 {
2094  uint8_t* pu8Descriptor;
2095  uint16_t u16Size;
2097 
2098 /******************************************************************************
2099  ** \brief Timeout handler
2100  **
2101  ** Used to create timeout callbacks via SOF interrupt
2102  **
2103  ******************************************************************************/
2105 {
2106  uint16_t u16TimeOut;
2107  void (* Handler)(stc_usbn_t* pstcUsb);
2109 
2110 
2111 /******************************************************************************
2112  ** \brief GPIO / external interrupt settings enumeration
2113  **
2114  ******************************************************************************/
2116 {
2127 
2128 
2129 /******************************************************************************
2130  ** \brief GPIO settings enumeration
2131  **
2132  ******************************************************************************/
2133 typedef enum en_usb_gpio_param
2134 {
2141 
2142 
2143 /******************************************************************************
2144  ** \brief Device alternative HCONX callback
2145  **
2146  ** \param en_usb_gpio_param_t type of callback
2147  **
2148  ** \return depending of type of callback TRUE or FALSE
2149  **
2150  ******************************************************************************/
2152 
2153 /******************************************************************************
2154  ** \brief Device VBUS callback
2155  **
2156  ** \param en_usb_gpio_param_t type of callback
2157  **
2158  ** \return depending of type of callback TRUE or FALSE
2159  **
2160  ******************************************************************************/
2162 
2163 /******************************************************************************
2164  ** \brief Host VBUS callback
2165  **
2166  ** \param en_usb_gpio_param_t type of callback
2167  **
2168  ** \return depending of type of callback TRUE or FALSE
2169  **
2170  ******************************************************************************/
2172 
2173 /******************************************************************************
2174  ** \brief Host pull-down callback
2175  **
2176  ** \param en_usb_gpio_param_t type of callback
2177  **
2178  ** \return depending of type of callback TRUE or FALSE
2179  **
2180  ******************************************************************************/
2182 
2183 /******************************************************************************
2184  ** \brief Host overcurrent callback
2185  **
2186  ** \param en_usb_gpio_param_t type of callback
2187  **
2188  ** \return depending of type of callback TRUE or FALSE
2189  **
2190  ******************************************************************************/
2192 
2193 
2194 /******************************************************************************
2195  ** \brief USB endpoint type
2196  **
2197  ******************************************************************************/
2198 typedef enum en_usb_ep_type
2199 {
2205 
2206 
2207 /******************************************************************************
2208  ** \brief USB endpoint buffer
2209  **
2210  ******************************************************************************/
2212 {
2213  uint8_t* pu8Buffer;
2214  uint8_t* pu8BufferPos;
2215  uint32_t u32BufferSize;
2216  uint32_t u32DataSize;
2218 
2219 struct stc_usbn_endpoint_data;
2220 struct stc_usb_config;
2221 
2222 /******************************************************************************
2223  ** \brief USB device init callback
2224  **
2225  ** \param pstcUsb USB handle
2226  **
2227  ** \param pstcConfig pointer to configurtion #stc_usb_config_t
2228  **
2229  ******************************************************************************/
2230 typedef void (*usb_device_init_t)(stc_usbn_t* pstcUsb, struct stc_usb_config* pstcConfig);
2231 
2232 /******************************************************************************
2233  ** \brief USB host init callback
2234  **
2235  ** \param pstcUsb USB handle
2236  **
2237  ** \param pstcConfig pointer to configurtion #stc_usb_config_t
2238  **
2239  ******************************************************************************/
2240 typedef void (*usb_host_init_t)(stc_usbn_t* pstcUsb,struct stc_usb_config* pstcConfig);
2241 
2242 /******************************************************************************
2243  ** \brief USB endpoint data transferred callback
2244  **
2245  ** \param pstcUsb USB handle
2246  **
2247  ** \param pstcEndpoint endoint handle
2248  **
2249  ******************************************************************************/
2250 typedef void (*usb_endpoint_datatransferred_func_ptr_t)(stc_usbn_t* pstcUsb, struct stc_usbn_endpoint_data* pstcEndpoint);
2251 
2252 /******************************************************************************
2253  ** \brief USB connect callback
2254  **
2255  ** \param pstcUsb USB handle
2256  **
2257  ******************************************************************************/
2258 typedef void (*usb_connect_func_ptr_t)(stc_usbn_t* pstcUsb);
2259 
2260 /******************************************************************************
2261  ** \brief USB disconnect callback
2262  **
2263  ** \param pstcUsb USB handle
2264  **
2265  ******************************************************************************/
2266 typedef void (*usb_disconnect_func_ptr_t)(stc_usbn_t* pstcUsb);
2267 
2268 /******************************************************************************
2269  ** \brief USB device configuration changed callback
2270  **
2271  ** \param pstcUsb USB handle
2272  **
2273  ******************************************************************************/
2274 typedef void (*usb_conf_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2275 
2276 /******************************************************************************
2277  ** \brief USB device setup received callback
2278  **
2279  ** \param pstcUsb USB handle
2280  **
2281  ******************************************************************************/
2282 typedef void (*usb_setp_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2283 
2284 /******************************************************************************
2285  ** \brief USB suspend callback
2286  **
2287  ** \param pstcUsb USB handle
2288  **
2289  ******************************************************************************/
2290 typedef void (*usb_susp_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2291 
2292 /******************************************************************************
2293  ** \brief USB wakeup callback
2294  **
2295  ** \param pstcUsb USB handle
2296  **
2297  ******************************************************************************/
2298 typedef void (*usb_wkup_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2299 
2300 /******************************************************************************
2301  ** \brief USB bus reset callback
2302  **
2303  ** \param pstcUsb USB handle
2304  **
2305  ******************************************************************************/
2306 typedef void (*usb_brst_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2307 
2308 /******************************************************************************
2309  ** \brief USB start of frame callback
2310  **
2311  ** \param pstcUsb USB handle
2312  **
2313  ******************************************************************************/
2314 typedef void (*usb_sof_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2315 
2316 /******************************************************************************
2317  ** \brief USB host token canceled callback
2318  **
2319  ** \param pstcUsb USB handle
2320  **
2321  ******************************************************************************/
2322 typedef void (*usb_tcan_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2323 
2324 /******************************************************************************
2325  ** \brief USB host remote wakeup callback
2326  **
2327  ** \param pstcUsb USB handle
2328  **
2329  ******************************************************************************/
2330 typedef void (*usb_rwkirq_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2331 
2332 /******************************************************************************
2333  ** \brief USB host bus reset callback
2334  **
2335  ** \param pstcUsb USB handle
2336  **
2337  ******************************************************************************/
2338 typedef void (*usb_urirq_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2339 
2340 /******************************************************************************
2341  ** \brief USB host token complete callback
2342  **
2343  ** \param pstcUsb USB handle
2344  **
2345  ******************************************************************************/
2346 typedef void (*usb_cmpirq_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2347 
2348 /******************************************************************************
2349  ** \brief USB host connect callback
2350  **
2351  ** \param pstcUsb USB handle
2352  **
2353  ******************************************************************************/
2354 typedef void (*usb_cnnirq_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2355 
2356 /******************************************************************************
2357  ** \brief USB host disconnect callback
2358  **
2359  ** \param pstcUsb USB handle
2360  **
2361  ******************************************************************************/
2362 typedef void (*usb_dirq_isr_func_ptr_t)(stc_usbn_t* pstcUsb);
2363 
2370 {
2376 
2377 
2378 /******************************************************************************
2379  ** \brief USB HAL endpoint informations
2380  **
2381  **
2382  ******************************************************************************/
2384 {
2385  volatile uint8_t u8EndpointAddress;
2386  volatile uint16_t u16EndpointSize;
2395  stc_usbn_t* pstcUsbInstance;
2396 
2398 
2401 {
2402  #if (FM_PERIPHERAL_ENABLE_USB0 == ON)
2404  #endif
2405  // Case if no DT instance is selected
2406  #if (FM_PERIPHERAL_ENABLE_USB1 == ON)
2408  #endif
2411 
2414 {
2415 #if USB_USES_DMA_0 == ON
2416  UsbDmaInstanceIndex0,
2417 #endif
2418 #if USB_USES_DMA_1 == ON
2419  UsbDmaInstanceIndex1,
2420 #endif
2421 #if USB_USES_DMA_2 == ON
2422  UsbDmaInstanceIndex2,
2423 #endif
2424 #if USB_USES_DMA_3 == ON
2425  UsbDmaInstanceIndex3,
2426 #endif
2427 #if USB_USES_DMA_4 == ON
2428  UsbDmaInstanceIndex4,
2429 #endif
2430 #if USB_USES_DMA_5 == ON
2431  UsbDmaInstanceIndex5,
2432 #endif
2433 #if USB_USES_DMA_6 == ON
2434  UsbDmaInstanceIndex6,
2435 #endif
2436 #if USB_USES_DMA_7 == ON
2437  UsbDmaInstanceIndex7,
2438 #endif
2441 
2442 /******************************************************************************
2443  ** \brief USB internal data
2444  **
2445  **
2446  ******************************************************************************/
2447 typedef struct stc_usb_intern_data
2448 {
2474  #if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
2476  uint8_t* pu8DeviceDescriptor;
2477  uint8_t* pu8ConfigDescriptor;
2478  #else
2480  #endif
2483 
2486 {
2487  volatile stc_usbn_t* pstcInstance;
2490 
2491 
2498 {
2505 
2506 
2512 typedef enum en_usb_status
2513 {
2518 } en_usb_status_t;
2519 
2527 typedef enum en_usb_mode
2528 {
2533 } en_usb_mode_t;
2534 
2540 typedef enum en_usb_switch
2541 {
2546 } en_usb_switch_t;
2547 
2548 
2555 typedef struct stc_usb_config
2556 {
2559  #if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
2560  uint8_t* pu8DeviceDescriptor;
2561  uint8_t* pu8ConfigDescriptor;
2562  #endif
2582 
2583 #if USB_USES_DMA == ON
2584 
2590 typedef struct stc_usb_dma
2591 {
2592  boolean_t bIsActive;
2593  IRQn_Type u8IRQ;
2594  stc_usbn_endpoint_data_t* pstcEpHandle;
2595  __IO uint32_t* pstcDMACA;
2596  __IO uint32_t* pstcDMACB;
2597  __IO uint32_t* pstcDMACSA;
2598  __IO uint32_t* pstcDMACDA;
2599 
2600 } stc_usb_dma_t;
2601 #endif
2602 
2603 /******************************************************************************/
2604 /* Global variable definitions ('extern') */
2605 /******************************************************************************/
2606 
2609 
2610 #if (USB_ENABLED == ON)
2611 
2612 en_result_t Usb_Configure(stc_usbn_t* pstcUsb, stc_usb_config_t* pstcConfig);
2613 
2614 en_result_t Usb_Init( void );
2615 
2616 en_result_t Usb_SetupHalEndpoint(stc_usbn_t* pstcUsb,uint8_t u8EndpointAddress , uint16_t u16FifoSize, en_usb_ep_type_t enType, boolean_t bInterruptsEnabled);
2617 
2618 en_result_t Usb_SwitchUsb(stc_usbn_t* pstcUsb, en_usb_switch_t enType, uint32_t u32SwitchDelay);
2619 
2620 en_result_t Usb_InitInstance(stc_usbn_t* pstcUsb);
2621 
2622 en_result_t Usb_DeinitInstance(stc_usbn_t* pstcUsb);
2623 
2624 stc_usbn_endpoint_data_t* Usb_GetEndpointPtr(stc_usbn_t* pstcUsb, uint8_t u8EndpointAddress);
2625 
2626 en_result_t Usb_HalSend(stc_usbn_endpoint_data_t* pstcEpHandle, uint8_t* pu8Data, uint16_t u16Size, uint16_t* pu16ByteCount);
2627 
2628 en_result_t Usb_HalReceive(stc_usbn_endpoint_data_t* pstcEpHandle, uint8_t* pu8Data, uint16_t* pu16ByteCount, boolean_t bClearDrq);
2629 
2631 
2633 
2635 
2637 
2639 
2640 uint8_t Usb_GetConfiguration(stc_usbn_t* pstcUsb);
2641 
2642 boolean_t Usb_AddTimeOut(stc_usbn_t* pstcUsb, void (* Handler)(stc_usbn_t* pstcUsb), uint16_t u16TimeOut);
2643 
2644 void Usb_RemoveTimeOut(stc_usbn_t* pstcUsb, void (* Handler)(stc_usbn_t* pstcUsb));
2645 
2647 
2648 #if USB_USES_DMA == ON
2649 en_result_t Usb_HalSendDma(stc_usbn_endpoint_data_t* pstcEpHandle, uint8_t* pu8Data, uint16_t u16Size, uint16_t* pu16ByteCount);
2650 #endif
2651 
2652 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
2653 extern void UsbIrqHandlerF(stc_usbn_t* pstcUsb, stc_usb_intern_data_t* pstcUsbInternData);
2654 #endif
2655 
2656 void Usb_OsTickHandle(void);
2657 
2658 extern void UsbIrqHandler(stc_usbn_t* pstcUsb, stc_usb_intern_data_t* pstcUsbInternData);
2659 
2660 void UsbConfig_UsbInit(void);
2661 
2662 void UsbConfig_SwitchMode(void);
2663 
2664 #endif /* USB_ENABLED == ON */
2665 
2666 #ifdef __cplusplus
2667 }
2668 #endif
2669 
2671 #endif /* __USB_H__ */
2672 /******************************************************************************/
2673 /* EOF (not truncated) */
2674 /******************************************************************************/