osCreatePiManager.c (2063B)
1 #include "libultra_internal.h" 2 #include "PR/os.h" 3 #include "piint.h" 4 5 #include "macros.h" 6 7 #define OS_PI_MGR_MESG_BUFF_SIZE 1 8 9 OSDevMgr __osPiDevMgr = { 0 }; 10 11 #if defined(VERSION_EU) || defined(VERSION_SH) || defined(VERSION_CN) 12 OSPiHandle *__osPiTable = NULL; 13 #endif 14 15 #if defined(VERSION_SH) || defined(VERSION_CN) 16 OSPiHandle *__osCurrentHandle[2] = { &__Dom1SpeedParam, &__Dom2SpeedParam }; 17 #endif 18 19 FORCE_BSS OSThread piMgrThread; 20 FORCE_BSS u32 piMgrStack[0x400]; // stack bottom 21 FORCE_BSS OSMesgQueue piEventQueue; 22 FORCE_BSS OSMesg piEventBuf[OS_PI_MGR_MESG_BUFF_SIZE + 1]; 23 24 extern u32 gOsPiAccessQueueCreated; 25 extern OSMesgQueue gOsPiMessageQueue; 26 void __osDevMgrMain(void *); 27 28 void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt) { 29 u32 int_disabled; 30 OSPri newPri; 31 OSPri currentPri; 32 33 if (!__osPiDevMgr.active) { 34 osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt); 35 osCreateMesgQueue(&piEventQueue, &piEventBuf[0], OS_PI_MGR_MESG_BUFF_SIZE); 36 if (!gOsPiAccessQueueCreated) { 37 __osPiCreateAccessQueue(); 38 } // what is this constant geez 39 osSetEventMesg(OS_EVENT_PI, &piEventQueue, (void *) 0x22222222); 40 newPri = -1; 41 currentPri = osGetThreadPri(NULL); 42 if (currentPri < pri) { 43 newPri = currentPri; 44 osSetThreadPri(NULL, pri); 45 } 46 int_disabled = __osDisableInt(); 47 __osPiDevMgr.active = TRUE; 48 __osPiDevMgr.thread = &piMgrThread; 49 __osPiDevMgr.cmdQueue = cmdQ; 50 __osPiDevMgr.evtQueue = &piEventQueue; 51 __osPiDevMgr.acsQueue = &gOsPiMessageQueue; 52 __osPiDevMgr.dma = osPiRawStartDma; 53 #if defined(VERSION_EU) || defined(VERSION_SH) || defined(VERSION_CN) 54 __osPiDevMgr.edma = osEPiRawStartDma; 55 #endif 56 osCreateThread(&piMgrThread, 0, __osDevMgrMain, (void *) &__osPiDevMgr, &piMgrStack[0x400], pri); 57 osStartThread(&piMgrThread); 58 __osRestoreInt(int_disabled); 59 if (newPri != -1) { 60 osSetThreadPri(NULL, newPri); 61 } 62 } 63 }