Skip to content

Commit

Permalink
wifi: attempt two at optimizing the sync mechanism. this time it shou…
Browse files Browse the repository at this point in the history
…ld be far less prone to problems.
  • Loading branch information
Arisotura committed Jul 28, 2023
1 parent 9c5cde8 commit 8fd46e5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,22 @@ void SendMPAck(u16 cmdcount, u16 clientfail)
*(u16*)&ack[0xC + 0x1A] = clientfail;
*(u32*)&ack[0xC + 0x1C] = 0;

if (!clientfail)
{
u32 nextbeacon;
if (IOPORT(W_TXBusy) & 0x0010)
nextbeacon = 0;
else
nextbeacon = ((IOPORT(W_BeaconCount1) - 1) << 10) + (0x400 - (USCounter & 0x3FF));
int runahead = std::min(CmdCounter, nextbeacon);
if (CmdCounter < 1000) runahead -= 210;
*(u32*)&ack[0] = std::max(runahead - (32*(TXSlots[1].Rate==2?4:8)), 0);
}
else
{
*(u32*)&ack[0] = PreambleLen(TXSlots[1].Rate);
}

int txlen = Platform::MP_SendAck(ack, 12+32, USTimestamp);
WIFI_LOG("wifi: sent %d/44 bytes of MP ack, %d %d\n", txlen, ComStatus, RXTime);
}
Expand Down Expand Up @@ -1076,9 +1092,10 @@ bool ProcessTX(TXSlot* slot, int num)
SetIRQ(1);
}

if (MPClientFail)
if (MPClientFail && false)
{
// if some clients failed to respond: try again
// TODO: fix this (causes instability)
StartTX_Cmd();
break;
}
Expand Down Expand Up @@ -1580,6 +1597,7 @@ bool CheckRX(int type) // 0=regular 1=MP replies 2=MP host frames
// we also need to determine how far we can run after having received this frame

RXTimestamp = timestamp;
//if (RXTimestamp < USTimestamp) printf("CRAP!! %04X %016llX %016llX\n", framectl, RXTimestamp, USTimestamp);
if (RXTimestamp < USTimestamp) RXTimestamp = USTimestamp;
NextSync = RXTimestamp + (framelen * (txrate==0x14 ? 4:8));

Expand All @@ -1591,6 +1609,12 @@ bool CheckRX(int type) // 0=regular 1=MP replies 2=MP host frames
// include the MP reply time window
NextSync += 112 + ((clienttime + 10) * NumClients(clientmask));
}
else if (MACEqual(&RXBuffer[12 + 4], MPAckMAC))
{
u32 runahead = *(u32*)&RXBuffer[0];

NextSync += runahead;
}
}
else
{
Expand Down

0 comments on commit 8fd46e5

Please sign in to comment.