Skip to content

Windows race condition fix#431

Draft
freshLobster wants to merge 25 commits intoespotek-org:masterfrom
freshLobster:lobster-pr-clean-winfix
Draft

Windows race condition fix#431
freshLobster wants to merge 25 commits intoespotek-org:masterfrom
freshLobster:lobster-pr-clean-winfix

Conversation

@freshLobster
Copy link
Copy Markdown
Contributor

@freshLobster freshLobster commented Mar 11, 2026

this is the same patch I did for issue #333, but applied to the windows specific code. It builds, it runs fine, tests fine, logs look good save for:
Frame phase error of 3
in the logs which just tells me that there's some minor isochronous endpoint frame alignment that needs to be adjusted.
That should have it's own separate issue and PR though. this is for #333 and #382

Edit: fixed the alignment/ordering

When reinitializing USB on Windows, MainWindow now triggers a driver shutdown if the driver is connected and waits for a shutdownComplete signal before running reinitUsbStage2. The winUsbDriver gained a shutdownProcedure that stops timers, aborts and flushes pipes, waits (with a 3000ms timeout) for overlapped ISO transfers to complete, sets connection state, and emits shutdownComplete. Guards were added to isoTimerTick and resubmission paths to avoid scheduling work during shutdown. Header changes add shutdown flags, a transferPending array, a shutdownElapsed timer and the shutdownComplete signal. Also includes minor qDebug formatting fixes and an explanatory comment about MAX_OVERLAP in the destructor.
Make pipeID handling platform-aware and tidy winusb behavior. In the USB generic driver, the pipeID array is now conditionally sized (NUM_ISO_ENDPOINTS on Windows, legacy 3 otherwise) and debug output on Windows casts pipeID to int to avoid char printing issues (genericusbdriver.h/.cpp). In the winusb driver, the overlapping-handle release loop now uses NUM_FUTURE_CTX instead of MAX_OVERLAP to avoid a potential out-of-bounds assumption, and the killMe() call was removed from isoTimerTick under non-WINDOWS_32_BIT to prevent an immediate termination on frame phase errors.
Add Desktop_Interface/run_test_win, Desktop_Interface/build_test_win_custom, and Desktop_Interface/tools to .gitignore so generated test/build artifacts are not tracked. Keeps the existing Desktop_Interface/_install entry and adds a trailing newline to the file.
Labels for nets PDI_CLK and PDI_DATA swapped to match ATxmega32A4U pinout. saved as Kicad 9.0 files
@mi-hol
Copy link
Copy Markdown
Contributor

mi-hol commented Mar 12, 2026

I did a basic test with Multimeter (mode 5) on Windows 11 and it works.

@turboencabulator would you perhaps have the time for a code review?

@EspoTek
Copy link
Copy Markdown
Collaborator

EspoTek commented Mar 13, 2026

"Frame phase error of 3" means that the data might be copying across into the buffer in the wrong order.

Can you see any discontinuities when feeding back a "weird" waveform like a 792Hz sine wave into the scope CH1?

@freshLobster
Copy link
Copy Markdown
Contributor Author

"Frame phase error of 3" means that the data might be copying across into the buffer in the wrong order.

Can you see any discontinuities when feeding back a "weird" waveform like a 792Hz sine wave into the scope CH1?

I haven't tested that yet. I can put this PR as a draft and open it again when the frame phase error is corrected?

Otherwise I can test it when I have time or someone else can feel free to check it out.

@mi-hol mi-hol marked this pull request as draft March 13, 2026 13:13
@mi-hol
Copy link
Copy Markdown
Contributor

mi-hol commented Mar 13, 2026

put this PR as a draft

just set it to DRAFT status

Copy link
Copy Markdown
Contributor

@turboencabulator turboencabulator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only got a few minor suggestions. This isn't a very thorough review, I'm not familiar with the Windows stuff and I don't have easy access to a Windows machine.

Improve the Windows USB reconnect path by making shutdown drain outstanding overlapped transfers before driver teardown and by withholding misaligned isochronous buffers until frames resynchronize after hotplug events. Also keep pipe ID debug output numeric across platforms for clearer diagnostics.
removed my comments on formatting. reordered winusbdriver members for the $$$cache$$$
@freshLobster freshLobster marked this pull request as ready for review March 25, 2026 21:52
…freshLobster/Labrador into lobster-pr-clean-winfix"

This reverts commit 7b25a52, reversing
changes made to 71fbe9a.
@freshLobster freshLobster marked this pull request as draft March 27, 2026 16:54
hoping to god this works or I just wasted like 8 hours of my life
This reverts commit 71fbe9a.
@freshLobster
Copy link
Copy Markdown
Contributor Author

I could use some help on fixing this. I dont know what happened, but my local build got all messed up and I cant get it back to the state where it worked properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants