Home | History | Annotate | Line # | Download | only in ralink
      1 /*	$NetBSD: ralink_debug.h,v 1.2 2011/07/28 15:38:49 matt Exp $	*/
      2 /*-
      3  * Copyright (c) 2011 CradlePoint Technology, Inc.
      4  * All rights reserved.
      5  *
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY CRADLEPOINT TECHNOLOGY, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _RALINK_DEBUG_H_
     30 #define _RALINK_DEBUG_H_
     31 
     32 /* Co-locate some debug routines to help keep the code clean.
     33  *  #define one or more ENABLE_RALINK_DEBUG_xxxx macros before including
     34  *  this file to turn on macros.  If none are defined the debug code
     35  *  won't be compiled in.
     36  */
     37 
     38 /*
     39  * High-level debug compile flag.  If this isn't defined, this is
     40  *  a release build.
     41  */
     42 
     43 /* Debugging options */
     44 #ifndef ENABLE_RALINK_DEBUG_ERROR
     45  #define ENABLE_RALINK_DEBUG_ERROR 0
     46 #endif
     47 #ifndef ENABLE_RALINK_DEBUG_FUNC
     48  #define ENABLE_RALINK_DEBUG_FUNC  0
     49 #endif
     50 #ifndef ENABLE_RALINK_DEBUG_MISC
     51  #define ENABLE_RALINK_DEBUG_MISC  0
     52 #endif
     53 #ifndef ENABLE_RALINK_DEBUG_INFO
     54  #define ENABLE_RALINK_DEBUG_INFO  0
     55 #endif
     56 #ifndef ENABLE_RALINK_DEBUG_REG
     57  #define ENABLE_RALINK_DEBUG_REG   0
     58 #endif
     59 /* don't check anything in with this option.  Just use this if you want to
     60  * force a specific statement and the above options don't give you fine enough
     61  * control.
     62  */
     63 #ifndef ENABLE_RALINK_DEBUG_FORCE
     64  #define ENABLE_RALINK_DEBUG_FORCE   0
     65 #endif
     66 
     67 #define RALINK_DEBUG_ERROR ((ENABLE_RALINK_DEBUG_ERROR ? 1 : 0) << 0)
     68 #define RALINK_DEBUG_MISC  ((ENABLE_RALINK_DEBUG_MISC  ? 1 : 0) << 1)
     69 #define RALINK_DEBUG_FUNC  ((ENABLE_RALINK_DEBUG_FUNC  ? 1 : 0) << 2)
     70 #define RALINK_DEBUG_INFO  ((ENABLE_RALINK_DEBUG_INFO  ? 1 : 0) << 3)
     71 #define RALINK_DEBUG_REG   ((ENABLE_RALINK_DEBUG_REG   ? 1 : 0) << 4)
     72 #define RALINK_DEBUG_FORCE ((ENABLE_RALINK_DEBUG_FORCE ? 1 : 0) << 5)
     73 
     74 #ifndef RALINK_DEBUG_ALL
     75 #define RALINK_DEBUG_ALL	( RALINK_DEBUG_ERROR | RALINK_DEBUG_MISC | RALINK_DEBUG_FUNC | \
     76 			  RALINK_DEBUG_INFO | RALINK_DEBUG_REG | RALINK_DEBUG_FORCE )
     77 #endif
     78 
     79 /*
     80  * RALINK_DEBUG_0 is used instead of:
     81  *
     82  * #if 0
     83  * 	RALINK_DEBUG(x, blah);
     84  * #endif
     85  *
     86  * in order to preserve the if'ed-out prints, without the clutter;
     87  * alternatively, just delete them and this macro
     88  */
     89 #define RALINK_DEBUG_0(n, args...)	do { } while (0)
     90 
     91 #ifdef CPDEBUG
     92 
     93 #if RALINK_DEBUG_ALL > 0
     94 #define RALINK_DEBUG(n, args...)		\
     95 	do {				\
     96 		if (RALINK_DEBUG_ALL & (n)) \
     97 			printf(args);	\
     98 	} while (0)
     99 #else
    100 #define RALINK_DEBUG(n, args...)   do { } while (0)
    101 #endif
    102 
    103 /* helper so we don't have to retype a bunch of times */
    104 #define RALINK_DEBUG_FUNC_ENTRY()	\
    105 		RALINK_DEBUG(RALINK_DEBUG_FUNC, "%s() entry\n", __FUNCTION__)
    106 #define RALINK_DEBUG_FUNC_EXIT()	\
    107 		RALINK_DEBUG(RALINK_DEBUG_FUNC, "%s() exit\n", __FUNCTION__)
    108 
    109 #else	/* DEBUG not defined (release build) */
    110 
    111 #define RALINK_DEBUG(n, args...)
    112 #define RALINK_DEBUG_FUNC_ENTRY()
    113 #define RALINK_DEBUG_FUNC_EXIT()
    114 
    115 #endif	/* DEBUG defined */
    116 
    117 #endif	/* _RALINK_DEBUG_H_ */
    118