Skip to content

Commit

Permalink
std: xous: use constants for stdout and stderr
Browse files Browse the repository at this point in the history
Use constants for the opcodes when writing to stdout or stderr.

There still is no stdin operation.

Signed-off-by: Sean Cross <sean@xobs.io>
  • Loading branch information
xobs committed Jan 13, 2024
1 parent aa73860 commit 99b0659
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions library/std/src/os/xous/services/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ impl<'a> Into<[usize; 5]> for LogScalar<'a> {
}
}

pub(crate) enum LogLend {
StandardOutput = 1,
StandardError = 2,
}

impl Into<usize> for LogLend {
fn into(self) -> usize {
self as usize
}
}

/// Return a `Connection` to the log server, which is used for printing messages to
/// the console and reporting panics. If the log server has not yet started, this
/// will block until the server is running. It is safe to call this multiple times,
Expand Down
8 changes: 5 additions & 3 deletions library/std/src/sys/pal/xous/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Stdout {}
pub struct Stderr;

use crate::os::xous::ffi::{lend, try_lend, try_scalar, Connection};
use crate::os::xous::services::{log_server, try_connect, LogScalar};
use crate::os::xous::services::{log_server, try_connect, LogLend, LogScalar};

impl Stdin {
pub const fn new() -> Stdin {
Expand Down Expand Up @@ -35,7 +35,8 @@ impl io::Write for Stdout {
for (dest, src) in lend_buffer.0.iter_mut().zip(chunk) {
*dest = *src;
}
lend(connection, 1, &lend_buffer.0, 0, chunk.len()).unwrap();
lend(connection, LogLend::StandardOutput.into(), &lend_buffer.0, 0, chunk.len())
.unwrap();
}
Ok(buf.len())
}
Expand All @@ -61,7 +62,8 @@ impl io::Write for Stderr {
for (dest, src) in lend_buffer.0.iter_mut().zip(chunk) {
*dest = *src;
}
lend(connection, 1, &lend_buffer.0, 0, chunk.len()).unwrap();
lend(connection, LogLend::StandardError.into(), &lend_buffer.0, 0, chunk.len())
.unwrap();
}
Ok(buf.len())
}
Expand Down

0 comments on commit 99b0659

Please sign in to comment.