Browse Source

add memory debug buffer.. Fix FreeBSD by adding a delay..

irr_shared
John-Mark Gurney 3 years ago
parent
commit
5baba3ad59
3 changed files with 55 additions and 1 deletions
  1. +11
    -0
      main.c
  2. +33
    -1
      misc.c
  3. +11
    -0
      misc.h

+ 11
- 0
main.c View File

@@ -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


+ 33
- 1
misc.c View File

@@ -26,13 +26,17 @@

#include "misc.h"

#include <stdarg.h>

#include <usbd_cdc_if.h>
#include <usb_device.h>

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

+ 11
- 0
misc.h View File

@@ -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

Loading…
Cancel
Save