gt.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2009, Texas Instruments Incorporated
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * *  Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  *
00012  * *  Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *
00016  * *  Neither the name of Texas Instruments Incorporated nor the names of
00017  *    its contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00022  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00023  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00024  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00027  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00028  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00029  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00030  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  * 
00032  */
00033 /*
00034  *  ======== gt.h ========
00035  */
00036 
00064 /*  Note        There are two definitions that affect which portions of trace
00065  *              are actually compiled into the client: @c GT_TRACE and
00066  *              @c GT_ASSERT. If @c GT_TRACE is set to 0 then all trace
00067  *              statements (except for assertions) will be compiled
00068  *              out of the client. If @c GT_ASSERT is set to 0 then
00069  *              assertions will be compiled out of the
00070  *              client.  @c GT_ASSERT can not be set to 0 unless @c GT_TRACE
00071  *              is also set to 0 (i.e. @c GT_TRACE == 1 implies @c GT_ASSERT
00072  *              == 1).
00073  */
00074 
00075 #ifndef ti_sdo_utils_trace_GT_
00076 #define ti_sdo_utils_trace_GT_
00077 
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081 
00084 
00087 #ifndef GT_TRACE
00088 #define GT_TRACE 1  /* 0 = "trace compiled out"; 1 = "trace active" */
00089 #endif
00090 
00091 #if !defined(GT_ASSERT) || GT_TRACE
00092 #define GT_ASSERT 1
00093 #endif
00094 
00095 typedef Void   (*GT_PrintFxn)(String fmt, ...);
00096 typedef Ptr    (*GT_MallocFxn)(Int size);
00097 typedef Void   (*GT_FreeFxn)(Ptr addr, Int size);
00098 typedef UInt32 (*GT_TimeFxn)(Void);
00099 
00100 typedef struct {
00101     GT_PrintFxn  PRINTFXN;
00102     Fxn          PIDFXN;
00103     Fxn          TIDFXN;
00104     GT_PrintFxn  ERRORFXN;
00105     GT_MallocFxn MALLOCFXN;
00106     GT_FreeFxn   FREEFXN;
00107     GT_TimeFxn   TIMEFXN;
00108     Fxn          LOCKFXN;
00109     Fxn          UNLOCKFXN;
00110     Fxn          INITFXN;
00111 } GT_Config;
00112 
00113 #if (GT_TRACE != 0) || (GT_ASSERT !=0 ) 
00114 extern __FAR__ GT_Config *GT;
00115 #endif 
00116 
00131 typedef struct {
00132     String      modName;    
00133     UInt8      *flags;      
00134 } GT_Mask;
00135 
00136 
00137 /*
00138  *  New GT Class definitions.
00139  *
00140  * [dm]TODO:H new proposal for how we should use different tracing classes: {
00141  *
00142  * - GT_ENTER (class 0): On entry to *and exit from* functions: consider
00143  *                       in general this class to be of interest to users
00144  *
00145  * - GT_1CLASS : debugging info of interest to module developer only
00146  *
00147  * - GT_2CLASS : info for developer that *might* be of interest to users
00148  *
00149  * - GT_3CLASS : open (module developer can creatively use this one)
00150  *
00151  * - GT_4CLASS : info for developer that's likely to be important to the users
00152  *
00153  * - GT_5CLASS : benchmarking
00154  *
00155  * - GT_6CLASS : warnings
00156  *
00157  * - GT_7CLASS : errors
00158  *
00159  * }
00160  */
00161 
00165 #define GT_ENTER        ((UInt8)0x01)
00166 
00167 #define GT_1CLASS       ((UInt8)0x02)   
00168 #define GT_2CLASS       ((UInt8)0x04)   
00169 #define GT_3CLASS       ((UInt8)0x08)   
00170 #define GT_4CLASS       ((UInt8)0x10)   
00176 #define GT_5CLASS       ((UInt8)0x20)
00177 
00182 #define GT_6CLASS       ((UInt8)0x40)
00183 
00188 #define GT_7CLASS       ((UInt8)0x80)
00189 
00190 /*
00191  *  ======== _GT_create ========
00192  */
00212 extern Void _GT_create(GT_Mask *mask, String modName);
00213 
00214 
00217 extern UInt32 GT_curTime(Void);
00218 
00219 #define GT_exit()
00220 
00223 /*
00224  *  ======== GT_init ========
00225  */
00232 extern Void GT_init(Void);
00233 
00234 
00235 /*
00236  *  ======== _GT_set ========
00237  */
00248 extern Void _GT_set(String str);
00249 
00250 
00251 /*
00252  *  ======== _GT_trace ========
00253  */
00276 extern Int _GT_trace(GT_Mask *mask, Int classId, String format, ...);
00277 
00279 extern Void GT_disable(Void);
00280 extern Void GT_enable(Void);
00281 extern Bool GT_getModNameFlags(String modName, UInt8 *flags);
00282 
00283 #if GT_ASSERT == 0
00284 
00285 #define GT_assert( mask, expr )
00286 #define GT_config( config )
00287 #define GT_configInit( config )
00288 #define GT_seterror( fxn )
00289 
00290 #else
00291 
00292 extern GT_Config _ti_sdo_utils_trace_GT_params;
00293 
00294 #define GT_assert( mask, expr ) \
00295         (!(expr) ? \
00296             (*GT->ERRORFXN)("assertion violation: %s, line %d\n", \
00297                             __FILE__, __LINE__), NULL : NULL)
00298 
00299 #define GT_config(config)     (_ti_sdo_utils_trace_GT_params = *(config))
00300 #define GT_configInit(config) (*(config) = _ti_sdo_utils_trace_GT_params)
00301 #define GT_seterror(fxn) (_ti_sdo_utils_trace_GT_params.ERRORFXN = (Fxn)(fxn))
00302 
00303 #endif
00304 
00307 #if GT_TRACE == 0
00308 
00311 #define GT_curLine()                ((MdUns)__LINE__)
00312 #define GT_curTime()                ((UInt32)0)
00313 #define GT_create(mask, modName)
00314 #define GT_exit()
00315 #define GT_init()
00316 #define GT_set(str)
00317 #define GT_setprintf( fxn )
00318 
00319 #define GT_query( mask, classId )     FALSE
00320 
00321 #define GT_0trace( mask, classId, format )
00322 #define GT_1trace( mask, classId, format, arg1 )
00323 #define GT_2trace( mask, classId, format, arg1, arg2 )
00324 #define GT_3trace( mask, classId, format, arg1, arg2, arg3 )
00325 #define GT_4trace( mask, classId, format, arg1, arg2, arg3, arg4 )
00326 #define GT_5trace( mask, classId, format, arg1, arg2, arg3, arg4, arg5 )
00327 #define GT_6trace( mask, classId, format, arg1, arg2, arg3, arg4, arg5, arg6 )
00328 
00331 #else   /* GT_TRACE == 1 */
00332 
00335 extern String GT_format;
00336 
00337 #define GT_curLine()      ((MdUns)__LINE__)
00338 #define GT_setprintf(fxn) (_ti_sdo_utils_trace_GT_params.PRINTFXN = (fxn))
00339 
00340 #define GT_query(mask, classId) ((*(mask).flags & (classId)))
00341 
00347 #define GT_create(mask, modName)    _GT_create((mask), (modName))
00348 
00352 #define GT_set(str)                 _GT_set(str)
00353 
00357 #define GT_0trace( mask, classId, format ) \
00358     ((*(mask).flags & (classId)) ? \
00359     _GT_trace(&(mask), (classId), (format)) : 0)
00360 
00364 #define GT_1trace( mask, classId, format, arg1 ) \
00365     ((*(mask).flags & (classId)) ? \
00366     _GT_trace(&(mask), (classId), (format), (arg1)) : 0)
00367 
00371 #define GT_2trace( mask, classId, format, arg1, arg2 ) \
00372     ((*(mask).flags & (classId)) ? \
00373     _GT_trace(&(mask), (classId), (format), (arg1), (arg2)) : 0)
00374 
00378 #define GT_3trace( mask, classId, format, arg1, arg2, arg3 ) \
00379     ((*(mask).flags & (classId)) ? \
00380     _GT_trace(&(mask), (classId), (format), (arg1), (arg2), (arg3)) : 0)
00381 
00385 #define GT_4trace( mask, classId, format, arg1, arg2, arg3, arg4 ) \
00386     ((*(mask).flags & (classId)) ? \
00387     _GT_trace(&(mask), (classId), (format), (arg1), (arg2), (arg3), (arg4)) : 0)
00388 
00392 #define GT_5trace( mask, classId, format, arg1, arg2, arg3, arg4, arg5 ) \
00393     ((*(mask).flags & (classId)) ? \
00394     _GT_trace(&(mask), (classId), (format), (arg1), (arg2), (arg3), (arg4), (arg5)) : 0)
00395 
00399 #define GT_6trace( mask, classId, format, arg1, arg2, arg3, arg4, arg5, arg6 ) \
00400     ((*(mask).flags & (classId)) ? \
00401     _GT_trace(&(mask), (classId), (format), (arg1), (arg2), (arg3), (arg4), \
00402         (arg5), (arg6)) : 0)
00403 
00404 
00405 
00406 #endif /* GT_TRACE */
00407   /* ingroup */
00409 
00410 #ifdef __cplusplus
00411 }
00412 #endif
00413 
00414 #endif
00415 
00416 /*
00417  */
00418 /*
00419  *  @(#) ti.sdo.utils.trace; 1, 0, 0,164; 11-8-2009 20:59:11; /db/atree/library/trees/fc/fc-l04x/src/
00420  */
00421 

Copyright 2009, Texas Instruments Incorporated