readhost.c 2.9 KB
/**************************************************************************
 *									  *
 *		 Copyright (C) 1995, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

#include <os.h>
#include <os_internal.h>
#include <rdb.h>


#ifndef _FINALROM
static int		readHostInitialized = 0;
static OSMesgQueue	readHostMesgQueue;
static OSMesg		readHostMesgBuf[1];

/*
 * Name:   osReadHost
 *
 * Description:
 *	Copy nbytes of data from the host to DRAM starting at dramAddr
 *
 * CAUTION: Application must insure that only one call to osReadHost at a time!!!
 * 
 * How it works:
 *   An application on the indy must open /dev/u64_data. Then the host app
 *   calls uhWriteGame with the data to be sent. The write call will block until
 *   the game sends a signal, indicating that it is ready to receive the data.
 *   When the write call receives the signal, it will start sending data over the
 *   rdb port, which will be stored in the buffer pointed to by __osRdb_Read_Data_Buf.
 *   When __osRdb_Read_Data_Ct is reached, exceptasm will generate a message of
 *   OS_EVENT_RDB_READ_DONE.   
 *
 *   Timing of which call is made first, osReadHost, or uhWriteGame is not critical. 
 *   If uhWriteGame occurs first, host will block, if osReadHost occurs first, host 
 *   kernal will save the ready message, and start once uhWriteGame occurs. Meanwhile,
 *   osReadHost will block waiting for done message. Note that osReadHost does block, 
 *   and stops the running of the thread that called it.
 *
 *   Potential problems occur if osReadHost is called, but not matched by an equivilent
 *   uhWriteGame call from the host.
 */

u8   *__osRdb_Read_Data_Buf;
u32  __osRdb_Read_Data_Ct;


void osReadHost(void *dramAddr, u32 nbytes)
{
    unsigned char  tstr[4];
    u32  sent = 0;

    /* The first time through, initialize a message queue for completion ack  */
    if (!readHostInitialized) 
    {
	osCreateMesgQueue(&readHostMesgQueue, readHostMesgBuf, 1);
	osSetEventMesg(OS_EVENT_RDB_READ_DONE, &readHostMesgQueue,NULL);
	readHostInitialized = 1;
    }

    /* set up pointers and counters used by exceptasm */
    __osRdb_Read_Data_Buf = (u8*)dramAddr;
    __osRdb_Read_Data_Ct = nbytes;
    /* send message to host telling host, you are ready for data */
    while(sent < 1)
	sent += __osRdbSend(&tstr[0],1,RDB_TYPE_GtoH_READY_FOR_DATA);
    /* block waiting for all data to be transferred */
    (void)osRecvMesg(&readHostMesgQueue, NULL, OS_MESG_BLOCK); 
    return;
}

#endif /* ifndef _FINALROM */