From e15f638fef11029b8c2362e941ef2deeacff0cbf Mon Sep 17 00:00:00 2001 From: Rodrigo Alfonso Date: Sat, 11 Feb 2023 06:31:48 -0300 Subject: [PATCH] Optimization: Trying to minimize time on ISRs --- README.md | 2 +- lib/LinkWireless.h | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 683b91b..72e30e5 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Name | Type | Default | Description `maxPlayers` | **u8** *(2~5)* | `5` | Maximum number of allowed players. The adapter will accept connections after reaching the limit, but the library will ignore them. If your game only supports -for example- two players, set this to `2` as it will make transfers faster. `timeout` | **u32** | `5` | Number of *frames* without receiving *any* data to reset the connection. `remoteTimeout` | **u32** | `10` | Number of *successful transfers* without a message from a client to mark the player as disconnected. -`interval` | **u16** | `50` | Number of *1024cycles* (61.04μs) ticks between transfers *(50 = 3,052ms)*. It's the interval of Timer #`sendTimerId`. +`interval` | **u16** | `50` | Number of *1024cycles* (61.04μs) ticks between transfers *(50 = 3.052ms)*. It's the interval of Timer #`sendTimerId`. `sendTimerId` | **u8** *(0~3)* | `3` | GBA Timer to use for sending. You can also change the compile-time constant `LINK_WIRELESS_QUEUE_SIZE` to set a custom buffer size (how many incoming and outcoming messages the queues can store at max). The default value is `30`, which seems fine for most games. diff --git a/lib/LinkWireless.h b/lib/LinkWireless.h index 104983e..f9a672e 100644 --- a/lib/LinkWireless.h +++ b/lib/LinkWireless.h @@ -484,22 +484,20 @@ class LinkWireless { return; linkSPI->_onSerial(true); - copyOutgoingState(); bool hasNewData = linkSPI->getAsyncState() == LinkSPI::AsyncState::READY; - if (hasNewData) + if (hasNewData) { if (!acknowledge()) { reset(); lastError = ACKNOWLEDGE_FAILED; - copyState(); return; } + } else + return; u32 newData = linkSPI->getAsyncData(); - if (!isSessionActive()) { - copyState(); + if (!isSessionActive()) return; - } if (asyncCommand.isActive) { if (asyncCommand.state == AsyncCommand::State::PENDING) { @@ -512,30 +510,23 @@ class LinkWireless { processAsyncCommand(); } } - - copyState(); } void _onTimer() { if (!isEnabled) return; - if (!isSessionActive()) { - copyState(); + if (!isSessionActive()) return; - } if (sessionState.recvTimeout >= config.timeout) { reset(); lastError = TIMEOUT; - copyState(); return; } if (!asyncCommand.isActive) acceptConnectionsOrSendData(); - - copyState(); } private: