Struct lc3_ensemble::sim::io::BiChannelIO
source · pub struct BiChannelIO { /* private fields */ }Expand description
An IO that reads from one channel and writes to another.
This binds the reader channel to the KBSR and KBDR. When a character is ready from the reader channel, the KBSR status is enabled and the character is accessible from the KBDR.
This binds the writer channel to the DSR and DDR. When a character is ready to be written to the writer channel, the DSR status is enabled and the character can be written to the DDR.
This IO type also exposes the MCR in the MCR MMIO address.
Implementations§
source§impl BiChannelIO
impl BiChannelIO
sourcepub fn new(
reader: impl FnMut() -> Result<u8, Stop> + Send + 'static,
writer: impl FnMut(u8) -> Result<(), Stop> + Send + 'static,
mcr: Arc<AtomicBool>
) -> Self
pub fn new( reader: impl FnMut() -> Result<u8, Stop> + Send + 'static, writer: impl FnMut(u8) -> Result<(), Stop> + Send + 'static, mcr: Arc<AtomicBool> ) -> Self
Creates a new bi-channel IO device with the given reader and writer.
This calls the reader function every time the IO input receives a byte. The reader function should block until a byte is ready, or return Stop if there are no more bytes to read.
This calls the writer function every time a byte needs to be written to the IO output.
This uses threads to read and write from input and output. As such, the channels will continue to poll input and output even when the simulator is not running. As such, care should be taken to not send messages through the reader thread while the simulator is not running.
sourcepub fn stdio(mcr: Arc<AtomicBool>) -> Self
pub fn stdio(mcr: Arc<AtomicBool>) -> Self
Creates a bi-channel IO device with stdin being the read data and stdout being the write data.
Note that due to how stdin works in terminals, data is only sent once a new line is typed. Additionally, this flushes stdout every time a byte is written.