From 06f0503a2066ab4fd13529b8ed8906e52b1d672b Mon Sep 17 00:00:00 2001 From: bernie Date: Wed, 8 Dec 2004 08:52:00 +0000 Subject: [PATCH] Save some more RAM on AVR. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@302 38d2e660-2303-0410-9eaa-f027e97ec537 --- debug.h | 11 +++++--- drv/kdebug.c | 76 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/debug.h b/debug.h index 86d6820c..66967a7b 100755 --- a/debug.h +++ b/debug.h @@ -17,6 +17,9 @@ /*#* *#* $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. *#* @@ -73,6 +76,7 @@ #define UNUSED(type,name) type #endif #else /* !OS_HOSTED */ + #include #include #endif /* !OS_HOSTED */ @@ -175,6 +179,7 @@ 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 @@ -182,20 +187,20 @@ 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__))) diff --git a/drv/kdebug.c b/drv/kdebug.c index 88554e95..03a86430 100755 --- a/drv/kdebug.c +++ b/drv/kdebug.c @@ -15,6 +15,9 @@ /*#* *#* $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. *#* @@ -285,6 +288,8 @@ void kputchar(char c) void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...) { + +#if CONFIG_PRINTF va_list ap; /* Mask serial TX intr */ @@ -297,6 +302,10 @@ void PGM_FUNC(kprintf)(const char * PGM_ATTR fmt, ...) /* Restore serial TX intr */ KDBG_RESTORE_IRQ(irqsave); +#else + /* A better than nothing printf() surrogate. */ + PGM_FUNC(kputs)(fmt); +#endif /* CONFIG_PRINTF */ } @@ -315,22 +324,61 @@ void PGM_FUNC(kputs)(const char * PGM_ATTR str) } -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; } @@ -342,7 +390,7 @@ void __init_wall(long *wall, int size) } -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; @@ -350,8 +398,14 @@ int __check_wall(long *wall, int size, const char *name, const char *file, int l { 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; } } @@ -360,6 +414,8 @@ int __check_wall(long *wall, int size, const char *name, const char *file, int l } +#if CONFIG_PRINTF + /*! * Dump binary data in hex */ @@ -372,4 +428,6 @@ void kdump(const void *_buf, size_t len) kputchar('\n'); } +#endif /* CONFIG_PRINTF */ + #endif /* _DEBUG */ -- 2.25.1