Ver código fonte

update(common/usb_log): update USB_ASSERT

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 8 meses atrás
pai
commit
644ac2b37f
1 arquivos alterados com 23 adições e 6 exclusões
  1. 23 6
      common/usb_log.h

+ 23 - 6
common/usb_log.h

@@ -75,12 +75,29 @@
 
 #define USB_LOG_RAW(...) CONFIG_USB_PRINTF(__VA_ARGS__)
 
-void usb_assert(const char *filename, int linenum);
-#define USB_ASSERT(f)                       \
-    do {                                    \
-        if (!(f))                           \
-            usb_assert(__FILE__, __LINE__); \
-    } while (0)
+#ifndef CONFIG_USB_ASSERT_DISABLE
+#define USB_ASSERT(f)                                                            \
+    do {                                                                         \
+        if (!(f)) {                                                              \
+            USB_LOG_ERR("ASSERT FAIL [%s] @ %s:%d\r\n", #f, __FILE__, __LINE__); \
+            while (1) {                                                          \
+            }                                                                    \
+        }                                                                        \
+    } while (false)
+
+#define USB_ASSERT_MSG(f, fmt, ...)                                              \
+    do {                                                                         \
+        if (!(f)) {                                                              \
+            USB_LOG_ERR("ASSERT FAIL [%s] @ %s:%d\r\n", #f, __FILE__, __LINE__); \
+            USB_LOG_ERR(fmt "\r\n", ##__VA_ARGS__);                              \
+            while (1) {                                                          \
+            }                                                                    \
+        }                                                                        \
+    } while (false)
+#else
+#define USB_ASSERT(f) {}
+#define USB_ASSERT_MSG(f, fmt, ...) {}
+#endif
 
 #define ___is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
 static inline void usb_hexdump(const void *ptr, uint32_t buflen)