tracer.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2000-2004 by ETH Zurich
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00021  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.btnode.ethz.ch
00031  *
00032  */
00033  /*
00034  * sys/tracer.h
00035  *
00036  * 22.12.2004 Philipp Blum <blum@tik.ee.ethz.ch>
00037  */
00038 #ifndef _SYS_TRACER_H_
00039 #define _SYS_TRACER_H_
00040 
00054 #include <sys/types.h>
00055 #include <sys/atom.h>
00056 
00057 /******************************************************************
00058  * defines 
00059  ******************************************************************/
00060 #define TRACE_MODE_FIRST            0
00061 #define TRACE_MODE_OFF              0
00062 #define TRACE_MODE_CIRCULAR         1 
00063 #define TRACE_MODE_ONESHOT          2
00064 #define TRACE_MODE_LAST             2
00065 #define TRACE_MODE_DEFAULT          TRACE_MODE_CIRCULAR
00066 
00067 #define TRACE_SIZE_DEFAULT        500
00068 
00069 /* Event types */
00070 #define TRACE_TAG_FIRST             0
00071 #define TRACE_TAG_CRITICAL_FIRST    0
00072 #define TRACE_TAG_CRITICAL_ENTER    0
00073 #define TRACE_TAG_CRITICAL_EXIT     1
00074 #define TRACE_TAG_CRITICAL_LAST     1
00075 #define TRACE_TAG_THREAD_FIRST      2
00076 #define TRACE_TAG_THREAD_YIELD      2
00077 #define TRACE_TAG_THREAD_SETPRIO    3
00078 #define TRACE_TAG_THREAD_WAIT       4
00079 #define TRACE_TAG_THREAD_SLEEP      5
00080 #define TRACE_TAG_THREAD_LAST       5
00081 #define TRACE_TAG_INTERRUPT_FIRST   6
00082 #define TRACE_TAG_INTERRUPT_ENTER   6
00083 #define TRACE_TAG_INTERRUPT_EXIT    7
00084 #define TRACE_TAG_INTERRUPT_LAST    7
00085 #define TRACE_TAG_START             8
00086 #define TRACE_TAG_STOP              9
00087 #define TRACE_TAG_USER             10
00088 #define TRACE_TAG_LAST             10
00089 
00090 #define TRACE_MAX_USER             10
00091 
00092 #define TRACE_INT_FIRST             0
00093 #define TRACE_INT_UART0_CTS         0
00094 #define TRACE_INT_UART0_RXCOMPL     1
00095 #define TRACE_INT_UART0_TXEMPTY     2
00096 #define TRACE_INT_UART1_CTS         3
00097 #define TRACE_INT_UART1_RXCOMPL     4
00098 #define TRACE_INT_UART1_TXEMPTY     5
00099 #define TRACE_INT_TIMER0_OVERFL     6
00100 #define TRACE_INT_TIMER1_OVERFL     7
00101 #define TRACE_INT_SUART_TIMER       8
00102 #define TRACE_INT_SUART_RX          9
00103 #define TRACE_INT_LAST              9
00104 
00105 /******************************************************************
00106  * typedefs
00107  ******************************************************************/
00110 typedef struct _t_traceitem {
00113     u_char tag;
00116     u_int  pc;
00119     u_int  time_h;
00122     u_int  time_l;
00123 } t_traceitem;
00124 
00125 
00126 /******************************************************************
00127  * global variables 
00128  ******************************************************************/
00131 extern u_int micros_high;
00134 extern t_traceitem *trace_items;
00137 extern t_traceitem *trace_current;
00140 extern int trace_head;
00143 extern int trace_size;
00146 extern char trace_isfull;
00149 extern char trace_mode;
00152 extern char trace_mask[TRACE_TAG_LAST+1];
00153 
00154 /******************************************************************
00155  * function prototypes API
00156  ******************************************************************/
00157 /*******************************************************************************
00158  * NutTraceInit
00159  ******************************************************************************/
00172 extern int  NutTraceInit(int size, char mode); 
00173 /*******************************************************************************
00174  * NutTraceStop
00175  ******************************************************************************/
00179 extern void NutTraceStop(void);
00180 /*******************************************************************************
00181  * NutTracePrint
00182  ******************************************************************************/
00189 extern void NutTracePrint(int size);
00190 /*******************************************************************************
00191  * NutTraceTerminal
00192  ******************************************************************************/
00203 extern void NutTraceTerminal(char* arg);
00204 /*******************************************************************************
00205  * NutTraceGetPC
00206  ******************************************************************************/
00216 extern int  NutTraceGetPC(void);
00217 /*******************************************************************************
00218  * NutTraceClear
00219  ******************************************************************************/
00223 extern void NutTraceClear(void);
00224 /*******************************************************************************
00225  * NutTraceMaskPrint
00226  ******************************************************************************/
00231 extern void NutTraceMaskPrint(void);
00232 /*******************************************************************************
00233  * NutTraceMaskClear
00234  ******************************************************************************/
00240 extern void NutTraceMaskClear(int tag);
00241 /*******************************************************************************
00242  * NutTraceMaskSet
00243  ******************************************************************************/
00249 extern void NutTraceMaskSet(int tag);
00250 /*******************************************************************************
00251  * NutTraceStatusPrint
00252  ******************************************************************************/
00256 extern void NutTraceStatusPrint(void);
00257 /*******************************************************************************
00258  * NutTraceRegisterUserTag
00259  ******************************************************************************/
00266 extern int NutTraceRegisterUserTag(int tag, char* tag_string);
00273 #define TRACE_ADD_ITEM(TAG,PC)                      \
00274     if ((trace_mode != TRACE_MODE_OFF) &&           \
00275         (trace_mask[TAG] == 1))                     \
00276     {                                               \
00277         asm volatile(                               \
00278             "in  __tmp_reg__, __SREG__" "\n\t"      \
00279             "push __tmp_reg__"  "\n\t"              \
00280             "cli"                       "\n\t"      \
00281         );                                          \
00282         trace_current = &trace_items[trace_head++]; \
00283         trace_current->tag = TAG;                   \
00284         trace_current->pc = PC;                     \
00285         trace_current->time_h = micros_high;        \
00286         trace_current->time_l = TCNT1;              \
00287         if (trace_head >= trace_size) {             \
00288             trace_isfull = 1;                       \
00289             trace_head = 0;                         \
00290             if (trace_mode == TRACE_MODE_ONESHOT)   \
00291                 trace_mode = TRACE_MODE_OFF;        \
00292         }                                           \
00293         asm volatile(                               \
00294             "pop __tmp_reg__"           "\n\t"      \
00295             "out __SREG__, __tmp_reg__" "\n\t"      \
00296         );                                          \
00297     }
00298 
00304 #define TRACE_ADD_ITEM_PC(TAG) TRACE_ADD_ITEM(TAG,NutTraceGetPC())
00305 
00306 #endif
00307 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/