2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-11 00:04:41 +00:00
|
|
|
void func_800C3C80(AudioMgr* audioMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
AudioTask* task = audioMgr->rspTask;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
if (audioMgr->rspTask->msgQueue != NULL) {
|
|
|
|
osSendMesg(task->msgQueue, NULL, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-11 00:04:41 +00:00
|
|
|
void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
|
2021-07-27 23:44:58 +00:00
|
|
|
AudioTask* rspTask;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-11 00:04:41 +00:00
|
|
|
if (SREG(20) > 0) {
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->rspTask = NULL;
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
if (audioMgr->rspTask != NULL) {
|
|
|
|
audioMgr->audioTask.next = NULL;
|
2022-04-09 00:20:23 +00:00
|
|
|
audioMgr->audioTask.flags = OS_SC_NEEDS_RSP;
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->audioTask.framebuffer = NULL;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->audioTask.list = audioMgr->rspTask->task;
|
2022-04-09 00:20:23 +00:00
|
|
|
audioMgr->audioTask.msgQueue = &audioMgr->taskQueue;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->audioTask.msg = NULL;
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&audioMgr->sched->cmdQueue, (OSMesg)&audioMgr->audioTask, OS_MESG_BLOCK);
|
2022-06-03 19:43:30 +00:00
|
|
|
Sched_Notify(audioMgr->sched);
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-05-11 00:04:41 +00:00
|
|
|
D_8016A550 = osGetTime();
|
|
|
|
if (SREG(20) >= 2) {
|
2021-07-27 23:44:58 +00:00
|
|
|
rspTask = NULL;
|
2020-05-11 00:04:41 +00:00
|
|
|
} else {
|
2021-07-27 23:44:58 +00:00
|
|
|
rspTask = func_800E4FE0();
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
|
|
|
D_8016A558 += osGetTime() - D_8016A550;
|
|
|
|
D_8016A550 = 0;
|
2021-07-27 23:44:58 +00:00
|
|
|
if (audioMgr->rspTask != NULL) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&audioMgr->taskQueue, NULL, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
func_800C3C80(audioMgr);
|
|
|
|
}
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->rspTask = rspTask;
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void AudioMgr_HandlePreNMI(AudioMgr* audioMgr) {
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Audio manager received OS_SC_PRE_NMI_MSG"
|
2020-05-11 00:04:41 +00:00
|
|
|
osSyncPrintf("オーディオマネージャが OS_SC_PRE_NMI_MSG を受け取りました\n");
|
2021-07-27 23:44:58 +00:00
|
|
|
Audio_PreNMI();
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioMgr_ThreadEntry(void* arg0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
AudioMgr* audioMgr = (AudioMgr*)arg0;
|
2020-05-11 00:04:41 +00:00
|
|
|
IrqMgrClient irqClient;
|
2021-02-14 00:49:40 +00:00
|
|
|
s16* msg = NULL;
|
2020-05-11 00:04:41 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("オーディオマネージャスレッド実行開始\n"); // "Start running audio manager thread"
|
2021-11-07 16:58:50 +00:00
|
|
|
Audio_Init();
|
|
|
|
AudioLoad_SetDmaHandler(DmaMgr_DmaHandler);
|
|
|
|
Audio_InitSound();
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&audioMgr->lockQueue, NULL, OS_MESG_BLOCK);
|
|
|
|
IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->interruptQueue);
|
2020-05-11 00:04:41 +00:00
|
|
|
|
|
|
|
while (true) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&audioMgr->interruptQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
switch (*msg) {
|
|
|
|
case OS_SC_RETRACE_MSG:
|
|
|
|
AudioMgr_HandleRetrace(audioMgr);
|
2022-04-09 00:20:23 +00:00
|
|
|
while (!MQ_IS_EMPTY(&audioMgr->interruptQueue)) {
|
|
|
|
osRecvMesg(&audioMgr->interruptQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
switch (*msg) {
|
|
|
|
case OS_SC_RETRACE_MSG:
|
|
|
|
break;
|
|
|
|
case OS_SC_PRE_NMI_MSG:
|
2022-06-03 19:43:30 +00:00
|
|
|
AudioMgr_HandlePreNMI(audioMgr);
|
2020-05-11 00:04:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OS_SC_PRE_NMI_MSG:
|
2022-06-03 19:43:30 +00:00
|
|
|
AudioMgr_HandlePreNMI(audioMgr);
|
2020-05-11 00:04:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioMgr_Unlock(AudioMgr* audioMgr) {
|
2022-04-09 00:20:23 +00:00
|
|
|
osRecvMesg(&audioMgr->lockQueue, NULL, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 19:43:30 +00:00
|
|
|
void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, Scheduler* sched, IrqMgr* irqMgr) {
|
2020-05-11 00:04:41 +00:00
|
|
|
bzero(audioMgr, sizeof(AudioMgr));
|
|
|
|
|
|
|
|
audioMgr->sched = sched;
|
|
|
|
audioMgr->irqMgr = irqMgr;
|
2021-07-27 23:44:58 +00:00
|
|
|
audioMgr->rspTask = NULL;
|
2020-05-11 00:04:41 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateMesgQueue(&audioMgr->taskQueue, audioMgr->taskMsgBuf, ARRAY_COUNT(audioMgr->taskMsgBuf));
|
|
|
|
osCreateMesgQueue(&audioMgr->interruptQueue, audioMgr->interruptMsgBuf, ARRAY_COUNT(audioMgr->interruptMsgBuf));
|
|
|
|
osCreateMesgQueue(&audioMgr->lockQueue, audioMgr->lockMsgBuf, ARRAY_COUNT(audioMgr->lockMsgBuf));
|
2020-05-11 00:04:41 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osSendMesg(&audioMgr->taskQueue, NULL, OS_MESG_BLOCK);
|
2020-05-11 00:04:41 +00:00
|
|
|
|
2022-04-09 00:20:23 +00:00
|
|
|
osCreateThread(&audioMgr->thread, id, AudioMgr_ThreadEntry, audioMgr, stack, pri);
|
|
|
|
osStartThread(&audioMgr->thread);
|
2020-05-11 00:04:41 +00:00
|
|
|
}
|