tracer.h File Reference


Detailed Description

Trace functions.

Author:
Philipp Blum <blum@tik.ee.ethz.ch>
Date:
22.12.2004

Definition in file tracer.h.

Go to the source code of this file.

Data Structures

struct  t_traceitem
 Item in the trace buffer. More...

Defines

#define TRACE_MODE_FIRST   0
#define TRACE_MODE_OFF   0
#define TRACE_MODE_CIRCULAR   1
#define TRACE_MODE_ONESHOT   2
#define TRACE_MODE_LAST   2
#define TRACE_MODE_DEFAULT   TRACE_MODE_CIRCULAR
#define TRACE_SIZE_DEFAULT   500
#define TRACE_TAG_FIRST   0
#define TRACE_TAG_CRITICAL_FIRST   0
#define TRACE_TAG_CRITICAL_ENTER   0
#define TRACE_TAG_CRITICAL_EXIT   1
#define TRACE_TAG_CRITICAL_LAST   1
#define TRACE_TAG_THREAD_FIRST   2
#define TRACE_TAG_THREAD_YIELD   2
#define TRACE_TAG_THREAD_SETPRIO   3
#define TRACE_TAG_THREAD_WAIT   4
#define TRACE_TAG_THREAD_SLEEP   5
#define TRACE_TAG_THREAD_LAST   5
#define TRACE_TAG_INTERRUPT_FIRST   6
#define TRACE_TAG_INTERRUPT_ENTER   6
#define TRACE_TAG_INTERRUPT_EXIT   7
#define TRACE_TAG_INTERRUPT_LAST   7
#define TRACE_TAG_START   8
#define TRACE_TAG_STOP   9
#define TRACE_TAG_USER   10
#define TRACE_TAG_LAST   10
#define TRACE_MAX_USER   10
#define TRACE_INT_FIRST   0
#define TRACE_INT_UART0_CTS   0
#define TRACE_INT_UART0_RXCOMPL   1
#define TRACE_INT_UART0_TXEMPTY   2
#define TRACE_INT_UART1_CTS   3
#define TRACE_INT_UART1_RXCOMPL   4
#define TRACE_INT_UART1_TXEMPTY   5
#define TRACE_INT_TIMER0_OVERFL   6
#define TRACE_INT_TIMER1_OVERFL   7
#define TRACE_INT_SUART_TIMER   8
#define TRACE_INT_SUART_RX   9
#define TRACE_INT_LAST   9
#define TRACE_ADD_ITEM(TAG, PC)
#define TRACE_ADD_ITEM_PC(TAG)   TRACE_ADD_ITEM(TAG,NutTraceGetPC())

Functions

int NutTraceInit (int size, char mode)
void NutTraceStop (void)
void NutTracePrint (int size)
void NutTraceTerminal (char *arg)
int NutTraceGetPC (void)
void NutTraceClear (void)
void NutTraceMaskPrint (void)
void NutTraceMaskClear (int tag)
void NutTraceMaskSet (int tag)
void NutTraceStatusPrint (void)
int NutTraceRegisterUserTag (int tag, char *tag_string)

Variables

u_int micros_high
 Upper 16 bits of microseconds clock, incremented on timer 1 overflow interrupts.
t_traceitemtrace_items
 Trace buffer, initialized by NutTraceInit.
t_traceitemtrace_current
 Pointer to the current item in the trace buffer.
int trace_head
 Current index in the trace buffer.
int trace_size
 Size of the trace buffer.
char trace_isfull
 Flag indicating whether all items in the trace buffer contain valid information.
char trace_mode
 Current state of the tracing facility.
char trace_mask [TRACE_TAG_LAST+1]
 Mask to individually disable tracing of specific event types.


Define Documentation

#define TRACE_MODE_FIRST   0

Definition at line 60 of file tracer.h.

#define TRACE_MODE_OFF   0

Definition at line 61 of file tracer.h.

#define TRACE_MODE_CIRCULAR   1

Definition at line 62 of file tracer.h.

