/*#*
*#* $Log$
+ *#* Revision 1.6 2004/12/08 08:52:00 bernie
+ *#* Save some more RAM on AVR.
+ *#*
*#* Revision 1.5 2004/12/08 08:04:13 bernie
*#* Doxygen fixes.
*#*
#define UNUSED(type,name) type
#endif
#else /* !OS_HOSTED */
+ #include <config.h>
#include <compiler.h>
#endif /* !OS_HOSTED */
void kdbg_init(void);
void kputchar(char c);
void kdump(const void *buf, size_t len);
+ void __init_wall(long *wall, int size);
#ifdef __AVR__
#include <avr/pgmspace.h>
void kprintf_P(const char *PROGMEM fmt, ...) FORMAT(__printf__, 1, 2);
int __assert_P(const char *PROGMEM cond, const char *PROGMEM file, int line);
int __invalid_ptr_P(void *p, const char *PROGMEM name, const char *PROGMEM file, int line);
+ int __check_wall_P(long *wall, int size, const char * PGM_ATTR name, const char * PGM_ATTR file, int line);
#define kputs(str) kputs_P(PSTR(str))
#define kprintf(fmt, ...) kprintf_P(PSTR(fmt) ,## __VA_ARGS__)
#define __assert(cond, file, line) __assert_P(PSTR(cond), PSTR(file), (line))
#define __invalid_ptr(p, name, file, line) __invalid_ptr_P((p), PSTR(name), PSTR(file), (line))
+ #define __check_wall(wall, size, name, file, line) __check_wall_P(wall, size, PSTR(name), PSTR(file), (line))
#else /* !__AVR__ */
void kputs(const char *str);
void kprintf(const char * fmt, ...) FORMAT(__printf__, 1, 2);
int __assert(const char *cond, const char *file, int line);
int __invalid_ptr(void *p, const char *name, const char *file, int line);
+ int __check_wall(long *wall, int size, const char *name, const char *file, int line);
#endif /* !__AVR__ */
- void __init_wall(long *wall, int size);
- int __check_wall(long *wall, int size, const char *name, const char *file, int line);
-
#ifndef CONFIG_KDEBUG_ASSERT_NO_TEXT
#define ASSERT(x) ((void)(LIKELY(x) ? 0 : __assert(#x, THIS_FILE, __LINE__)))
#define ASSERT2(x, help) ((void)(LIKELY(x) ? 0 : __assert(help " (" #x ")", THIS_FILE, __LINE__)))
/*#*
*#* $Log$
+ *#* Revision 1.18 2004/12/08 08:52:00 bernie
+ *#* Save some more RAM on AVR.
+ *#*
*#* Revision 1.17 2004/10/03 18:41:28 bernie
*#* Restore \version header killed by mistake in previous commit.
*#*
void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...)
{
+
+#if CONFIG_PRINTF
va_list ap;
/* Mask serial TX intr */
/* Restore serial TX intr */
KDBG_RESTORE_IRQ(irqsave);
+#else
+ /* A better than nothing printf() surrogate. */
+ PGM_FUNC(kputs)(fmt);
+#endif /* CONFIG_PRINTF */
}
}
-int PGM_FUNC(__assert)(const char * PGM_ATTR cond, const char * PGM_ATTR file, int line)
+/*!
+ * Cheap function to print small integers without using printf().
+ */
+static int kputnum(int num)
+{
+ int output_len = 0;
+ int divisor = 10000;
+ int digit;
+
+ do
+ {
+ digit = num / divisor;
+ num %= divisor;
+
+ if (digit || output_len || divisor == 1)
+ {
+ kputchar(digit + '0');
+ ++output_len;
+ }
+ }
+ while (divisor /= 10);
+
+ return output_len;
+}
+
+
+static void klocation(const char * PGM_ATTR file, int line)
{
PGM_FUNC(kputs)(file);
- PGM_FUNC(kprintf)(PSTR(":%d: Assertion failed: "), line);
+ kputchar(':');
+ kputnum(line);
+ PGM_FUNC(kputs)(PSTR(": "));
+}
+
+int PGM_FUNC(__assert)(const char * PGM_ATTR cond, const char * PGM_ATTR file, int line)
+{
+ klocation(file, line);
+ PGM_FUNC(kputs)(PSTR("Assertion failed: "));
PGM_FUNC(kputs)(cond);
- PGM_FUNC(kputs)(PSTR("\n"));
+ kputchar('\n');
return 1;
}
int PGM_FUNC(__invalid_ptr)(void *value, const char * PGM_ATTR name, const char * PGM_ATTR file, int line)
{
- PGM_FUNC(kputs)(file);
- PGM_FUNC(kprintf)(PSTR(":%d: Invalid pointer: "), line);
+ klocation(file, line);
+ PGM_FUNC(kputs)(PSTR("Invalid ptr: "));
PGM_FUNC(kputs)(name);
- PGM_FUNC(kprintf)(PSTR(" = 0x%x\n"), value);
+ #if CONFIG_PRINTF
+ PGM_FUNC(kprintf)(PSTR(" = 0x%x\n"), value);
+ #else
+ (void)value;
+ kputchar('\n');
+ #endif
return 1;
}
}
-int __check_wall(long *wall, int size, const char *name, const char *file, int line)
+int PGM_FUNC(__check_wall)(long *wall, int size, const char * PGM_ATTR name, const char * PGM_ATTR file, int line)
{
int i, fail = 0;
{
if (wall[i] != WALL_VALUE)
{
- kprintf("%s:%d: Wall broken: %s[%d] (0x%p) = 0x%lx\n",
- file, line, name, i, wall + i, wall[i]);
+ klocation(file, line);
+ PGM_FUNC(kputs)(PSTR("Wall broken: "));
+ PGM_FUNC(kputs)(name);
+ #if CONFIG_PRINTF
+ PGM_FUNC(kprintf)(PSTR("[%d] (0x%p) = 0x%lx\n"), i, wall + i, wall[i]);
+ #else
+ kputchar('\n');
+ #endif
fail = 1;
}
}
}
+#if CONFIG_PRINTF
+
/*!
* Dump binary data in hex
*/
kputchar('\n');
}
+#endif /* CONFIG_PRINTF */
+
#endif /* _DEBUG */