aboutsummaryrefslogtreecommitdiff
path: root/src/Wifi.cpp
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2023-07-28 10:14:33 +0200
committerArisotura <thetotalworm@gmail.com>2023-07-28 10:14:33 +0200
commit8fd46e5f8ccc4fe152bef2059114f6373030d63c (patch)
tree05476534c2b25fcb7b1d6c71d621ca2833e75602 /src/Wifi.cpp
parent9c5cde810993b4f1a5595021b96327a184d12e17 (diff)
wifi: attempt two at optimizing the sync mechanism. this time it should be far less prone to problems.
Diffstat (limited to 'src/Wifi.cpp')
-rw-r--r--src/Wifi.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/Wifi.cpp b/src/Wifi.cpp
index 5173120..aa3cf1d 100644
--- a/src/Wifi.cpp
+++ b/src/Wifi.cpp
@@ -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);
}
@@ -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;
}
@@ -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));
@@ -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
{