Skip to content

Commit b70296c

Browse files
committed
uefi: improve clarity over timeout in SerialIoMode
1 parent 1ccc595 commit b70296c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

uefi-raw/src/protocol/console/serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ bitflags! {
6262
pub struct SerialIoMode {
6363
/// Bitmask of the control bits that this device supports.
6464
pub control_mask: ControlBits,
65-
/// If applicable, the number of microseconds to wait before assuming an
65+
/// The number of microseconds (µs) to wait before assuming an read or write
6666
/// operation timed out.
67-
pub timeout: u32,
67+
pub timeout_us: u32,
6868
/// Device's baud rate, or 0 if unknown.
6969
pub baud_rate: u64,
7070
/// Size in character's of the device's buffer.

uefi-test-runner/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern crate alloc;
1010

1111
use alloc::string::ToString;
1212
use alloc::vec::Vec;
13+
use core::time::Duration;
1314
use uefi::mem::memory_map::MemoryMap;
1415
use uefi::prelude::*;
1516
use uefi::proto::console::serial::Serial;
@@ -111,7 +112,7 @@ fn send_request_helper(serial: &mut Serial, request: HostRequest) -> Result {
111112

112113
// Set a 10 second timeout for the read and write operations.
113114
let mut io_mode = *serial.io_mode();
114-
io_mode.timeout = 10_000_000;
115+
io_mode.timeout_us = Duration::from_secs(10).as_micros() as u32;
115116
serial.set_attributes(&io_mode)?;
116117

117118
// Send a screenshot request to the host.

uefi/src/proto/console/serial.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Serial {
5959
&mut self.0,
6060
mode.baud_rate,
6161
mode.receive_fifo_depth,
62-
mode.timeout,
62+
mode.timeout_us,
6363
mode.parity,
6464
mode.data_bits as u8,
6565
mode.stop_bits,
@@ -90,7 +90,9 @@ impl Serial {
9090
/// so far.
9191
///
9292
/// To prevent missing data (overrun), it is recommended to call this
93-
/// function multiple times.
93+
/// function multiple times. To prevent long blocking times, i.e., to only
94+
/// read what is available as of calling this function, it is recommended to
95+
/// set the timeout in [`IoMode`] to 1 µs.
9496
pub fn read(&mut self, data: &mut [u8]) -> Result<usize /* read bytes*/> {
9597
let mut buffer_size = data.len();
9698
let status = unsafe { (self.0.read)(&mut self.0, &mut buffer_size, data.as_mut_ptr()) };

0 commit comments

Comments
 (0)