-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.c
91 lines (74 loc) · 1.69 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
random utilities
Copyright (C) 2008, 2009 Hector Martin "marcan" <[email protected]>
# 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
*/
#include "types.h"
#include "utils.h"
#include "gecko.h"
#include "vsprintf.h"
#include "start.h"
#include "gpio.h"
#include "hollywood.h"
#include <stdarg.h>
#if defined(CAN_HAZ_USBGECKO) && !defined(LOADER) && !defined(NDEBUG)
static char ascii(char s) {
if(s < 0x20) return '.';
if(s > 0x7E) return '.';
return s;
}
void hexdump(const void *d, int len) {
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");
}
}
#endif
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;
}
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);
set32(HW_GPIO1BOUT, GP_SLOTLED);
udelay(500000);
debug_output(0);
clear32(HW_GPIO1BOUT, GP_SLOTLED);
udelay(500000);
}
}