2010-06-03 18:37:14 +02:00
|
|
|
#include <gccore.h>
|
2009-12-03 02:06:09 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-11-12 19:14:09 +01:00
|
|
|
#include <stdarg.h>
|
2010-11-06 16:30:14 +01:00
|
|
|
#include <malloc.h>
|
2010-12-03 19:38:57 +01:00
|
|
|
#include <sys/iosupport.h>
|
2009-11-01 00:23:27 +01:00
|
|
|
|
2013-10-01 23:13:08 +02:00
|
|
|
// #define DEBUG_TO_FILE
|
|
|
|
// #define WIFI_GECKO // don't keep this for released build
|
|
|
|
|
|
|
|
#ifdef WIFI_GECKO
|
|
|
|
#include <utils/wifi_gecko.h>
|
|
|
|
#endif
|
|
|
|
|
2009-11-01 00:23:27 +01:00
|
|
|
/* init-globals */
|
2010-11-28 16:31:08 +01:00
|
|
|
static bool geckoinit = false;
|
2009-11-01 00:23:27 +01:00
|
|
|
|
2010-11-06 16:30:14 +01:00
|
|
|
void gprintf(const char *format, ...)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2012-05-06 12:59:58 +02:00
|
|
|
#ifndef DEBUG_TO_FILE
|
2013-10-01 23:13:08 +02:00
|
|
|
#ifndef WIFI_GECKO
|
|
|
|
if (!geckoinit)
|
|
|
|
return;
|
|
|
|
#endif
|
2012-05-06 12:59:58 +02:00
|
|
|
#endif
|
2010-11-06 16:30:14 +01:00
|
|
|
|
2011-11-12 19:14:09 +01:00
|
|
|
static char stringBuf[4096];
|
|
|
|
int len;
|
2010-11-06 16:30:14 +01:00
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2011-11-12 19:14:09 +01:00
|
|
|
if((len = vsnprintf(stringBuf, sizeof(stringBuf), format, va)) > 0)
|
2010-11-06 16:30:14 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
#ifdef DEBUG_TO_FILE
|
|
|
|
FILE *debugF = fopen("sd:/debug.txt", "a");
|
|
|
|
if(!debugF)
|
|
|
|
debugF = fopen("sd:/debug.txt", "w");
|
|
|
|
if(debugF)
|
2012-05-06 12:59:58 +02:00
|
|
|
{
|
|
|
|
fwrite(stringBuf, 1, strlen(stringBuf), debugF);
|
|
|
|
fclose(debugF);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
usb_sendbuffer(1, stringBuf, len);
|
2011-07-26 00:28:22 +02:00
|
|
|
#endif
|
2013-10-01 23:13:08 +02:00
|
|
|
|
|
|
|
#ifdef WIFI_GECKO
|
|
|
|
wifi_printf(stringBuf);
|
|
|
|
#endif
|
2010-11-06 16:30:14 +01:00
|
|
|
}
|
|
|
|
va_end(va);
|
2010-06-03 18:36:25 +02:00
|
|
|
}
|
2009-10-20 13:46:55 +02:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
bool InitGecko()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
|
|
|
if (geckoattached)
|
|
|
|
{
|
|
|
|
usb_flush(EXI_CHANNEL_1);
|
|
|
|
geckoinit = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-10-20 13:46:55 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
char ascii(char s)
|
2010-09-16 12:22:24 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (s < 0x20) return '.';
|
|
|
|
if (s > 0x7E) return '.';
|
|
|
|
return s;
|
2010-09-16 12:22:24 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void hexdump(void *d, int len)
|
2010-09-16 12:22:24 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u8 *data;
|
|
|
|
int i, off;
|
|
|
|
data = (u8*) d;
|
|
|
|
|
2014-07-14 18:31:52 +02:00
|
|
|
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
2011-07-26 00:28:22 +02:00
|
|
|
gprintf("\n==== =============================================== ================\n");
|
|
|
|
|
|
|
|
for (off = 0; off < len; off += 16)
|
|
|
|
{
|
|
|
|
gprintf("%04x ", off);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if ((i + off) >= len)
|
|
|
|
gprintf(" ");
|
|
|
|
else gprintf("%02x ", data[off + i]);
|
|
|
|
|
|
|
|
gprintf(" ");
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if ((i + off) >= len)
|
|
|
|
gprintf(" ");
|
|
|
|
else gprintf("%c", ascii(data[off + i]));
|
|
|
|
gprintf("\n");
|
|
|
|
}
|
2010-09-16 12:22:24 +02:00
|
|
|
}
|
|
|
|
|
2017-12-14 15:26:57 +01:00
|
|
|
static ssize_t __out_write(struct _reent *r, void *fd, const char *ptr, size_t len)
|
2010-12-03 19:38:57 +01:00
|
|
|
{
|
2012-01-01 18:58:10 +01:00
|
|
|
if(len > 0)
|
|
|
|
usb_sendbuffer(1, ptr, len);
|
2010-12-03 19:38:57 +01:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const devoptab_t gecko_out = {
|
|
|
|
"stdout", // device name
|
|
|
|
0, // size of file structure
|
|
|
|
NULL, // device open
|
|
|
|
NULL, // device close
|
|
|
|
__out_write,// device write
|
|
|
|
NULL, // device read
|
|
|
|
NULL, // device seek
|
|
|
|
NULL, // device fstat
|
|
|
|
NULL, // device stat
|
|
|
|
NULL, // device link
|
|
|
|
NULL, // device unlink
|
|
|
|
NULL, // device chdir
|
|
|
|
NULL, // device rename
|
|
|
|
NULL, // device mkdir
|
|
|
|
0, // dirStateSize
|
|
|
|
NULL, // device diropen_r
|
|
|
|
NULL, // device dirreset_r
|
|
|
|
NULL, // device dirnext_r
|
|
|
|
NULL, // device dirclose_r
|
2011-02-06 19:36:32 +01:00
|
|
|
NULL, // device statvfs_r
|
|
|
|
NULL, // device ftruncate_r
|
|
|
|
NULL, // device fsync_r
|
|
|
|
NULL, // device deviceData
|
|
|
|
NULL, // device chmod_r
|
|
|
|
NULL, // device fchmod_r
|
2017-12-14 15:26:57 +01:00
|
|
|
NULL, // device rmdir_r
|
2020-12-12 22:35:12 +01:00
|
|
|
#if __GNUC__ > 8
|
|
|
|
NULL, // lstat_r
|
|
|
|
NULL, // utimes_r
|
|
|
|
#endif
|
2010-12-03 19:38:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void USBGeckoOutput()
|
|
|
|
{
|
|
|
|
devoptab_list[STD_OUT] = &gecko_out;
|
|
|
|
devoptab_list[STD_ERR] = &gecko_out;
|
|
|
|
}
|