rdbsend.c
3.21 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "os.h"
#include "os_internal.h"
#include "rdb.h"
#include "R4300.h"
#ifdef BBPLAYER
#include "bbint.h"
#include "bbdebug.h"
#endif
#ifndef _FINALROM
extern rdbPacket * __osRdb_IP6_Data;
extern u32 __osRdb_IP6_Size;
extern u32 __osRdb_IP6_Ct;
extern u32 __osRdb_IP6_CurWrite;
u32 __osRdb_Usb_Active = 0;
extern u32 __osRdb_Usb_GetAvailSendBytes();
void (*__osRdb_Usb_StartSend)(void *, int);
#ifdef BBPLAYER
extern u32 __osRdb_IP6_Empty;
#else
u32 __osRdb_IP6_Empty = 1;
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifdef BBPLAYER
/* Check if the IDE connection is present */
#define PROBE_IDE_RDB() \
(IDE_WRITE(IDE_RDB_RDATA_REG+0,0xbabe), \
IDE_WRITE(IDE_RDB_RDATA_REG+2,0xcafe), \
((IDE_READ(IDE_RDB_RDATA_REG+0) == 0xbabe) & \
(IDE_READ(IDE_RDB_RDATA_REG+2) == 0xcafe)))
#endif
u32 __osRdbSend(u8 *buf, u32 size, u32 type)
{
rdbPacket *pPtr, pkt;
u32 len, c, inCt = 0;
u32 needFirst = 0;
u32 mask;
u32 sent = 0;
#ifdef BBPLAYER
/* call usb initialization automatically */
if (__osRdb_IP6_Data == NULL) {
osBbUsbInit();
/* if IDE is present, it overrides USB */
if (PROBE_IDE_RDB())
__osRdb_Usb_Active = 0;
}
#endif
mask = __osDisableInt();
if(__osRdb_IP6_Empty) /* if there are no transmissions in progress */
{
#ifdef BBPLAYER
if (__osRdb_Usb_Active) {
if (__osRdb_Usb_GetAvailSendBytes() < sizeof pkt) {
/* Not enough space in RDBS - wait until next time */
__osRestoreInt(mask);
return 0;
}
}
#endif
__osRdb_IP6_Empty = 0; /* mark __osRdb_IP6_Empty as FALSE */
pkt.type = (unsigned int)type;
len = MIN(size,3);
pkt.length = (unsigned int)len;
c = 0;
while(c < len)
pkt.buf[c++] = buf[inCt++];
/* Fill the rest with 0 (better debugging) */
while(c < 3)
pkt.buf[c++] = 0;
size -= len;
sent = len;
needFirst = 1;
}
/*
* If there isn't room in the buffer, don't try and send in this block.
* return with the number sent, and let application reenter call.
*/
while((size > 0) && (__osRdb_IP6_Ct < __osRdb_IP6_Size))
{
len = MIN(size,3);
pPtr = &__osRdb_IP6_Data[__osRdb_IP6_CurWrite];
pPtr->type = (unsigned int)type;
pPtr->length = (unsigned int)len;
c = 0;
while(c < len)
pPtr->buf[c++] = buf[inCt++];
/* Fill the rest with 0 (better debugging) */
while(c < 3)
pPtr->buf[c++] = 0;
__osRdb_IP6_CurWrite++;
if(__osRdb_IP6_CurWrite >= __osRdb_IP6_Size)
__osRdb_IP6_CurWrite = 0;
__osRdb_IP6_Ct++;
size -= len;
sent += len;
}
if(needFirst)
{
#ifdef BBPLAYER
if (__osBbIsBb) {
if (__osRdb_Usb_Active) {
(*__osRdb_Usb_StartSend)(&pkt, sizeof pkt);
} else {
IDE_WRITE(IDE_RDB_RDATA_REG, *((u32 *) &pkt)>>16);
IDE_WRITE(IDE_RDB_RDATA_REG+2, *((u32 *) &pkt));
IDE_WRITE(IDE_RDB_CTRL_REG, IDE_RDB_CTRL_SET_BB_REQ);
}
} else
#endif
*((u32 *) RDB_BASE_REG) = *((u32 *) &pkt);
}
#ifdef BBPLAYER
else if (__osBbIsBb && __osRdb_Usb_Active)
(*__osRdb_Usb_StartSend)(NULL, 0);
#endif
__osRestoreInt(mask);
return(sent);
}
#endif /* ifndef _FINALROM */