1 //------------------------------------------------------------------------------
2 // <copyright file="a_debug.h" company="Atheros">
3 // Copyright (c) 2004-2010 Atheros Corporation. All rights reserved.
6 // Permission to use, copy, modify, and/or distribute this software for any
7 // purpose with or without fee is hereby granted, provided that the above
8 // copyright notice and this permission notice appear in all copies.
10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
28 #endif /* __cplusplus */
33 /* standard debug print masks bits 0..7 */
34 #define ATH_DEBUG_ERR (1 << 0) /* errors */
35 #define ATH_DEBUG_WARN (1 << 1) /* warnings */
36 #define ATH_DEBUG_INFO (1 << 2) /* informational (module startup info) */
37 #define ATH_DEBUG_TRC (1 << 3) /* generic function call tracing */
38 #define ATH_DEBUG_RSVD1 (1 << 4)
39 #define ATH_DEBUG_RSVD2 (1 << 5)
40 #define ATH_DEBUG_RSVD3 (1 << 6)
41 #define ATH_DEBUG_RSVD4 (1 << 7)
43 #define ATH_DEBUG_MASK_DEFAULTS (ATH_DEBUG_ERR | ATH_DEBUG_WARN)
44 #define ATH_DEBUG_ANY 0xFFFF
46 /* other aliases used throughout */
47 #define ATH_DEBUG_ERROR ATH_DEBUG_ERR
48 #define ATH_LOG_ERR ATH_DEBUG_ERR
49 #define ATH_LOG_INF ATH_DEBUG_INFO
50 #define ATH_LOG_TRC ATH_DEBUG_TRC
51 #define ATH_DEBUG_TRACE ATH_DEBUG_TRC
52 #define ATH_DEBUG_INIT ATH_DEBUG_INFO
54 /* bits 8..31 are module-specific masks */
55 #define ATH_DEBUG_MODULE_MASK_SHIFT 8
57 /* macro to make a module-specific masks */
58 #define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
60 void DebugDumpBytes(A_UCHAR *buffer, A_UINT16 length, char *pDescription);
62 /* Debug support on a per-module basis
66 * Each module can utilize it's own debug mask variable. A set of commonly used
67 * masks are provided (ERRORS, WARNINGS, TRACE etc..). It is up to each module
68 * to define module-specific masks using the macros above.
70 * Each module defines a single debug mask variable debug_XXX where the "name" of the module is
71 * common to all C-files within that module. This requires every C-file that includes a_debug.h
72 * to define the module name in that file.
76 * #define ATH_MODULE_NAME htc
77 * #include "a_debug.h"
79 * This will define a debug mask structure called debug_htc and all debug macros will reference this
82 * A module can define module-specific bit masks using the ATH_DEBUG_MAKE_MODULE_MASK() macro:
84 * #define ATH_DEBUG_MY_MASK1 ATH_DEBUG_MAKE_MODULE_MASK(0)
85 * #define ATH_DEBUG_MY_MASK2 ATH_DEBUG_MAKE_MODULE_MASK(1)
87 * The instantiation of the debug structure should be made by the module. When a module is
88 * instantiated, the module can set a description string, a default mask and an array of description
89 * entries containing information on each module-defined debug mask.
90 * NOTE: The instantiation is statically allocated, only one instance can exist per module.
95 * #define ATH_DEBUG_BMI ATH_DEBUG_MAKE_MODULE_MASK(0)
98 * static ATH_DEBUG_MASK_DESCRIPTION bmi_debug_desc[] = {
99 * { ATH_DEBUG_BMI , "BMI Tracing"}, <== description of the module specific mask
102 * ATH_DEBUG_INSTANTIATE_MODULE_VAR(bmi,
103 * "bmi" <== module name
104 * "Boot Manager Interface", <== description of module
105 * ATH_DEBUG_MASK_DEFAULTS, <== defaults
106 * ATH_DEBUG_DESCRIPTION_COUNT(bmi_debug_desc),
111 * A module can optionally register it's debug module information in order for other tools to change the
112 * bit mask at runtime. A module can call A_REGISTER_MODULE_DEBUG_INFO() in it's module
113 * init code. This macro can be called multiple times without consequence. The debug info maintains
114 * state to indicate whether the information was previously registered.
118 #define ATH_DEBUG_MAX_MASK_DESC_LENGTH 32
119 #define ATH_DEBUG_MAX_MOD_DESC_LENGTH 64
123 A_CHAR Description[ATH_DEBUG_MAX_MASK_DESC_LENGTH];
124 } ATH_DEBUG_MASK_DESCRIPTION;
126 #define ATH_DEBUG_INFO_FLAGS_REGISTERED (1 << 0)
128 typedef struct _ATH_DEBUG_MODULE_DBG_INFO{
129 struct _ATH_DEBUG_MODULE_DBG_INFO *pNext;
130 A_CHAR ModuleName[16];
131 A_CHAR ModuleDescription[ATH_DEBUG_MAX_MOD_DESC_LENGTH];
133 A_UINT32 CurrentMask;
135 ATH_DEBUG_MASK_DESCRIPTION *pMaskDescriptions; /* pointer to array of descriptions */
136 } ATH_DEBUG_MODULE_DBG_INFO;
138 #define ATH_DEBUG_DESCRIPTION_COUNT(d) (int)((sizeof((d))) / (sizeof(ATH_DEBUG_MASK_DESCRIPTION)))
140 #define GET_ATH_MODULE_DEBUG_VAR_NAME(s) _XGET_ATH_MODULE_NAME_DEBUG_(s)
141 #define GET_ATH_MODULE_DEBUG_VAR_MASK(s) _XGET_ATH_MODULE_NAME_DEBUG_(s).CurrentMask
142 #define _XGET_ATH_MODULE_NAME_DEBUG_(s) debug_ ## s
144 #ifdef ATH_DEBUG_MODULE
146 /* for source files that will instantiate the debug variables */
147 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions) \
148 ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s) = \
149 {NULL,(name),(moddesc),0,(initmask),count,(descriptions)}
151 #ifdef ATH_MODULE_NAME
152 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(ATH_MODULE_NAME);
153 #define AR_DEBUG_LVL_CHECK(lvl) (GET_ATH_MODULE_DEBUG_VAR_MASK(ATH_MODULE_NAME) & (lvl))
154 #endif /* ATH_MODULE_NAME */
156 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl) GET_ATH_MODULE_DEBUG_VAR_MASK(s) = (lvl)
158 #define ATH_DEBUG_DECLARE_EXTERN(s) \
159 extern ATH_DEBUG_MODULE_DBG_INFO GET_ATH_MODULE_DEBUG_VAR_NAME(s)
161 #define AR_DEBUG_PRINTBUF(buffer, length, desc) DebugDumpBytes(buffer,length,desc)
164 #define AR_DEBUG_ASSERT A_ASSERT
166 void a_dump_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
167 void a_register_module_debug_info(ATH_DEBUG_MODULE_DBG_INFO *pInfo);
168 #define A_DUMP_MODULE_DEBUG_INFO(s) a_dump_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
169 #define A_REGISTER_MODULE_DEBUG_INFO(s) a_register_module_debug_info(&(GET_ATH_MODULE_DEBUG_VAR_NAME(s)))
171 #else /* !ATH_DEBUG_MODULE */
172 /* NON ATH_DEBUG_MODULE */
173 #define ATH_DEBUG_INSTANTIATE_MODULE_VAR(s,name,moddesc,initmask,count,descriptions)
174 #define AR_DEBUG_LVL_CHECK(lvl) 0
175 #define AR_DEBUG_PRINTBUF(buffer, length, desc)
176 #define AR_DEBUG_ASSERT(test)
177 #define ATH_DEBUG_DECLARE_EXTERN(s)
178 #define ATH_DEBUG_SET_DEBUG_MASK(s,lvl)
179 #define A_DUMP_MODULE_DEBUG_INFO(s)
180 #define A_REGISTER_MODULE_DEBUG_INFO(s)
184 A_STATUS a_get_module_mask(A_CHAR *module_name, A_UINT32 *pMask);
185 A_STATUS a_set_module_mask(A_CHAR *module_name, A_UINT32 Mask);
186 void a_dump_module_debug_info_by_name(A_CHAR *module_name);
187 void a_module_debug_support_init(void);
188 void a_module_debug_support_cleanup(void);
191 #include "../os/windows/include/debug.h"
194 #ifdef ATHR_CE_LEGACY
195 #include "../os/windows/include/debug.h"
198 #if defined(__linux__) && !defined(LINUX_EMULATION)
199 #include "../os/linux/include/debug_linux.h"
203 #include "../os/rexos/include/common/debug_rexos.h"
207 #include "../os/win_art/include/debug_win.h"
211 #include <debug_win.h>
215 #define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index)))
216 #include "../os/threadx/include/common/debug_threadx.h"
222 #endif /* __cplusplus */