piacs.c 2.52 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.  *
 *                                                                        *
 **************************************************************************/

/**************************************************************************
 *
 *  Module: iopiacs.c
 *
 *  $Revision: 1.1.1.2 $
 *  $Date: 2002/10/29 08:06:43 $
 *  $Author: blythe $
 *  $Source: /root/leakn64/depot/rf/sw/bbplayer/libultra/nintendo/pi/piacs.c,v $
 *
 *  Description:
 *	This file contains routines to get access to the PI device.
 *
 **************************************************************************/


#include "osint.h"
#include "rcp.h"


#define NUM_ACCESS_MESG		1

/* Access queue used for mutual exclusion on PI */
static OSMesg	piAccessBuf[NUM_ACCESS_MESG];

int		__osPiAccessQueueEnabled = 0;
OSMesgQueue	__osPiAccessQueue;


/*
 * Name:   __osPiCreateAccessQueue
 *
 * Description:
 *	
 *
 * Globals Referenced: 
 *	None
 */
void
__osPiCreateAccessQueue(void)
{
    __osPiAccessQueueEnabled = 1;

    osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, NUM_ACCESS_MESG);

    /* Initialize the access queue with a resource token */
    (void)osSendMesg(&__osPiAccessQueue, (OSMesg)0, OS_MESG_NOBLOCK);
}


/*
 * Name:   __osPiGetAccess
 *
 * Description:
 *	Get the access right to PI by blocking on the access queue. 
 *
 * Globals Referenced: 
 *	__osPiAccessQueue
 */
void
__osPiGetAccess(void)
{
    OSMesg dummyMesg;

    /* Create access message queue if haven't done so */
    if (!__osPiAccessQueueEnabled) {
        __osPiCreateAccessQueue();
    }

    (void)osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK);
}


/*
 * Name:   __osPiRelAccess
 *
 * Description:
 *	Release the access right to PI by sending a mesg to the access queue. 
 *
 * Globals Referenced: 
 *	__osPiAccessQueue
 */
void
__osPiRelAccess(void)
{
    (void)osSendMesg(&__osPiAccessQueue, (OSMesg)0, OS_MESG_NOBLOCK);
}