contreset.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.  *
 *                                                                        *
 **************************************************************************/

#include "osint.h"
#include "controller.h"
#include "siint.h"

/*
 * This call issues a reset command to controllers to return joystick
 * back to neutral position.
 * A value of 0 is returned if the calls succeed, otherwise
 * -1 is returned
 */
s32
osContReset(OSMesgQueue *mq, OSContStatus *data)
{
  u8	pattern;
  s32 	ret;

  /* Block to get resource token */
  __osSiGetAccess();

  if (CONT_RESET != __osContLastCmd) {

    /* Set up request command format for all channels */

#if !defined(_HW_VERSION_1) && !defined(BBPLAYER)
    __osPackResetData();
    ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam);
    (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
    ret = __osSiRawStartDma(OS_READ, &__osContPifRam);
    (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
#endif
    __osPackRequestData(CONT_RESET);
    ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam);
    (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);

    /* 
     * Always make the last command an illegal one, so we never optimize
     * out the DMA write
     */
    __osContLastCmd = CONT_SETCH - 1;
  }

  /* trigger pifmacro */

  ret = __osSiRawStartDma(OS_READ, &__osContPifRam);
  (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);

  /* reformat the 64 bytes RAM data and save in data array */

  __osContGetInitData(&pattern, data);

  /* Return resource token */
  __osSiRelAccess();
  return(ret);
}

#ifndef _HW_VERSION_1
void
__osPackResetData(void)
{
  u8 	*ptr;
  int	i;

  /* set format flag */

  __osContPifRam.pifstatus = CONT_FORMAT;

  ptr = (u8 *)(&__osContPifRam);

  /* Setup reset format for each channel */

  for (i = 0; i < MAXCONTROLLERS; i++) {
    *ptr++ = CHANNEL_RESET;
  }
  *((u8 *)ptr) = FORMAT_END;
}
#endif