uart/trap/main: remove global read_uart fn
authorKit Rhett Aultman <kit@kitaultman.com>
Sun, 29 Sep 2024 18:58:30 +0000 (14:58 -0400)
committerKit Rhett Aultman <kit@kitaultman.com>
Sun, 29 Sep 2024 18:58:30 +0000 (14:58 -0400)
commitb433dfa308a5a3a8e2b5024203e9179396db4119
tree5190f7c295d4ca580dad7780110fc4f8a57e8fa8
parent11f8f0afcb5b4efd578d0bfcc80788b2a8204670
uart/trap/main: remove global read_uart fn

The previous implementation of the UART interrupt handler relied on a
public global function, read_uart, in order to get data waiting in the
UART's registers.  This is an artifact of the Uart code which focuses on
having a single global Uart, largely so the println!() macros can work
with it.

It seems a bit awkward going forward having all possible read/write
points of the UART going through global functions; indeed, future code
would like to work simply by writing bytes or strings into interfaces
and not worrying about where it goes, so as a stepping stone on that
way, this commit refactors out the global read_uart( ) function and
replaces it with a scheme where the interrupt handler has its own
interface to the UART.

Having multiple Uart objects is fine for now but really only because we
know we're single-threading.  More ideal would be, in the future, for
each Uart to be a reference to a single Uart struct, since the Uart's
underlying implementation already has some amount of concurrency
control.  At the end of the day, there's one single UART on the system,
and we really want to create a situation where code writes into, say, a
Console interface instead of the Uart, and there's a "console manager"
deciding what's going to the UART and what isn't.

Baby steps, though.
src/main.rs
src/trap.rs
src/uart.rs