testunitready.c 895 Bytes

#include <ultra64.h>

#ifndef	_LONGCMD
#include <leo.h>
#else
#include <leosp.h>
#endif

extern 	s32	__leoActive;

s32 LeoTestUnitReady(LEOStatus *status)
{
  volatile LEOCmdTestUnitReady	cmdBlock;
  
  /* 
   * Check for existence of Leo Manager 
   */
  if (!__leoActive) {
    return(-1);
  }
  
  /*
   * Check to see if PI bus is busy. If so, return LEO_ERROR_BUSY.
   *   (if IO_BUSY it's O.K., because it will be done soon.)
   */
  if (IO_READ(PI_STATUS_REG) & PI_STATUS_DMA_BUSY)
    return LEO_ERROR_BUSY;

  /*
   * Fill up command block
   */
  cmdBlock.header.command	= LEO_COMMAND_TEST_UNIT_READY;
  cmdBlock.header.reserve1	= 0;
  cmdBlock.header.control	= 0;
  cmdBlock.header.reserve3	= 0;

  leoCommand((void *)&cmdBlock);

  while(cmdBlock.header.status == LEO_STATUS_BUSY)
    ;
  
  *status = cmdBlock.test;
  
  return (cmdBlock.header.sense);
  
} /* LeoTestUnitReady */