2015-04-22 01:31:31 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-04-23 23:22:40 +08:00
|
|
|
#include <generated/csr.h>
|
|
|
|
|
2015-04-22 01:31:31 +08:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static int buffer_index;
|
|
|
|
static char buffer[LOG_BUFFER_SIZE];
|
|
|
|
|
|
|
|
void log_va(const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
char outbuf[256];
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
buffer[buffer_index] = outbuf[i];
|
|
|
|
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
buffer[buffer_index] = '\n';
|
|
|
|
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
|
2015-04-23 23:22:40 +08:00
|
|
|
|
|
|
|
#ifdef CSR_ETHMAC_BASE
|
|
|
|
/* Since main comms are over ethernet, the serial port
|
|
|
|
* is free for us to use. */
|
|
|
|
puts(outbuf);
|
|
|
|
#endif
|
2015-04-22 01:31:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
log_va(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_get(char *outbuf)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
j = buffer_index + 1;
|
|
|
|
for(i=0;i<LOG_BUFFER_SIZE;i++) {
|
|
|
|
outbuf[i] = buffer[j];
|
|
|
|
j = (j + 1) % LOG_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
}
|