voicegetstatus.c
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*---------------------------------------------------------------------
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.2 2003/03/25 20:42:04 blythe Exp $
---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"
#include "siint.h"
#ifndef BBPLAYER
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);
}
#endif