rdbsend.c
1.6 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
#include "os.h"
#include "os_internal.h"
#include "rdb.h"
#include "R4300.h"
#ifndef _FINALROM
extern rdbPacket * __osRdb_IP6_Data;
extern u32 __osRdb_IP6_Size;
extern u32 __osRdb_IP6_Ct;
extern u32 __osRdb_IP6_CurWrite;
u32 __osRdb_IP6_Empty = 1;
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#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;
mask = __osDisableInt();
if(__osRdb_IP6_Empty) /* if there are no transmissions in progress */
{
__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++];
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++];
__osRdb_IP6_CurWrite++;
if(__osRdb_IP6_CurWrite >= __osRdb_IP6_Size)
__osRdb_IP6_CurWrite = 0;
__osRdb_IP6_Ct++;
size -= len;
sent += len;
}
if(needFirst)
{
*((u32 *) RDB_BASE_REG) = *((u32 *) &pkt);
}
__osRestoreInt(mask);
return(sent);
}
#endif /* ifndef _FINALROM */