Bladeren bron

add DEBUG_printf function

SummerGift 8 jaren geleden
bovenliggende
commit
1f1a99e3f2
2 gewijzigde bestanden met toevoegingen van 28 en 2 verwijderingen
  1. 15 0
      port/mpy_main.c
  2. 13 2
      py/bc.c

+ 15 - 0
port/mpy_main.c

@@ -136,6 +136,21 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
 }
 #endif
 
+#include <stdarg.h>
+
+int DEBUG_printf(const char *format, ...)
+{
+	static char log_buf[512];
+    va_list args;
+
+    /* args point to the first variable parameter */
+    va_start(args, format);
+    /* must use vprintf to print */
+    rt_vsprintf(log_buf, format, args);
+    rt_kprintf("%s", log_buf);
+    va_end(args);
+}
+
 #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
 #include <finsh.h>
 static void python(uint8_t argc, char **argv) {

+ 13 - 2
py/bc.c

@@ -25,9 +25,19 @@
  * THE SOFTWARE.
  */
 
-#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <assert.h>
+
+#include "py/mpconfig.h"
+#include "py/misc.h"
+#include "py/mpstate.h"
+
+#if MICROPY_DEBUG_VERBOSE // print debugging info
+#define DEBUG_printf DEBUG_printf
+#else // don't print debugging info
+#define DEBUG_printf(...) (void)0
+#endif
 
 #include "py/runtime.h"
 #include "py/bc0.h"
@@ -35,6 +45,7 @@
 
 #if MICROPY_DEBUG_VERBOSE // print debugging info
 #define DEBUG_PRINT (1)
+#define DEBUG_printf DEBUG_printf
 #else // don't print debugging info
 #define DEBUG_PRINT (0)
 #define DEBUG_printf(...) (void)0