--- tinyos-1.x/tos/types/dbg.h.orig Thu Jan 22 13:11:11 2004 +++ tinyos-1.x/tos/types/dbg.h Fri Jan 23 19:31:09 2004 @@ -122,6 +122,101 @@ } } +#elif (defined(PLATFORM_MICA2) || defined(PLATFORM_MICA2DOT)) && !defined(NDEBUG) +#include +#include + +/* Atmel128L platforms going through the debugging device */ +#undef dbg +#undef dbg_clear +#undef dbg_active +#define dbg_add_mode(...) { } +#define dbg_add_modes(...) { } +#define dbg_help() { } +#define dbg_active(x) (TRUE) + +/* int64_t and variable argument lists is broken on certain versions of + * AVR tools. So make sure TOS_dbg_mode is an uint32_t */ +#undef TOS_dbg_mode +#define TOS_dbg_mode uint32_t + +/* Define the various output ports */ +#define MICADBG_TIME ((volatile uint8_t *)(0xFA)) +#define MICADBG_DATA ((volatile uint8_t *)(0xFB)) +#define MICADBG_MODE ((volatile uint32_t *)(0xFC)) + +/* File object to output debugging messages to */ +static FILE* dbg_fileout = NULL; + +static int dbg_putchar(char c) { + /* Copy it into the appropriate memory location */ + *MICADBG_DATA = c; + return 0; +} + +static void dbg_init() { + /* Create a new file to use dbg_putchar */ + if(dbg_fileout == NULL) { + dbg_fileout = fdevopen(dbg_putchar, NULL, 0); + } +} +static void dbg(TOS_dbg_mode mode, const char *format, ...) { + va_list list; + static char buffer[256]; + char *x; + const char *y; + int inFormat; + + /* Freeze time */ + *MICADBG_TIME = 1; + /* Make sure the debugging file has been initialized */ + if(dbg_fileout == NULL) { + dbg_init(); + } + /* Output the debugging type */ + *MICADBG_MODE = mode; + + /* The AVR printf() cannot handle the 'h' character size modifier that + * TinyOS likes to use. */ + x = buffer; + y = format; + inFormat = 0; + while(*y) { + if(!inFormat) { + if(*y == '%') { + inFormat = 1; + } + *(x++) = *(y++); + } else { + switch(*y) { + case 'h': + /* Do nothing */ + y++; + break; + case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': + case 'p': case 'c': case 's': case '%': + case 'e': case 'E': case 'f': case 'F': case 'g': case 'G': + /* Leaving format string */ + inFormat = 0; + /* Fall through */ + default: + *(x++) = *(y++); + } + } /* if(!inFormat) { */ + } /* while(*y) { */ + *x = 0; + /* Print the message with vprintf to stderr */ + va_start(list, format); + vfprintf(dbg_fileout, buffer, list); + va_end(list); + + /* Restore time */ + *MICADBG_TIME = 0; +} + +/* This is sorta implemented in a weird way, just pass to dbg() */ +#define dbg_clear dbg + #else /* No debugging */