1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 13:54:44 +00:00
oot/src/libultra_boot_O2/pimgr.c

59 lines
1.6 KiB
C
Raw Normal View History

#include "global.h"
#include "ultra64/internal.h"
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
OSMgrArgs __osPiDevMgr = { 0 };
2020-03-17 04:31:30 +00:00
OSPiHandle __Dom1SpeedParam;
OSPiHandle __Dom2SpeedParam;
OSThread piThread;
u8 piStackThread[0x1000];
OSMesgQueue piEventQueue;
OSMesg piEventBuf[2];
OSThread __osThreadSave;
OSPiHandle* __osPiTable = NULL;
2020-03-22 21:19:43 +00:00
OSPiHandle* __osCurrentHandle[] = {
2020-03-17 04:31:30 +00:00
&__Dom1SpeedParam,
&__Dom2SpeedParam,
};
2020-03-22 21:19:43 +00:00
void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) {
2020-03-17 04:31:30 +00:00
u32 int_disabled;
OSPri newPri;
OSPri currentPri;
2020-03-22 21:19:43 +00:00
if (!__osPiDevMgr.initialized) {
2020-03-17 04:31:30 +00:00
osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt);
osCreateMesgQueue(&piEventQueue, piEventBuf, 1);
2020-03-22 21:19:43 +00:00
if (!__osPiAccessQueueEnabled) {
2020-03-17 04:31:30 +00:00
__osPiCreateAccessQueue();
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)0x22222222);
newPri = -1;
currentPri = osGetThreadPri(NULL);
2020-03-22 21:19:43 +00:00
if (currentPri < pri) {
2020-03-17 04:31:30 +00:00
newPri = currentPri;
osSetThreadPri(NULL, pri);
}
int_disabled = __osDisableInt();
__osPiDevMgr.initialized = true;
__osPiDevMgr.cmdQueue = cmdQ;
__osPiDevMgr.mgrThread = &piThread;
__osPiDevMgr.eventQueue = &piEventQueue;
__osPiDevMgr.acccessQueue = &__osPiAccessQueue;
__osPiDevMgr.piDmaCallback = __osPiRawStartDma;
__osPiDevMgr.epiDmaCallback = __osEPiRawStartDma;
2020-03-22 21:19:43 +00:00
osCreateThread(&piThread, 0, __osDevMgrMain, (void*)&__osPiDevMgr, piStackThread + sizeof(piStackThread), pri);
2020-03-17 04:31:30 +00:00
osStartThread(&piThread);
__osRestoreInt(int_disabled);
2020-03-22 21:19:43 +00:00
if (newPri != -1) {
2020-03-17 04:31:30 +00:00
osSetThreadPri(NULL, newPri);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
}