rdbsend.c 1.6 KB
#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 */