WiFi tweaks

* batch all wifi in to one write

* writeCrcPacket already chunks the response, so we don't really need it, but limit maximum TCP write size

* format cleanup

* don't cache wifi stuff (for now)

* h7 fiddling
This commit is contained in:
Matthew Kennedy 2024-03-12 16:14:04 -07:00 committed by rusefillc
parent f9e0dddc4c
commit ee4b0af655
3 changed files with 50 additions and 14 deletions

View File

@ -75,7 +75,6 @@ void TsChannelBase::writeCrcPacketLarge(const uint8_t responseCode, const uint8_
crc = crc32inc((void*)buf, crc, size);
*(uint32_t*)crcBuffer = SWAP_UINT32(crc);
// If data, write that
if (size) {
write(buf, size, /*isEndOfPacket*/false);

View File

@ -29,7 +29,7 @@ static input_queue_t wifiIqueue;
static bool socketReady = false;
class WifiChannel : public TsChannelBase {
class WifiChannel final : public TsChannelBase {
public:
WifiChannel()
: TsChannelBase("WiFi")
@ -37,17 +37,27 @@ public:
}
bool isReady() const override {
return true;
return socketReady;
}
void write(const uint8_t* buffer, size_t size, bool /*isEndOfPacket*/) override {
sendBuffer = buffer;
sendSize = size;
void write(const uint8_t* buffer, size_t size, bool /*isEndOfPacket*/) final override {
while (size > 0) {
// Write at most SOCKET_BUFFER_MAX_LENGTH bytes at a time
size_t chunkSize = size > SOCKET_BUFFER_MAX_LENGTH ? SOCKET_BUFFER_MAX_LENGTH : size;
sendRequest = true;
isrSemaphore.signal();
// Write this chunk
sendBuffer = buffer;
sendSize = chunkSize;
sendRequest = true;
isrSemaphore.signal();
sendDoneSemaphore.wait();
// Step buffer/size for the next chunk
buffer += chunkSize;
size -= chunkSize;
// Wait for this chunk to complete
sendDoneSemaphore.wait();
}
}
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override {
@ -55,7 +65,7 @@ public:
}
};
static WifiChannel wifiChannel;
static NO_CACHE WifiChannel wifiChannel;
class WifiHelperThread : public ThreadController<4096> {
public:
@ -75,7 +85,7 @@ public:
}
};
static WifiHelperThread wifiHelper;
static NO_CACHE WifiHelperThread wifiHelper;
static tstrWifiInitParam param;
@ -94,7 +104,7 @@ void wifiCallback(uint8 u8MsgType, void* pvMsg) {
}
}
uint8_t rxBuf[512];
static NO_CACHE uint8_t rxBuf[512];
static void socketCallback(SOCKET sock, uint8_t u8Msg, void* pvMsg) {
switch (u8Msg) {
@ -150,7 +160,13 @@ static void socketCallback(SOCKET sock, uint8_t u8Msg, void* pvMsg) {
recv(sock, &rxBuf, nextRecv, 0);
} else {
close(sock);
socketReady = false;
{
chibios_rt::CriticalSectionLocker csl;
iqResetI(&wifiIqueue);
}
}
} break;
case SOCKET_MSG_SEND: {
@ -207,7 +223,7 @@ struct WifiConsoleThread : public TunerstudioThread {
}
};
static WifiConsoleThread wifiThread;
static NO_CACHE WifiConsoleThread wifiThread;
void startWifiConsole() {
iqObjectInit(&wifiIqueue, recvBuffer, sizeof(recvBuffer), nullptr, nullptr);

View File

@ -58,7 +58,7 @@ SPIConfig wifi_spicfg = {
.ssport = NULL,
.sspad = 0,
.cfg1 = 7 // 8 bits per byte
| 0 /* MBR = 0, divider = 2 */,
| 2 << 28 /* MBR = 2, divider = 8 */,
.cfg2 = 0
};
@ -122,6 +122,8 @@ sint8 nm_bus_speed(uint8 /*level*/) {
return M2M_SUCCESS;
}
extern "C" void resetSpiDevice(SPIDriver* spi);
sint8 nm_spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz) {
spiSelectI(wifiSpi);
@ -136,6 +138,19 @@ sint8 nm_spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz) {
}
}
} else {
// #if CORTEX_MODEL == 7
// if (pu8Mosi) {
// SCB_CleanDCache_by_Addr((uint32_t*)pu8Mosi, u16Sz);
// }
// #endif
// #ifdef STM32H7XX
// /* workaround for silicon errata */
// /* see https://github.com/rusefi/rusefi/issues/2395 */
// resetSpiDevice(wifiSpi);
// spiStart(wifiSpi, &wifi_spicfg);
// #endif
if (pu8Mosi && pu8Miso) {
spiExchange(wifiSpi, u16Sz, pu8Mosi, pu8Miso);
} else if (pu8Mosi) {
@ -146,6 +161,12 @@ sint8 nm_spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz) {
// Neither MISO nor MOSI???
osalSysHalt("wifi neither mosi nor miso");
}
// #if CORTEX_MODEL == 7
// if (pu8Miso) {
// SCB_InvalidateDCache_by_Addr((uint32_t*)pu8Miso, u16Sz);
// }
// #endif
}
spiUnselectI(wifiSpi);