diff --git a/main.c b/main.c index 923e105..b1bbdfc 100644 --- a/main.c +++ b/main.c @@ -190,6 +190,8 @@ int main(void) { + debug_printf("starting...\n"); + BoardInitMcu(); Radio.Init(&revents); @@ -200,6 +202,15 @@ main(void) #if 1 wait_for_vcp(); + /* + * This is required to use w/ FreeBSD. Not sure why but if this + * delay isn't here, the code will hang waiting for the output to + * be sent, and it never does get sent. I believe this is because + * the packet to enable sending the data hasn't arrived yet, and + * this code fails to handle that case, and drops the data on the + * floor. + */ + DelayMs(50); usb_printf("starting...\r\n"); #endif diff --git a/misc.c b/misc.c index aeeb6c7..0e9c847 100644 --- a/misc.c +++ b/misc.c @@ -26,13 +26,17 @@ #include "misc.h" +#include + #include #include +static volatile uint32_t holding; void Error_Handler(void) { - /* XXX - handle error */ + debug_printf("error_handler\n"); + for (;;) holding++; } /* @@ -48,3 +52,31 @@ wait_for_vcp(void) } } +#if MEM_DEBUG_BUF +static char debugbuf[1024]; +static uint32_t debugpos; + +void +debug_printf(const char *format, ...) +{ + char buf[128]; + char *pos; + va_list args; + uint32_t length; + uint32_t cpy; + + va_start(args, format); + length = vsnprintf(buf, sizeof buf, format, args); + va_end(args); + + pos = &buf[0]; + while (length) { + cpy = MIN(length, sizeof debugbuf - debugpos); + memcpy(&debugbuf[debugpos], pos, cpy); + + debugpos += cpy; + pos += cpy; + length -= cpy; + } +} +#endif diff --git a/misc.h b/misc.h index fb0f741..1495ec8 100644 --- a/misc.h +++ b/misc.h @@ -1,2 +1,13 @@ void wait_for_vcp(void); void Error_Handler(void); + +#define MEM_DEBUG_BUF 0 + +#if MEM_DEBUG_BUF +void debug_printf(const char *format, ...); +#else +static inline void +debug_printf(const char *format, ...) +{ +} +#endif