add the RF wakeup thing

This commit is contained in:
Arisotura 2022-09-01 23:14:02 +02:00
parent f380a53404
commit ab084fcf08
3 changed files with 30 additions and 10 deletions

View File

@ -52,8 +52,6 @@ enum
Event_DSi_CamTransfer, Event_DSi_CamTransfer,
Event_DSi_DSP, Event_DSi_DSP,
Event_WifiLegacy,
Event_MAX Event_MAX
}; };

View File

@ -504,6 +504,11 @@ void CancelEvent(u32 id)
SchedListMask &= ~(1<<id); SchedListMask &= ~(1<<id);
} }
bool EventScheduled(u32 id)
{
return (SchedListMask & (1<<id)) != 0;
}
void PowerDown(); void PowerDown();
@ -1573,7 +1578,7 @@ void MSTimer(u32 param)
{ {
if (IOPORT(W_USCompareCnt)) if (IOPORT(W_USCompareCnt))
{ {
if (USCounter == USCompare) if ((USCounter & ~0x3FF) == USCompare)
{ {
BlockBeaconIRQ14 = false; BlockBeaconIRQ14 = false;
SetIRQ14(0); SetIRQ14(0);
@ -1601,6 +1606,18 @@ void MSTimer(u32 param)
ScheduleEvent(Event_MSTimer, true, 1024, MSTimer, 0); ScheduleEvent(Event_MSTimer, true, 1024, MSTimer, 0);
} }
void RFWakeup(u32 param)
{
bool switchOffPowerSaving = ((IOPORT(W_PowerUnk) & 0x0001) || ForcePowerOn);
if ((IOPORT(W_PowerState) & 0x0002) || switchOffPowerSaving)
{
IOPORT(W_PowerState) = 0;
IOPORT(W_RFPins) = 1;
IOPORT(W_RFPins) = 0x0084;
SetIRQ(11);
}
}
void USTimer(u32 param) void USTimer(u32 param)
{ {
/*USTimestamp++; /*USTimestamp++;
@ -1832,7 +1849,7 @@ void USTimer(u32 param)
// measurement: 16715us per frame // measurement: 16715us per frame
// calculation: 16715.113113088143330744761992174us per frame // calculation: 16715.113113088143330744761992174us per frame
//NDS::ScheduleEvent(NDS::Event_Wifi, true, 33, USTimer, 0); //NDS::ScheduleEvent(NDS::Event_Wifi, true, 33, USTimer, 0);
NDS::ScheduleEvent(NDS::Event_WifiLegacy, true, 34, USTimer, 0); //NDS::ScheduleEvent(NDS::Event_WifiLegacy, true, 34, USTimer, 0);
} }
@ -2001,7 +2018,8 @@ void Write(u32 addr, u16 val)
if (!(oldval & 0x0001) && (val & 0x0001)) if (!(oldval & 0x0001) && (val & 0x0001))
{ {
if (!(USUntilPowerOn < 0 && ForcePowerOn)) //if (!(USUntilPowerOn < 0 && ForcePowerOn))
if (!(EventScheduled(Event_RFWakeup) && ForcePowerOn))
{ {
//printf("mode reset power on %08x\n", NDS::ARM7->R[15]); //printf("mode reset power on %08x\n", NDS::ARM7->R[15]);
IOPORT(0x034) = 0x0002; IOPORT(0x034) = 0x0002;
@ -2010,7 +2028,8 @@ void Write(u32 addr, u16 val)
if (IOPORT(W_PowerUnk) & 0x0002) if (IOPORT(W_PowerUnk) & 0x0002)
{ {
USUntilPowerOn = -2048; //USUntilPowerOn = -2048;
ScheduleEvent(Event_RFWakeup, false, 2048, RFWakeup, 0);
IOPORT(W_PowerState) |= 0x100; IOPORT(W_PowerState) |= 0x100;
} }
} }
@ -2103,7 +2122,8 @@ void Write(u32 addr, u16 val)
{ {
//printf("power on\n"); //printf("power on\n");
IOPORT(W_PowerState) |= 0x100; IOPORT(W_PowerState) |= 0x100;
USUntilPowerOn = -2048; //USUntilPowerOn = -2048;
ScheduleEvent(Event_RFWakeup, false, 2048, RFWakeup, 0);
ForcePowerOn = false; ForcePowerOn = false;
} }
} }
@ -2125,14 +2145,16 @@ void Write(u32 addr, u16 val)
{ {
//printf("power on\n"); //printf("power on\n");
IOPORT(W_PowerState) |= 0x100; IOPORT(W_PowerState) |= 0x100;
USUntilPowerOn = -2048; //USUntilPowerOn = -2048;
ScheduleEvent(Event_RFWakeup, false, 2048, RFWakeup, 0);
ForcePowerOn = false; ForcePowerOn = false;
} }
if (val == 0x8000) if (val == 0x8000)
{ {
//printf("force power on\n"); //printf("force power on\n");
IOPORT(W_PowerState) |= 0x100; IOPORT(W_PowerState) |= 0x100;
USUntilPowerOn = -2048; //USUntilPowerOn = -2048;
ScheduleEvent(Event_RFWakeup, false, 2048, RFWakeup, 0);
ForcePowerOn = true; ForcePowerOn = true;
} }
break; break;

View File

@ -156,7 +156,7 @@ enum
Event_RXCheck = 0, Event_RXCheck = 0,
Event_IRQ15, Event_IRQ15,
Event_MSTimer, Event_MSTimer,
Event_PowerOn, Event_RFWakeup,
Event_MPClientSync, Event_MPClientSync,
Event_TRX, Event_TRX,
Event_RF, Event_RF,