Skip to content

Commit c93feb0

Browse files
committed
Add SYS_Report{,v}
Add SYS_EnableGecko
1 parent 72b0615 commit c93feb0

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ OGCOBJ := \
144144
console_font_8x16.o timesupp.o lock_supp.o newlibc.o usbgecko.o usbmouse.o \
145145
sbrk.o malloc_lock.o kprintf.o stm.o ios.o es.o isfs.o usb.o network_common.o \
146146
sdgecko_io.o sdgecko_buf.o gcsd.o argv.o network_wii.o wiisd.o conf.o usbstorage.o \
147-
texconv.o wiilaunch.o mic.o
147+
texconv.o wiilaunch.o mic.o system_report.o
148148

149149
#---------------------------------------------------------------------------------
150150
MODOBJ := freqtab.o mixer.o modplay.o semitonetab.o gcmodplay.o

gc/ogc/system.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ distribution.
3838

3939
#include <gctypes.h>
4040
#include <gcutil.h>
41+
#include <stdarg.h>
4142
#include <time.h>
4243
#include <ogc/lwp_queue.h>
4344
#include "gx_struct.h"
@@ -425,6 +426,10 @@ u32 SYS_GetSimulatedMem2Size(void);
425426
powercallback SYS_SetPowerCallback(powercallback cb);
426427
#endif
427428

429+
void SYS_Report(const char *msg,...);
430+
void SYS_Reportv(const char *msg,va_list list);
431+
void SYS_EnableGecko(s32 chan,bool safe);
432+
428433
void kprintf(const char *fmt,...);
429434

430435
#ifdef __cplusplus

libogc/system_report.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*-------------------------------------------------------------
2+
3+
system_report.c -- Formatted output to serial port
4+
5+
Copyright (C) 2025 Extrems' Corner.org
6+
7+
This software is provided 'as-is', without any express or implied
8+
warranty. In no event will the authors be held liable for any
9+
damages arising from the use of this software.
10+
11+
Permission is granted to anyone to use this software for any
12+
purpose, including commercial applications, and to alter it and
13+
redistribute it freely, subject to the following restrictions:
14+
15+
1. The origin of this software must not be misrepresented; you
16+
must not claim that you wrote the original software. If you use
17+
this software in a product, an acknowledgment in the product
18+
documentation would be appreciated but is not required.
19+
20+
2. Altered source versions must be plainly marked as such, and
21+
must not be misrepresented as being the original software.
22+
23+
3. This notice may not be removed or altered from any source
24+
distribution.
25+
26+
-------------------------------------------------------------*/
27+
28+
#include <gctypes.h>
29+
#include <ogc/system.h>
30+
#include <ogc/usbgecko.h>
31+
#include <stdarg.h>
32+
#include <stdio.h>
33+
34+
static FILE *fp = NULL;
35+
static s32 Chan = -1;
36+
static bool Safe = true;
37+
38+
extern s32 InitializeUART(void);
39+
extern s32 WriteUARTN(void *buf, u32 len);
40+
41+
static int WriteReport(void *c, const char *buf, int n)
42+
{
43+
if (usb_isgeckoalive(Chan)) {
44+
if (Safe)
45+
return usb_sendbuffer_safe(Chan, buf, n);
46+
else
47+
return usb_sendbuffer(Chan, buf, n);
48+
} else {
49+
if (InitializeUART() != 0)
50+
return -1;
51+
if (WriteUARTN((void *)buf, n) != 0)
52+
return -1;
53+
}
54+
55+
return n;
56+
}
57+
58+
static void __attribute__((constructor)) __SYS_InitReport(void)
59+
{
60+
fp = fwopen(NULL, WriteReport);
61+
setlinebuf(fp);
62+
}
63+
64+
static void __attribute__((destructor)) __SYS_DeinitReport(void)
65+
{
66+
fclose(fp);
67+
fp = NULL;
68+
}
69+
70+
void __attribute__((weak)) SYS_Report(const char *msg, ...)
71+
{
72+
va_list list;
73+
va_start(list, msg);
74+
vfprintf(fp, msg, list);
75+
va_end(list);
76+
}
77+
78+
void __attribute__((weak)) SYS_Reportv(const char *msg, va_list list)
79+
{
80+
vfprintf(fp, msg, list);
81+
}
82+
83+
void SYS_EnableGecko(s32 chan, bool safe)
84+
{
85+
flockfile(fp);
86+
Chan = chan;
87+
Safe = safe;
88+
funlockfile(fp);
89+
}

libogc/usbgecko.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
static u32 usbgecko_inited = 0;
19-
static lwpq_t wait_exi_queue[3];
19+
static lwpq_t wait_exi_queue[EXI_CHANNEL_MAX];
2020

2121
static s32 __usbgecko_exi_unlock(s32 chan,s32 dev)
2222
{
@@ -161,6 +161,9 @@ int usb_isgeckoalive(s32 chn)
161161
s32 ret;
162162
u16 val;
163163

164+
if (chn < EXI_CHANNEL_0 || chn >= EXI_CHANNEL_MAX)
165+
return 0;
166+
164167
while (EXI_ProbeEx(chn) == 0);
165168

166169
if (EXI_GetID(chn, EXI_DEVICE_0, &id) == 0)

0 commit comments

Comments
 (0)