angry-goose-initiative / wiki

AGI Wiki
0 stars 0 forks source link

UART Race Condition #46

Closed JZJisawesome closed 4 months ago

JZJisawesome commented 4 months ago

Sometimes, but not always, running uart_read_test has funky results.

I only observe this sometimes, and only on debug (not on release) builds. This smells like some sort of timing issue with the read thread in the UART, or with tsqueue.h:

Image

JZJisawesome commented 4 months ago

I think this issue just came about because the initial value of the LSR register was randomized, so we sometimes thought data was available when in reality it wasn't. It also means the LCR was randomized and thus sometimes DLAB was set, replacing the LSR with the PSD and messing things up.

This lines up with the behaviour since it only happened with debug builds and only some of the time (for some seeds).

Implementing the LSR register with more accuracy appears to have resolved the issue on my personal/jzj/uartlinux branch.