#define TRACE_MODE_ONESHOT   2

Definition at line 63 of file tracer.h.

#define TRACE_MODE_LAST   2

Definition at line 64 of file tracer.h.

#define TRACE_MODE_DEFAULT   TRACE_MODE_CIRCULAR

Definition at line 65 of file tracer.h.

#define TRACE_SIZE_DEFAULT   500

Definition at line 67 of file tracer.h.

#define TRACE_TAG_FIRST   0

Definition at line 70 of file tracer.h.

#define TRACE_TAG_CRITICAL_FIRST   0

Definition at line 71 of file tracer.h.

#define TRACE_TAG_CRITICAL_ENTER   0

Definition at line 72 of file tracer.h.

#define TRACE_TAG_CRITICAL_EXIT   1

Definition at line 73 of file tracer.h.

#define TRACE_TAG_CRITICAL_LAST   1

Definition at line 74 of file tracer.h.

#define TRACE_TAG_THREAD_FIRST   2

Definition at line 75 of file tracer.h.

#define TRACE_TAG_THREAD_YIELD   2

Definition at line 76 of file tracer.h.

Referenced by NutThreadResume().

#define TRACE_TAG_THREAD_SETPRIO   3

Definition at line 77 of file tracer.h.

Referenced by NutThreadSetPriority().

#define TRACE_TAG_THREAD_WAIT   4

Definition at line 78 of file tracer.h.

Referenced by NutEventWait().

#define TRACE_TAG_THREAD_SLEEP   5

Definition at line 79 of file tracer.h.

Referenced by NutSleep().

#define TRACE_TAG_THREAD_LAST   5

Definition at line 80 of file tracer.h.

#define TRACE_TAG_INTERRUPT_FIRST   6

Definition at line 81 of file tracer.h.

#define TRACE_TAG_INTERRUPT_ENTER   6

Definition at line 82 of file tracer.h.

#define TRACE_TAG_INTERRUPT_EXIT   7

Definition at line 83 of file tracer.h.

#define TRACE_TAG_INTERRUPT_LAST   7

Definition at line 84 of file tracer.h.

#define TRACE_TAG_START   8

Definition at line 85 of file tracer.h.

#define TRACE_TAG_STOP   9

Definition at line 86 of file tracer.h.

#define TRACE_TAG_USER   10

Definition at line 87 of file tracer.h.

#define TRACE_TAG_LAST   10

Definition at line 88 of file tracer.h.

#define TRACE_MAX_USER   10

Definition at line 90 of file tracer.h.

#define TRACE_INT_FIRST   0

Definition at line 92 of file tracer.h.

#define TRACE_INT_UART0_CTS   0

Definition at line 93 of file tracer.h.

#define TRACE_INT_UART0_RXCOMPL   1

Definition at line 94 of file tracer.h.

#define TRACE_INT_UART0_TXEMPTY   2

Definition at line 95 of file tracer.h.

#define TRACE_INT_UART1_CTS   3

Definition at line 96 of file tracer.h.

#define TRACE_INT_UART1_RXCOMPL   4

Definition at line 97 of file tracer.h.

#define TRACE_INT_UART1_TXEMPTY   5

Definition at line 98 of file tracer.h.

#define TRACE_INT_TIMER0_OVERFL   6

Definition at line 99 of file tracer.h.

#define TRACE_INT_TIMER1_OVERFL   7

Definition at line 100 of file tracer.h.

#define TRACE_INT_SUART_TIMER   8

Definition at line 101 of file tracer.h.

#define TRACE_INT_SUART_RX   9

Definition at line 102 of file tracer.h.

#define TRACE_INT_LAST   9

Definition at line 103 of file tracer.h.

#define TRACE_ADD_ITEM ( TAG,
PC   ) 

Value:

