Trim CVS logs and cleanup header info.
[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  * All Rights Reserved.
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.2  2004/05/23 18:21:53  bernie
20  * Trim CVS logs and cleanup header info.
21  *
22  * Revision 1.1  2004/05/23 18:10:11  bernie
23  * Import drv/ modules.
24  *
25  */
26 #ifndef KDEBUG_H
27 #define KDEBUG_H
28
29 #include "compiler.h"
30
31 /* Avoid name clashes with Win32 headers */
32 #ifdef ASSERT
33 #undef ASSERT
34 #endif
35
36 #if defined(_DEBUG)
37         void kdbg_init(void);
38         void kdump(const void *buf, size_t len);
39
40         #ifdef __AVR__
41
42                 #include <avr/pgmspace.h>
43                 void kputs_P(const char *PROGMEM str);
44                 void kprintf_P(const char *PROGMEM fmt, ...) FORMAT(__printf__, 1, 2);
45                 int __assert_P(const char *PROGMEM cond, const char *PROGMEM file, int line);
46                 int __invalid_ptr_P(void *p, const char *PROGMEM name, const char *PROGMEM file, int line);
47                 #define kputs(str)  kputs_P(PSTR(str))
48                 #define kprintf(fmt, ...)  kprintf_P(PSTR(fmt) ,## __VA_ARGS__)
49                 #define __assert(cond, file, line)  __assert_P(PSTR(cond), PSTR(file), (line))
50                 #define __invalid_ptr(p, name, file, line)  __invalid_ptr_P((p), PSTR(name), PSTR(file), (line))
51
52         #else
53                 void kputs(const char *str);
54                 void kprintf(const char * fmt, ...) FORMAT(__printf__, 1, 2);
55                 int __assert(const char *cond, const char *file, int line);
56                 int __invalid_ptr(void *p, const char *name, const char *file, int line);
57         #endif
58
59         void __init_wall(long *wall, int size);
60         int __check_wall(long *wall, int size, const char *name, const char *file, int line);
61
62         #define THIS_FILE                       __FILE__
63         #define ASSERT(x)                       ((x) ? 0 : __assert(#x, THIS_FILE, __LINE__))
64         #define ASSERT_VALID_PTR(p)             ((p >= 0x200) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
65         #define ASSERT_VALID_PTR_OR_NULL(p)     (((p == NULL) || (p >= 0x200)) ? 0 : __invalid_ptr(p, #p, THIS_FILE, __LINE__))
66         #define TRACE                           kprintf("%s()\n", __FUNCTION__)
67         #define TRACEMSG(msg,...)               kprintf("%s(): " msg "\n", __FUNCTION__, ## __VA_ARGS__)
68         #define DB(x)                           x
69
70         /* Walls to detect data corruption */
71         #define WALL_SIZE                       8
72         #define WALL_VALUE                      (long)0xABADCAFEL
73         #define DECLARE_WALL(name,size)         static long name[(size) / sizeof(long)];
74         #define INIT_WALL(name)                 __init_wall((name), countof(name))
75         #define CHECK_WALL(name)                __check_wall((name), countof(name), #name, THIS_FILE, __LINE__)
76
77 #else /* !_DEBUG */
78
79         #define ASSERT(x)
80         #define ASSERT_VALID_PTR(p)
81         #define ASSERT_VALID_PTR_OR_NULL(p)
82         #define TRACE                           do {} while(0)
83         #define TRACEMSG(x,...)                 do {} while(0)
84         #define DB(x)
85
86         #define DECLARE_WALL(name, size)
87         #define INIT_WALL(name)
88         #define CHECK_WALL(name)
89
90 #endif /* !_DEBUG */
91
92 #endif /* KDEBUG_H */