Skip to content

Commit 3833511

Browse files
committed
Semaphore: Aesthetic fixes.
1 parent 090aa87 commit 3833511

5 files changed

Lines changed: 5 additions & 19 deletions

File tree

right/src/event_scheduler.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "peripherals/merge_sensor.h"
1212
#include "power_mode.h"
1313
#include "usb_report_updater.h"
14-
#include "usb_semaphore.h"
1514
#include "oneshot.h"
1615
#include "trace.h"
1716

@@ -253,11 +252,6 @@ static void processEvt(event_scheduler_event_t evt)
253252
case EventSchedulerEvent_SendUsbReports:
254253
EventVector_Set(EventVector_SendUsbReports);
255254
break;
256-
case EventSchedulerEvent_UpdateUsbSemaphore:
257-
// Drives the semaphore timeout so a stuck (unconfirmed) report gets resent
258-
// even if nothing else wakes the event loop.
259-
UsbSemaphore_RecalculateIsReady();
260-
break;
261255
case EventSchedulerEvent_CheckLeftBleVsUart:
262256
#if DEVICE_IS_UHK80_LEFT
263257
BtManager_CheckLeftBleVsUart();

right/src/event_scheduler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
EventSchedulerEvent_OneShotTimeout,
5151
EventSchedulerEvent_KickHid,
5252
EventSchedulerEvent_SendUsbReports,
53-
EventSchedulerEvent_UpdateUsbSemaphore,
5453
EventSchedulerEvent_CheckLeftBleVsUart,
5554
EventSchedulerEvent_ConnectionsUpdateState,
5655
EventSchedulerEvent_Count

right/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ int main(void)
235235
sendFirstReport();
236236

237237
Trace_Printc("initialized");
238+
LOG_INF("Booted up");
238239

239240
while (1) {
240241
Trace_Printc("{");

right/src/usb_report_sender.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ static bool blockedByReportThrottle() {
251251

252252
// If we are retrying too agressively, we may clog some USB hubs, so add a throttle in that case as well.
253253
if (currentTime < retryThrottleTime) {
254-
blockedUntil = MAX(retryThrottleTime, blockedUntil);;
254+
blockedUntil = MAX(retryThrottleTime, blockedUntil);
255255
blocked = true;
256256
}
257257

258258
// To reduce mouse latency, don't construct report until we are close enough to transport window.
259259
if ((int32_t)(UsbReportWindowEstimate - currentTime) > USB_REPORT_WINDOW_LOOKAHEAD_MS) {
260260
uint32_t throttleUntil = UsbReportWindowEstimate - USB_REPORT_WINDOW_LOOKAHEAD_MS;
261-
blockedUntil = MAX(throttleUntil, blockedUntil);;
261+
blockedUntil = MAX(throttleUntil, blockedUntil);
262262
blocked = true;
263263
}
264264

@@ -281,7 +281,7 @@ static bool blockedByReportThrottle() {
281281
return false;
282282
}
283283

284-
// All paths have to call either UsbReportUpdater_UpdateActiveReports or justPreprocessInput.
284+
// All paths have to call either UsbReportUpdater_UpdateActiveReports or justPreprocessInput(true).
285285
void UsbReportSender_UpdateAndSendUsbReports(void)
286286
{
287287
Trace_Printc("u1");

right/src/usb_semaphore.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ void UsbSemaphore_Clear(void) {
4343
UsbSemaphore.mouse.inFlight = false;
4444
}
4545

46-
// Release a report's in-flight latch once it has been successfully sent (USB/BLE via the
47-
// async sent callback, NUS/dongle synchronously on successful enqueue). This unblocks report
48-
// processing: advance the baseline to the just-sent report and reset the resend state
49-
// (ShouldResendReport(0, ...) clears the retry counter and the give-up latch). This means
50-
// "sent", not "delivered" - for USB/BLE the delivery confirmation is a separate, later event.
5146
void UsbSemaphore_Release(report_send_state_t* st) {
5247
st->switchActiveReport();
5348
st->retries = 0;
@@ -56,10 +51,7 @@ void UsbSemaphore_Release(report_send_state_t* st) {
5651
EventScheduler_Schedule(Timer_GetCurrentTime(), EventSchedulerEvent_Postponer, "Usb semaphore released. Recalculate throttle delay.");
5752
}
5853

59-
// Recompute the in-flight gate. While a report is still in flight within its confirmation
60-
// grace window we are not ready (return false). Once the window elapses, re-arm the resend
61-
// for the still-pending reports (their baseline was never advanced, so the current state is
62-
// re-sent rather than lost) and report ready.
54+
// NOTE: if we retry too soon, we might get a double report confirmation, confirming this report and the next one, which would make us loose the next one if its transport failes. Low probability in practice.
6355
bool UsbSemaphore_RecalculateIsReady(void) {
6456
if (UsbSemaphore_AnyInFlight() && CurrentPowerMode <= PowerMode_LastAwake) {
6557
if (Timer_GetElapsedTime(&UpdateUsbReports_LastUpdateTime) < USB_SEMAPHORE_TIMEOUT) {

0 commit comments

Comments
 (0)