blob: 2c9af2329d36bf2b6541f875b2aa332fde5b7e45 [file] [log] [blame]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001/*****************************************************************************
2
3 AudioScience HPI driver
Eliot Blennerhassett40818b62011-12-22 13:38:32 +13004 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19Debug macros.
20
21*****************************************************************************/
22
23#ifndef _HPIDEBUG_H
24#define _HPIDEBUG_H
25
26#include "hpi_internal.h"
27
28/* Define debugging levels. */
29enum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */
30 HPI_DEBUG_LEVEL_WARNING = 1,
31 HPI_DEBUG_LEVEL_NOTICE = 2,
32 HPI_DEBUG_LEVEL_INFO = 3,
33 HPI_DEBUG_LEVEL_DEBUG = 4,
34 HPI_DEBUG_LEVEL_VERBOSE = 5 /* same printk level as DEBUG */
35};
36
37#define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE
38
39/* an OS can define an extra flag string that is appended to
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130040 the start of each message, eg see linux kernel hpios.h */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020041
42#ifdef SOURCEFILE_NAME
43#define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " "
44#else
45#define FILE_LINE __FILE__ ":" __stringify(__LINE__) " "
46#endif
47
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020048#define HPI_DEBUG_ASSERT(expression) \
49 do { \
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130050 if (!(expression)) { \
51 printk(KERN_ERR FILE_LINE \
52 "ASSERT " __stringify(expression)); \
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020053 } \
54 } while (0)
55
56#define HPI_DEBUG_LOG(level, ...) \
57 do { \
58 if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
59 printk(HPI_DEBUG_FLAG_##level \
60 FILE_LINE __VA_ARGS__); \
61 } \
62 } while (0)
63
64void hpi_debug_init(void);
65int hpi_debug_level_set(int level);
66int hpi_debug_level_get(void);
67/* needed by Linux driver for dynamic debug level changes */
68extern int hpi_debug_level;
69
70void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);
71
72void hpi_debug_data(u16 *pdata, u32 len);
73
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130074#define HPI_DEBUG_DATA(pdata, len) \
75 do { \
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020076 if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
77 hpi_debug_data(pdata, len); \
78 } while (0)
79
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130080#define HPI_DEBUG_MESSAGE(level, phm) \
81 do { \
82 if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
Eliot Blennerhassett1528fbb2011-02-10 17:26:02 +130083 hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130084 FILE_LINE __stringify(level)); \
85 } \
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020086 } while (0)
87
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130088#define HPI_DEBUG_RESPONSE(phr) \
89 do { \
Eliot Blennerhassett1528fbb2011-02-10 17:26:02 +130090 if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \
91 (phr->error)) ||\
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130092 (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \
Eliot Blennerhassett1528fbb2011-02-10 17:26:02 +130093 printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +130094 phr->version, phr->error, phr->specific_error); \
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020095 } while (0)
96
97#ifndef compile_time_assert
98#define compile_time_assert(cond, msg) \
99 typedef char msg[(cond) ? 1 : -1]
100#endif
101
Eliot Blennerhassettf0dcad42011-02-10 17:25:56 +1300102#endif /* _HPIDEBUG_H_ */