4 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2000,2001,2002 Bernardo Innocenti <bernie@codewiz.org>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief Definition of handy debug macros. These macros are no-ops
10 * when the preprocessor symbol _DEBUG isn't defined.
14 * \author Bernardo Innocenti <bernie@develer.com>
19 * Revision 1.4 2004/07/30 14:26:33 rasky
20 * Semplificato l'output dell'ASSERT
21 * Aggiunta ASSERT2 con stringa di help opzionalmente disattivabile
23 * Revision 1.3 2004/06/03 11:27:09 bernie
24 * Add dual-license information.
26 * Revision 1.2 2004/05/23 18:21:53 bernie
27 * Trim CVS logs and cleanup header info.
29 * Revision 1.1 2004/05/23 18:10:11 bernie
30 * Import drv/ modules.
38 /* Avoid name clashes with Win32 headers */
45 void kdump(const void *buf, size_t len);
49 #include <avr/pgmspace.h>
50 void kputs_P(const char *PROGMEM str);
51 void kprintf_P(const char *PROGMEM fmt, ...) FORMAT(__printf__, 1, 2);
52 int __assert_P(const char *PROGMEM cond, const char *PROGMEM file, int line);
53 int __invalid_ptr_P(void *p, const char *PROGMEM name, const char *PROGMEM file, int line);
54 #define kputs(str) kputs_P(PSTR(str))
55 #define kprintf(fmt, ...) kprintf_P(PSTR(fmt) ,## __VA_ARGS__)
56 #define __assert(cond, file, line) __assert_P(PSTR(cond), PSTR(file), (line))
57 #define __invalid_ptr(p, name, file, line) __invalid_ptr_P((p), PSTR(name), PSTR(file), (line))
60 void kputs(const char *str);
61 void kprintf(const char * fmt, ...) FORMAT(__printf__, 1, 2);
62 int __assert(const char *cond, const char *file, int line);
63 int __invalid_ptr(void *p, const char *name, const char *file, int line);
66 void __init_wall(long *wall, int size);
67 int __check_wall(long *wall, int size, const char *name, const char *file, int line);
69 #define THIS_FILE __FILE__
70 #ifndef CONFIG_KDEBUG_ASSERT_NO_TEXT
71 #define ASSERT(x) ((x) ? 0 : __assert(#x, THIS_FILE, __LINE__))
72 #define ASSERT2(x, help) ((x) ? 0 : __assert(help " (" #x ")", THIS_FILE, __LINE__))
74 #define ASSERT(x) ((x) ? 0 : __assert("", THIS_FILE, __LINE__))
75 #define ASSERT2(x, help) ASSERT(x)
78 #define ASSERT_VALID_PTR(p) ((p >= 0x200) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
79 #define ASSERT_VALID_PTR_OR_NULL(p) (((p == NULL) || (p >= 0x200)) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
80 #define TRACE kprintf("%s()\n", __FUNCTION__)
81 #define TRACEMSG(msg,...) kprintf("%s(): " msg "\n", __FUNCTION__, ## __VA_ARGS__)
84 /* Walls to detect data corruption */
86 #define WALL_VALUE (long)0xABADCAFEL
87 #define DECLARE_WALL(name,size) static long name[(size) / sizeof(long)];
88 #define INIT_WALL(name) __init_wall((name), countof(name))
89 #define CHECK_WALL(name) __check_wall((name), countof(name), #name, THIS_FILE, __LINE__)
94 #define ASSERT2(x, help)
95 #define ASSERT_VALID_PTR(p)
96 #define ASSERT_VALID_PTR_OR_NULL(p)
97 #define TRACE do {} while(0)
98 #define TRACEMSG(x,...) do {} while(0)
101 #define DECLARE_WALL(name, size)
102 #define INIT_WALL(name)
103 #define CHECK_WALL(name)
105 INLINE void kdbg_init(void) {}
106 INLINE void kprintf(UNUSED(const char*, fmt), ...) {}
110 #endif /* KDEBUG_H */