voicegetstatus.c 1.92 KB
/*---------------------------------------------------------------------
 	Copyright (C) 1997, Nintendo.
 	
 	File		voicegetstatus.c
 	Coded    by	Koji Mitsunari.	Oct  6, 1997.
 	Modified by	Koji Mitsunari.	Jul  3, 1998.
 	Comments	Voice Recognition System
   
 	$Id: voicegetstatus.c,v 1.1.1.1 2002/05/02 03:28:44 blythe Exp $
   ---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"
#include "siint.h"

s32
__osVoiceGetStatus(OSMesgQueue *mq, int channel, u8 *status)
{
  __OSContRequesFormatShort 	readformat;
  s32				ret = 0;
  int				i;
  u8 				*ptr = (u8 *)(&__osContPifRam);
  int				retry = 2;

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

  do {
    if (ret != CONT_ERR_CONTRFAIL) {
      __osContPifRam.pifstatus = CONT_FORMAT;

      for (i = 0; i < channel; i++, *ptr++ = 0);

      *ptr++ = 1;			/* TX SIZE */
      *ptr++ = 3;			/* RX SIZE */
      *ptr = CONT_REQUEST;		/* COMMAND */
      ptr += 4;
      *ptr = FORMAT_END;

      __osContLastCmd = CONT_ETC;
      ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam);
      (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
    }
    /* trigger pifmacro */
    ret = __osSiRawStartDma(OS_READ, &__osContPifRam);
    (void)osRecvMesg(mq, (OSMesg *)NULL, OS_MESG_BLOCK);
	
    ptr = (u8 *)(&__osContPifRam) + channel;

    readformat = *((__OSContRequesFormatShort *)ptr);

    ret = (u8)((readformat.rxsize & CON_ERR_MASK) >> 4);
    *status = readformat.status;
  
    if (ret == 0) {
      if (readformat.typeh == 0 && readformat.typel == 1) {
	if (readformat.status & 4) {
	  ret = CONT_ERR_CONTRFAIL;
	}
      } else {
	ret = CONT_ERR_DEVICE;
      }
    } else if (ret & CONT_NO_RESPONSE_ERROR) {
      ret = CONT_ERR_NO_CONTROLLER;
    } else {
      ret = CONT_ERR_CONTRFAIL;
    }
  } while ((ret == CONT_ERR_CONTRFAIL) && (retry-- >= 0));

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