TRACE(), TRACEMSG(): Reduce code and data footprint.
[bertos.git] / drv / kdebug.c
index 03a86430787ad181e27902deecde4337b79800a0..a8159022c061159c5bcdca5ba930672f1f61eaef 100755 (executable)
@@ -1,9 +1,9 @@
 /*!
  * \file
  * <!--
- * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
  * Copyright 2000, 2001, 2002 Bernardo Innocenti <bernie@codewiz.org>
- * This file is part of DevLib - See devlib/README for information.
+ * This file is part of DevLib - See README.devlib for information.
  * -->
  *
  * \brief General pourpose debug support for embedded systems (implementation).
 
 /*#*
  *#* $Log$
+ *#* Revision 1.21  2005/02/16 20:29:48  bernie
+ *#* TRACE(), TRACEMSG(): Reduce code and data footprint.
+ *#*
+ *#* Revision 1.20  2005/01/25 08:36:40  bernie
+ *#* kputnum(): Export.
+ *#*
+ *#* Revision 1.19  2004/12/31 17:47:45  bernie
+ *#* Rename UNUSED() to UNUSED_ARG().
+ *#*
  *#* Revision 1.18  2004/12/08 08:52:00  bernie
  *#* Save some more RAM on AVR.
  *#*
@@ -74,8 +83,9 @@
 
 #include <debug.h>
 #include <cpu.h>
-#include "hw.h"
-#include "config.h"
+#include <macros.h> /* for BV() */
+#include <config.h>
+#include <hw.h>
 
 #include <mware/formatwr.h> /* for _formatted_write() */
 
@@ -257,7 +267,7 @@ void kdbg_init(void)
 /*!
  * Output one character to the debug console
  */
-static void __kputchar(char c, UNUSED(void *, unused))
+static void __kputchar(char c, UNUSED_ARG(void *, unused))
 {
        /* Poll while serial buffer is still busy */
        KDBG_WAIT_READY();
@@ -286,19 +296,14 @@ void kputchar(char c)
 }
 
 
-void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...)
+void PGM_FUNC(kvprintf)(const char * PGM_ATTR fmt, va_list ap)
 {
-
 #if CONFIG_PRINTF
-       va_list ap;
-
        /* Mask serial TX intr */
        kdbg_irqsave_t irqsave;
        KDBG_MASK_IRQ(irqsave);
 
-       va_start(ap, fmt);
        PGM_FUNC(_formatted_write)(fmt, __kputchar, 0, ap);
-       va_end(ap);
 
        /* Restore serial TX intr */
        KDBG_RESTORE_IRQ(irqsave);
@@ -308,6 +313,14 @@ void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...)
 #endif /* CONFIG_PRINTF */
 }
 
+void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       PGM_FUNC(kvprintf)(fmt, ap);
+       va_end(ap);
+}
 
 void PGM_FUNC(kputs)(const char * PGM_ATTR str)
 {
@@ -327,7 +340,7 @@ void PGM_FUNC(kputs)(const char * PGM_ATTR str)
 /*!
  * Cheap function to print small integers without using printf().
  */
-static int kputnum(int num)
+int kputnum(int num)
 {
        int output_len = 0;
        int divisor = 10000;
@@ -367,6 +380,22 @@ int PGM_FUNC(__assert)(const char * PGM_ATTR cond, const char * PGM_ATTR file, i
        return 1;
 }
 
+void PGM_FUNC(__trace)(const char * PGM_ATTR name)
+{
+       PGM_FUNC(kputs)(name);
+       PGM_FUNC(kputs)(PSTR("()\n"));
+}
+
+void PGM_FUNC(__tracemsg)(const char * PGM_ATTR name, const char * PGM_ATTR fmt, ...)
+{
+       va_list ap;
+
+       PGM_FUNC(kputs)(name);
+       PGM_FUNC(kputs)(PSTR("(): "));
+       va_start(ap, fmt);
+       PGM_FUNC(kvprintf)(fmt, ap);
+       va_end(ap);
+}
 
 int PGM_FUNC(__invalid_ptr)(void *value, const char * PGM_ATTR name, const char * PGM_ATTR file, int line)
 {