Spelling/grammar fixes.
[bertos.git] / drv / kdebug.h
1 /*!
2  * \file
3  * <!--
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.
7  * -->
8  *
9  * \brief Definition of handy debug macros.  These macros are no-ops
10  *        when the preprocessor symbol _DEBUG isn't defined.
11  *
12  * \version $Id$
13  *
14  * \author Bernardo Innocenti <bernie@develer.com>
15  */
16
17 /*#*
18  *#* $Log$
19  *#* Revision 1.6  2004/08/25 14:12:08  rasky
20  *#* Aggiornato il comment block dei log RCS
21  *#*
22  *#* Revision 1.5  2004/08/24 16:19:08  bernie
23  *#* kputchar(): New public function; Add missing dummy inlines for \!_DEBUG.
24  *#*
25  *#* Revision 1.4  2004/07/30 14:26:33  rasky
26  *#* Semplificato l'output dell'ASSERT
27  *#* Aggiunta ASSERT2 con stringa di help opzionalmente disattivabile
28  *#*
29  *#* Revision 1.3  2004/06/03 11:27:09  bernie
30  *#* Add dual-license information.
31  *#*
32  *#* Revision 1.2  2004/05/23 18:21:53  bernie
33  *#* Trim CVS logs and cleanup header info.
34  *#*
35  *#* Revision 1.1  2004/05/23 18:10:11  bernie
36  *#* Import drv/ modules.
37  *#*
38  *#*/
39 #ifndef KDEBUG_H
40 #define KDEBUG_H
41
42 #include "compiler.h"
43
44 /* Avoid name clashes with Win32 headers */
45 #ifdef ASSERT
46 #undef ASSERT
47 #endif
48
49 #if defined(_DEBUG)
50         void kdbg_init(void);
51         void kputchar(char c);
52         void kdump(const void *buf, size_t len);
53
54         #ifdef __AVR__
55
56                 #include <avr/pgmspace.h>
57                 void kputs_P(const char *PROGMEM str);
58                 void kprintf_P(const char *PROGMEM fmt, ...) FORMAT(__printf__, 1, 2);
59                 int __assert_P(const char *PROGMEM cond, const char *PROGMEM file, int line);
60                 int __invalid_ptr_P(void *p, const char *PROGMEM name, const char *PROGMEM file, int line);
61                 #define kputs(str)  kputs_P(PSTR(str))
62                 #define kprintf(fmt, ...)  kprintf_P(PSTR(fmt) ,## __VA_ARGS__)
63                 #define __assert(cond, file, line)  __assert_P(PSTR(cond), PSTR(file), (line))
64                 #define __invalid_ptr(p, name, file, line)  __invalid_ptr_P((p), PSTR(name), PSTR(file), (line))
65
66         #else
67                 void kputs(const char *str);
68                 void kprintf(const char * fmt, ...) FORMAT(__printf__, 1, 2);
69                 int __assert(const char *cond, const char *file, int line);
70                 int __invalid_ptr(void *p, const char *name, const char *file, int line);
71         #endif
72
73         void __init_wall(long *wall, int size);
74         int __check_wall(long *wall, int size, const char *name, const char *file, int line);
75
76         #define THIS_FILE  __FILE__
77         #ifndef CONFIG_KDEBUG_ASSERT_NO_TEXT
78                 #define ASSERT(x)                   ((x) ? 0 : __assert(#x, THIS_FILE, __LINE__))
79                 #define ASSERT2(x, help)            ((x) ? 0 : __assert(help " (" #x ")", THIS_FILE, __LINE__))
80         #else
81                 #define ASSERT(x)                   ((x) ? 0 : __assert("", THIS_FILE, __LINE__))
82                 #define ASSERT2(x, help)            ASSERT(x)
83         #endif
84
85         #define ASSERT_VALID_PTR(p)             ((p >= 0x200) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
86         #define ASSERT_VALID_PTR_OR_NULL(p)     (((p == NULL) || (p >= 0x200)) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
87         #define TRACE                           kprintf("%s()\n", __FUNCTION__)
88         #define TRACEMSG(msg,...)               kprintf("%s(): " msg "\n", __FUNCTION__, ## __VA_ARGS__)
89         #define DB(x)                           x
90
91         /* Walls to detect data corruption */
92         #define WALL_SIZE                       8
93         #define WALL_VALUE                      (long)0xABADCAFEL
94         #define DECLARE_WALL(name,size)         static long name[(size) / sizeof(long)];
95         #define INIT_WALL(name)                 __init_wall((name), countof(name))
96         #define CHECK_WALL(name)                __check_wall((name), countof(name), #name, THIS_FILE, __LINE__)
97
98 #else /* !_DEBUG */
99
100         #define ASSERT(x)                    do {} while(0)
101         #define ASSERT2(x, help)             do {} while(0)
102         #define ASSERT_VALID_PTR(p)          do {} while(0)
103         #define ASSERT_VALID_PTR_OR_NULL(p)  do {} while(0)
104         #define TRACE                        do {} while(0)
105         #define TRACEMSG(x,...)              do {} while(0)
106         #define DB(x)                        /* nothing */
107
108         #define DECLARE_WALL(name, size)
109         #define INIT_WALL(name)
110         #define CHECK_WALL(name)
111
112         INLINE void kdbg_init(void) { /*nop*/ }
113         INLINE void kputchar(UNUSED(char, c)) { /*nop*/ }
114         INLINE void kputs(UNUSED(const char*, str)) { /*nop*/ }
115         INLINE void kprintf(UNUSED(const char*, fmt), ...) { /*nop*/ }
116
117 #endif /* !_DEBUG */
118
119 #endif /* KDEBUG_H */