2012-04-29 17:42:35 +02:00
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/iosupport.h>
|
2012-05-05 12:46:01 +02:00
|
|
|
#include <stdarg.h>
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "memory/mem2.hpp"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "wifi_gecko.hpp"
|
|
|
|
|
|
|
|
#define GPRINTF_SIZE 256
|
|
|
|
#define SDWRITE_SIZE 1024
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
bool geckoinit = false;
|
2012-12-08 17:17:35 +01:00
|
|
|
bool sd_inited = false;
|
2012-04-29 17:42:35 +02:00
|
|
|
bool bufferMessages = true;
|
2012-12-08 17:17:35 +01:00
|
|
|
|
|
|
|
char gprintfBuffer[GPRINTF_SIZE];
|
2012-10-10 16:03:04 +02:00
|
|
|
char sdwritebuffer[SDWRITE_SIZE];
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2018-05-08 15:49:43 +02:00
|
|
|
//static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len)
|
|
|
|
static ssize_t __out_write(struct _reent *r __attribute__((unused)), void *fd __attribute__((unused)), const char *ptr, size_t len)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-04-29 17:42:35 +02:00
|
|
|
if(geckoinit && ptr)
|
|
|
|
{
|
|
|
|
u32 level;
|
|
|
|
level = IRQ_Disable();
|
2012-08-05 21:28:54 +02:00
|
|
|
usb_sendbuffer_safe(1, ptr, len);
|
2012-04-29 17:42:35 +02:00
|
|
|
IRQ_Restore(level);
|
|
|
|
}
|
|
|
|
return len;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const devoptab_t gecko_out = {
|
2012-05-05 12:46:01 +02:00
|
|
|
"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
|
|
|
|
NULL, // device statvfs_r
|
|
|
|
NULL, // device ftruncate_r
|
|
|
|
NULL, // device fsync_r
|
|
|
|
NULL, // device deviceData
|
|
|
|
NULL, // device chmod_r
|
|
|
|
NULL, // device fchmod_r
|
2018-05-08 15:49:43 +02:00
|
|
|
NULL, // device rmdir_r
|
2018-10-08 13:29:08 +02:00
|
|
|
//NULL, // lstat_r
|
|
|
|
//NULL, // utimes_r
|
2012-01-21 21:57:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void USBGeckoOutput()
|
|
|
|
{
|
2012-04-29 17:42:35 +02:00
|
|
|
devoptab_list[STD_OUT] = &gecko_out;
|
|
|
|
devoptab_list[STD_ERR] = &gecko_out;
|
|
|
|
}
|
|
|
|
|
2012-12-08 17:17:35 +01:00
|
|
|
static char ascii(char s)
|
|
|
|
{
|
|
|
|
if(s < 0x20)
|
|
|
|
return '.';
|
|
|
|
if(s > 0x7E)
|
|
|
|
return '.';
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:03:04 +02:00
|
|
|
static void WriteToFile(const char* tmp, size_t len)
|
2012-04-29 17:42:35 +02:00
|
|
|
{
|
2012-12-08 17:17:35 +01:00
|
|
|
if(bufferMessages == false)
|
2012-05-13 19:25:26 +02:00
|
|
|
return;
|
|
|
|
|
2012-10-10 16:03:04 +02:00
|
|
|
if((strlen(sdwritebuffer) + len) < SDWRITE_SIZE)
|
|
|
|
strcat(sdwritebuffer, tmp);
|
2012-04-29 17:42:35 +02:00
|
|
|
|
2012-12-08 17:17:35 +01:00
|
|
|
if(sd_inited == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FILE *outfile = fopen("sd:/wiiflow.log", "a");
|
|
|
|
if(outfile)
|
2012-04-29 17:42:35 +02:00
|
|
|
{
|
2012-12-08 17:17:35 +01:00
|
|
|
fwrite(sdwritebuffer, 1, strlen(sdwritebuffer), outfile);
|
|
|
|
memset(sdwritebuffer, 0, SDWRITE_SIZE);
|
|
|
|
fclose(outfile);
|
2012-04-29 17:42:35 +02:00
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-12-08 17:17:35 +01:00
|
|
|
void Gecko_Init(void)
|
|
|
|
{
|
|
|
|
USBGeckoOutput();
|
|
|
|
memset(sdwritebuffer, 0, SDWRITE_SIZE);
|
|
|
|
memset(gprintfBuffer, 0, GPRINTF_SIZE);
|
|
|
|
|
|
|
|
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
|
|
|
|
if(geckoattached)
|
|
|
|
{
|
|
|
|
geckoinit = true;
|
|
|
|
usb_flush(EXI_CHANNEL_1);
|
|
|
|
const char *initstr = "USB Gecko inited.\n";
|
|
|
|
__out_write(NULL, 0, initstr, strlen(initstr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogToSD_SetBuffer(bool buf)
|
|
|
|
{
|
|
|
|
bufferMessages = buf;
|
|
|
|
sd_inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2012-09-23 14:10:25 +02:00
|
|
|
void gprintf(const char *format, ...)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2012-10-10 16:03:04 +02:00
|
|
|
size_t len = vsnprintf(gprintfBuffer, GPRINTF_SIZE - 1, format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
2012-09-23 14:10:25 +02:00
|
|
|
__out_write(NULL, 0, gprintfBuffer, len);
|
2012-12-08 17:17:35 +01:00
|
|
|
WiFiDebugger.Send(gprintfBuffer, len);
|
2012-09-23 14:10:25 +02:00
|
|
|
WriteToFile(gprintfBuffer, len);
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-05-05 12:46:01 +02:00
|
|
|
void ghexdump(void *d, int len)
|
|
|
|
{
|
|
|
|
u8 *data;
|
|
|
|
int i, off;
|
|
|
|
data = (u8*)d;
|
|
|
|
|
|
|
|
gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF");
|
|
|
|
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");
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-12-08 17:17:35 +01:00
|
|
|
#ifdef __cplusplus
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
2012-12-08 17:17:35 +01:00
|
|
|
#endif
|