pimgr.c
5.54 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*====================================================================
* pimgr.c
*
* Copyright 1994-1995, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
/**************************************************************************
*
* $Revision: 1.2 $
* $Date: 2004/02/06 02:16:48 $
* $Source: /root/leakn64/depot/rf/sw/bbplayer/libultra/nintendo/pi/pimgr.c,v $
*
* Description:
* Peripheral Interface Manager (PIM)
* Create a high priority thread to handle Peripheral Interface (PI)
* requests.
*
**************************************************************************/
#include "osint.h"
#include "piint.h"
#include "rcp.h"
/* Number of message entries in event queues */
#define NUM_EV_MESG 1
#define PI_EVENT_MESG 0x22222222
/*
* Static variables
*/
static OSThread piThread; /* PIM Thread structure */
static char piThreadStack[OS_PIM_STACKSIZE];
#ifndef _FINALROM
#include <rdb.h>
#define OS_PIM_RAMROM_STACKSIZE 1024
static OSThread ramromThread; /* PIM Thread structure */
static char ramromThreadStack[OS_PIM_RAMROM_STACKSIZE];
static OSMesgQueue getRamromQ;
static OSMesg getRamromBuf[1];
static OSMesgQueue freeRamromQ;
static OSMesg freeRamromBuf[1];
static void ramromMain(void *);
#endif
static OSMesgQueue piEventQueue; /* Event queue structure */
static OSMesg piEventBuf[NUM_EV_MESG];
/*
* Global variables
*/
OSDevMgr __osPiDevMgr = {0}; /* Device Manager structure */
OSPiHandle *__osPiTable = (OSPiHandle*)NULL; /* Device Table */
/* running PI device */
OSPiHandle __Dom1SpeedParam, __Dom2SpeedParam;
OSPiHandle *__osCurrentHandle[2] = {&__Dom1SpeedParam, &__Dom2SpeedParam};
/* OSPiHandle __LowSpeedDom1Handle; */
/*
* Extern declarations
*/
extern OSMesgQueue __osPiAccessQueue;
extern int __osPiAccessQueueEnabled;
extern void __osPiCreateAccessQueue(void);
/*
* Name: osCreatePiManager
*
* Description:
* Create and start the Peripheral Interface Manager (PIM).
* Caller specifies the necessary parameters to create PIM command queue.
*
* Globals Referenced:
* __osPiDevMgr
* __osPiAccessQueueEnabled
* piEventQueue
* piEventBuf
* piThread
* piThreadStack
* osDevMgrMain
*/
void
osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt)
{
u32 savedMask;
OSPri oldPri, myPri;
#ifdef _DEBUG
if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) {
__osError(ERR_OSCREATEPIMANAGER, 1, pri);
return;
}
#endif
/* If PI Manager is already running, simply return */
if (__osPiDevMgr.active)
return;
/* Create the input I/O command queue, wait queue, and access queue */
osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt);
osCreateMesgQueue(&piEventQueue, piEventBuf, NUM_EV_MESG);
if (!__osPiAccessQueueEnabled)
__osPiCreateAccessQueue();
/* Take over PI interrupt */
osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)PI_EVENT_MESG);
/*
* Check the current thread priority against the PIM's priority.
* If current is lower, temporarily increase it to same level as PIM
*/
oldPri = -1;
myPri = osGetThreadPri((OSThread *)NULL);
if (myPri < pri) {
oldPri = myPri;
osSetThreadPri((OSThread *)NULL, pri);
}
/* Set global to tell that Peripheral Interface Manager is on and active */
savedMask = __osDisableInt();
__osPiDevMgr.active = 1;
__osPiDevMgr.thread = &piThread;
__osPiDevMgr.cmdQueue = cmdQ;
__osPiDevMgr.evtQueue = &piEventQueue;
__osPiDevMgr.acsQueue = &__osPiAccessQueue;
__osPiDevMgr.dma = __osPiRawStartDma;
__osPiDevMgr.edma = __osEPiRawStartDma;
osCreateThread(&piThread, OS_TID_PIMGR, __osDevMgrMain, (void *)&__osPiDevMgr,
piThreadStack+OS_PIM_STACKSIZE, (OSPri)pri);
osStartThread(&piThread);
#ifndef _FINALROM
osCreateThread(&ramromThread, OS_TID_RAMROM, ramromMain, NULL,
ramromThreadStack+OS_PIM_RAMROM_STACKSIZE, (OSPri)pri - 1);
osStartThread(&ramromThread);
#endif /* ifndef _FINALROM */
/* Restore original interrupt mask */
__osRestoreInt(savedMask);
/* Restore original thread priority */
if (oldPri != -1)
osSetThreadPri((OSThread *)NULL, oldPri);
} /* osCreatePiManager */
#ifndef _FINALROM
static void ramromMain(void *arg)
{
u32 sent;
u8 tmp[3];
osCreateMesgQueue(&getRamromQ, getRamromBuf, 1);
osCreateMesgQueue(&freeRamromQ, freeRamromBuf, 1);
osSetEventMesg(OS_EVENT_RDB_REQ_RAMROM, &getRamromQ, NULL);
osSetEventMesg(OS_EVENT_RDB_FREE_RAMROM, &freeRamromQ, NULL);
while(1)
{
osRecvMesg(&getRamromQ, NULL, OS_MESG_BLOCK);
/* Block to get resource token */
__osPiGetAccess();
sent = 0;
while(sent < 1)
sent += __osRdbSend(tmp,1,RDB_TYPE_GtoH_RAMROM);
osRecvMesg(&freeRamromQ, NULL, OS_MESG_BLOCK);
/* Return resource token */
__osPiRelAccess();
}
}
#endif