xref: /minix3/minix/drivers/usb/usbd/include/usbd/usbd_common.h (revision 2d64210c1dbcd340904718f2d4e9e81adeab3c7d)
1 /*
2  * Whatever is commonly used throughout USBD code
3  */
4 
5 #ifndef _USBD_COMMON_H_
6 #define _USBD_COMMON_H_
7 
8 /* For commonly used: NULL, EXIT_*, and stuff like that */
9 #include <stdlib.h>
10 
11 /* Current printf implementation for dumping important messages */
12 #include <stdio.h>
13 
14 /* In case of verbose debug output, enable this: */
15 #if 0
16 #define DEBUG
17 #endif
18 
19 /* This allows us to analyze thread context in
20  * consecutive function calls (DEBUG_DUMP) */
21 #include <ddekit/thread.h>
22 
23 /* Represents current thread's name string */
24 #define HCD_THREAD_NAME ddekit_thread_get_name(ddekit_thread_myself())
25 
26 
27 /*===========================================================================*
28  *    Standard output message                                                *
29  *===========================================================================*/
30 #define USB_MSG(fmt, ...)						\
31 	do {								\
32 		printf("USBD: ");					\
33 		printf(fmt, ##__VA_ARGS__);				\
34 		printf("\n");						\
35 	} while(0)
36 
37 
38 /*===========================================================================*
39  *    Debug helpers                                                          *
40  *===========================================================================*/
41 #ifdef DEBUG
42 #define DEBUG_DUMP							\
43 	do {								\
44 		printf("USBD: [%s -> %s]\n", HCD_THREAD_NAME, __func__);\
45 	} while(0)
46 
47 #define USB_DBG(fmt, ...)						\
48 	do {								\
49 		printf("USBD: [%s -> %s] ", HCD_THREAD_NAME, __func__);	\
50 		printf(fmt, ##__VA_ARGS__);				\
51 		printf("\n");						\
52 	} while(0)
53 
54 #else
55 #define DEBUG_DUMP		((void)0)
56 #define USB_DBG(fmt, ...)	((void)0)
57 #endif
58 
59 
60 /*===========================================================================*
61  *    Assert for USB code                                                    *
62  *===========================================================================*/
63 #define USB_ASSERT(cond, otherwise)					\
64 	do {								\
65 		if (!(cond)) {						\
66 			USB_MSG("ASSERTION ERROR (%s -> %s:%d) - "	\
67 				otherwise, HCD_THREAD_NAME,		\
68 				__func__, __LINE__);			\
69 			exit(EXIT_FAILURE);				\
70 		}							\
71 	} while(0)
72 
73 
74 #endif /* !_USBD_COMMON_H_ */
75