2009-04-10 18:15:10 +02:00
|
|
|
/*
|
|
|
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
|
|
|
random utilities
|
|
|
|
|
|
|
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
|
|
|
|
2009-05-11 07:53:16 +02:00
|
|
|
# This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
2009-04-10 18:15:10 +02:00
|
|
|
*/
|
2009-05-11 07:53:16 +02:00
|
|
|
|
2008-12-28 14:35:37 +01:00
|
|
|
#include "types.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
#include "vsprintf.h"
|
2009-01-08 23:27:22 +01:00
|
|
|
#include "start.h"
|
2009-05-05 23:59:41 +02:00
|
|
|
#include "gpio.h"
|
2009-01-08 23:27:22 +01:00
|
|
|
#include "hollywood.h"
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2010-07-04 17:56:03 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-07-09 01:27:09 +02:00
|
|
|
#if !defined(LOADER) && !defined(NDEBUG)
|
2008-12-28 14:35:37 +01:00
|
|
|
static char ascii(char s) {
|
|
|
|
if(s < 0x20) return '.';
|
|
|
|
if(s > 0x7E) return '.';
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-07-04 17:56:56 +02:00
|
|
|
void hexdump(const void *d, int len) {
|
2008-12-28 14:35:37 +01:00
|
|
|
u8 *data;
|
|
|
|
int i, off;
|
|
|
|
data = (u8*)d;
|
|
|
|
for (off=0; off<len; off += 16) {
|
|
|
|
gecko_printf("%08x ",off);
|
|
|
|
for(i=0; i<16; i++)
|
|
|
|
if((i+off)>=len) gecko_printf(" ");
|
|
|
|
else gecko_printf("%02x ",data[off+i]);
|
|
|
|
|
|
|
|
gecko_printf(" ");
|
|
|
|
for(i=0; i<16; i++)
|
|
|
|
if((i+off)>=len) gecko_printf(" ");
|
|
|
|
else gecko_printf("%c",ascii(data[off+i]));
|
|
|
|
gecko_printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2010-07-04 17:56:03 +02:00
|
|
|
|
|
|
|
int sprintf(char *buffer, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
i = vsprintf(buffer, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
return i;
|
|
|
|
}
|
2009-05-05 23:59:41 +02:00
|
|
|
#endif
|
2008-12-28 14:35:37 +01:00
|
|
|
|
2009-01-08 23:27:22 +01:00
|
|
|
void udelay(u32 d)
|
|
|
|
{
|
|
|
|
// should be good to max .2% error
|
|
|
|
u32 ticks = d * 19 / 10;
|
|
|
|
|
|
|
|
if(ticks < 2)
|
|
|
|
ticks = 2;
|
|
|
|
|
|
|
|
u32 now = read32(HW_TIMER);
|
|
|
|
|
|
|
|
u32 then = now + ticks;
|
|
|
|
|
|
|
|
if(then < now) {
|
|
|
|
while(read32(HW_TIMER) >= now);
|
|
|
|
now = read32(HW_TIMER);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(now < then) {
|
|
|
|
now = read32(HW_TIMER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void panic(u8 v)
|
|
|
|
{
|
|
|
|
while(1) {
|
|
|
|
debug_output(v);
|
2009-05-05 23:59:41 +02:00
|
|
|
set32(HW_GPIO1BOUT, GP_SLOTLED);
|
2009-01-08 23:27:22 +01:00
|
|
|
udelay(500000);
|
|
|
|
debug_output(0);
|
2009-05-05 23:59:41 +02:00
|
|
|
clear32(HW_GPIO1BOUT, GP_SLOTLED);
|
2009-01-08 23:27:22 +01:00
|
|
|
udelay(500000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|