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 <stdint.h> 00056 #include <sys/atom.h> 00057 00058 /****************************************************************** 00059 * defines 00060 ******************************************************************/ 00061 #define TRACE_MODE_FIRST 0 00062 #define TRACE_MODE_OFF 0 00063 #define TRACE_MODE_CIRCULAR 1 00064 #define TRACE_MODE_ONESHOT 2 00065 #define TRACE_MODE_LAST 2 00066 #define TRACE_MODE_DEFAULT TRACE_MODE_CIRCULAR 00067 00068 #define TRACE_SIZE_DEFAULT 500 00069 00070 /* Event types */ 00071 #define TRACE_TAG_FIRST 0 00072 #define TRACE_TAG_CRITICAL_FIRST 0 00073 #define TRACE_TAG_CRITICAL_ENTER 0 00074 #define TRACE_TAG_CRITICAL_EXIT 1 00075 #define TRACE_TAG_CRITICAL_LAST 1 00076 #define TRACE_TAG_THREAD_FIRST 2 00077 #define TRACE_TAG_THREAD_YIELD 2 00078 #define TRACE_TAG_THREAD_SETPRIO 3 00079 #define TRACE_TAG_THREAD_WAIT 4 00080 #define TRACE_TAG_THREAD_SLEEP 5 00081 #define TRACE_TAG_THREAD_LAST 5 00082 #define TRACE_TAG_INTERRUPT_FIRST 6 00083 #define TRACE_TAG_INTERRUPT_ENTER 6 00084 #define TRACE_TAG_INTERRUPT_EXIT 7 00085 #define TRACE_TAG_INTERRUPT_LAST 7 00086 #define TRACE_TAG_START 8 00087 #define TRACE_TAG_STOP 9 00088 #define TRACE_TAG_USER 10 00089 #define TRACE_TAG_LAST 10 00090 00091 #define TRACE_MAX_USER 10 00092 00093 #define TRACE_INT_FIRST 0 00094 #define TRACE_INT_UART0_CTS 0 00095 #define TRACE_INT_UART0_RXCOMPL 1 00096 #define TRACE_INT_UART0_TXEMPTY 2 00097 #define TRACE_INT_UART1_CTS 3 00098 #define TRACE_INT_UART1_RXCOMPL 4 00099 #define TRACE_INT_UART1_TXEMPTY 5 00100 #define TRACE_INT_TIMER0_OVERFL 6 00101 #define TRACE_INT_TIMER1_OVERFL 7 00102 #define TRACE_INT_SUART_TIMER 8 00103 #define TRACE_INT_SUART_RX 9 00104 #define TRACE_INT_LAST 9 00105 00106 /****************************************************************** 00107 * typedefs 00108 ******************************************************************/ 00111 typedef struct _t_traceitem { 00114 uint8_t tag; 00117 unsigned int pc; 00120 unsigned int time_h; 00123 unsigned int time_l; 00124 } t_traceitem; 00125 00126 00127 /****************************************************************** 00128 * global variables 00129 ******************************************************************/ 00132 extern unsigned int micros_high; 00135 extern t_traceitem *trace_items; 00138 extern t_traceitem *trace_current; 00141 extern int trace_head; 00144 extern int trace_size; 00147 extern char trace_isfull; 00150 extern char trace_mode; 00153 extern char trace_mask[TRACE_TAG_LAST+1]; 00154 00155 /****************************************************************** 00156 * function prototypes API 00157 ******************************************************************/ 00158 /******************************************************************************* 00159 * NutTraceInit 00160 ******************************************************************************/ 00173 extern int NutTraceInit(int size, char mode); 00174 /******************************************************************************* 00175 * NutTraceStop 00176 ******************************************************************************/ 00180 extern void NutTraceStop(void); 00181 /******************************************************************************* 00182 * NutTracePrint 00183 ******************************************************************************/ 00190 extern void NutTracePrint(int size); 00191 /******************************************************************************* 00192 * NutTraceTerminal 00193 ******************************************************************************/ 00204 extern void NutTraceTerminal(char* arg); 00205 /******************************************************************************* 00206 * NutTraceGetPC 00207 ******************************************************************************/ 00217 extern int NutTraceGetPC(void); 00218 /******************************************************************************* 00219 * NutTraceClear 00220 ******************************************************************************/ 00224 extern void NutTraceClear(void); 00225 /******************************************************************************* 00226 * NutTraceMaskPrint 00227 ******************************************************************************/ 00232 extern void NutTraceMaskPrint(void); 00233 /******************************************************************************* 00234 * NutTraceMaskClear 00235 ******************************************************************************/ 00241 extern void NutTraceMaskClear(int tag); 00242 /******************************************************************************* 00243 * NutTraceMaskSet 00244 ******************************************************************************/ 00250 extern void NutTraceMaskSet(int tag); 00251 /******************************************************************************* 00252 * NutTraceStatusPrint 00253 ******************************************************************************/ 00257 extern void NutTraceStatusPrint(void); 00258 /******************************************************************************* 00259 * NutTraceRegisterUserTag 00260 ******************************************************************************/ 00267 extern int NutTraceRegisterUserTag(int tag, char* tag_string); 00274 #define TRACE_ADD_ITEM(TAG,PC) \ 00275 if ((trace_mode != TRACE_MODE_OFF) && \ 00276 (trace_mask[TAG] == 1)) \ 00277 { \ 00278 asm volatile( \ 00279 "in __tmp_reg__, __SREG__" "\n\t" \ 00280 "push __tmp_reg__" "\n\t" \ 00281 "cli" "\n\t" \ 00282 ); \ 00283 trace_current = &trace_items[trace_head++]; \ 00284 trace_current->tag = TAG; \ 00285 trace_current->pc = PC; \ 00286 trace_current->time_h = micros_high; \ 00287 trace_current->time_l = TCNT1; \ 00288 if (trace_head >= trace_size) { \ 00289 trace_isfull = 1; \ 00290 trace_head = 0; \ 00291 if (trace_mode == TRACE_MODE_ONESHOT) \ 00292 trace_mode = TRACE_MODE_OFF; \ 00293 } \ 00294 asm volatile( \ 00295 "pop __tmp_reg__" "\n\t" \ 00296 "out __SREG__, __tmp_reg__" "\n\t" \ 00297 ); \ 00298 } 00299 00305 #define TRACE_ADD_ITEM_PC(TAG) TRACE_ADD_ITEM(TAG,NutTraceGetPC()) 00306 00307 #endif 00308