if ((trace_mode != TRACE_MODE_OFF) &&           \
        (trace_mask[TAG] == 1))                     \
    {                                               \
        asm volatile(                               \
            "in  __tmp_reg__, __SREG__" "\n\t"      \
            "push __tmp_reg__"  "\n\t"              \
            "cli"                       "\n\t"      \
        );                                          \
        trace_current = &trace_items[trace_head++]; \
        trace_current->tag = TAG;                   \
        trace_current->pc = PC;                     \
        trace_current->time_h = micros_high;        \
        trace_current->time_l = TCNT1;              \
        if (trace_head >= trace_size) {             \
            trace_isfull = 1;                       \
            trace_head = 0;                         \
            if (trace_mode == TRACE_MODE_ONESHOT)   \
                trace_mode = TRACE_MODE_OFF;        \
        }                                           \
        asm volatile(                               \
            "pop __tmp_reg__"           "\n\t"      \
            "out __SREG__, __tmp_reg__" "\n\t"      \
        );                                          \
    }
Macro to insert an event in the trace buffer

Parameters:
TAG Type of event
PC Additional information, depending on the type of event

Definition at line 273 of file tracer.h.

Referenced by NutEventWait(), NutSleep(), NutThreadResume(), and NutThreadSetPriority().

#define TRACE_ADD_ITEM_PC ( TAG   )     TRACE_ADD_ITEM(TAG,NutTraceGetPC())

Macro to insert an event in the trace buffer, filling the additional information field with the program counter (PC)

Parameters:
TAG Type of event

Definition at line 304 of file tracer.h.


Function Documentation

int NutTraceInit ( int  size,
char  mode 
)

Initializes the trace buffer and activates tracing. Starts timer 1 for microsecond clock, enables interrupt on overflow

Parameters:
size Number of items in the trace buffer
mode Mode of operation
Returns:
int Status

void NutTraceStop ( void   ) 

Sets trace_mode to TRACE_MODE_OFF and thus stop tracing

void NutTracePrint ( int  size  ) 

Prints the current contents of the trace buffer

Parameters:
size can be used to limit the number of printed items, if size==0, then all items of the buffer are printed

void NutTraceTerminal ( char *  arg  ) 

Commands to manipulate the tracing facility

Parameters:
arg String containing the commands
  • print <size> calls NutPrintTrace
  • oneshot restarts tracing in the oneshot mode
  • circular restarts tracing in the ciruclar mode
  • size <size> restarts tracing in the current mode, using a buffer of length <size>
  • stop stops tracing

int NutTraceGetPC ( void   ) 

Returns the program counter (PC) of the instruction following NutGetPC The .map file of the application can be used to find the actual C Code

WARNING: Most likely only works on AVR. Works by inspecting the stack, thus the function breaks when local variables are introduced in NutGetPC

Returns:
int Program counter

void NutTraceClear ( void   ) 

Clears the trace buffer, but leaves trace_mode unaltered.

void NutTraceMaskPrint ( void   ) 

Prints the current state of trace_mask, which for every type of event (TRACE_TAG_XXX) determines, whether they are inserted in the trace buffer or not.

void NutTraceMaskClear ( int  tag  ) 

Disables tracing of a particular event type

Parameters:
tag of event to disable

void NutTraceMaskSet ( int  tag  ) 

Enables tracing of a particular event type

Parameters:
tag of event to enable

void NutTraceStatusPrint ( void   ) 

Prints current status of tracing facility

int NutTraceRegisterUserTag ( int  tag,
char *  tag_string 
)

Registers a user event type

Parameters:
tag of the new event type (e.g. define TRACE_USER_SEND 0)
tag_string name of the event type used when printing the trace buffer


Variable Documentation

u_int micros_high

Upper 16 bits of microseconds clock, incremented on timer 1 overflow interrupts.

t_traceitem* trace_items

Trace buffer, initialized by NutTraceInit.

t_traceitem* trace_current

Pointer to the current item in the trace buffer.

int trace_head

Current index in the trace buffer.

int trace_size

Size of the trace buffer.

char trace_isfull

Flag indicating whether all items in the trace buffer contain valid information.

char trace_mode

Current state of the tracing facility.

char trace_mask[TRACE_TAG_LAST+1]

Mask to individually disable tracing of specific event types.


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