diff options
author | 2020-08-31 23:16:21 +0200 | |
---|---|---|
committer | 2020-10-13 21:30:44 +0200 | |
commit | 10b29d3a4fc43503c25fb2c7ffbeaad44c2fb103 (patch) | |
tree | ceb6fc008cfbcc430a4254464d0e3341c34796e1 /cortex-m-semihosting/src/export.rs | |
parent | f77d64a2d1505335e4a170d03a40993bb066fd02 (diff) | |
download | cortex-m-10b29d3a4fc43503c25fb2c7ffbeaad44c2fb103.tar.gz cortex-m-10b29d3a4fc43503c25fb2c7ffbeaad44c2fb103.tar.zst cortex-m-10b29d3a4fc43503c25fb2c7ffbeaad44c2fb103.zip |
Import semihosting crates as-is
Diffstat (limited to 'cortex-m-semihosting/src/export.rs')
-rw-r--r-- | cortex-m-semihosting/src/export.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cortex-m-semihosting/src/export.rs b/cortex-m-semihosting/src/export.rs new file mode 100644 index 0000000..c188ab0 --- /dev/null +++ b/cortex-m-semihosting/src/export.rs @@ -0,0 +1,51 @@ +//! IMPLEMENTATION DETAILS USED BY MACROS + +use core::fmt::{self, Write}; + +use cortex_m::interrupt; + +use crate::hio::{self, HStderr, HStdout}; + +static mut HSTDOUT: Option<HStdout> = None; + +pub fn hstdout_str(s: &str) { + let _result = interrupt::free(|_| unsafe { + if HSTDOUT.is_none() { + HSTDOUT = Some(hio::hstdout()?); + } + + HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop) + }); +} + +pub fn hstdout_fmt(args: fmt::Arguments) { + let _result = interrupt::free(|_| unsafe { + if HSTDOUT.is_none() { + HSTDOUT = Some(hio::hstdout()?); + } + + HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop) + }); +} + +static mut HSTDERR: Option<HStderr> = None; + +pub fn hstderr_str(s: &str) { + let _result = interrupt::free(|_| unsafe { + if HSTDERR.is_none() { + HSTDERR = Some(hio::hstderr()?); + } + + HSTDERR.as_mut().unwrap().write_str(s).map_err(drop) + }); +} + +pub fn hstderr_fmt(args: fmt::Arguments) { + let _result = interrupt::free(|_| unsafe { + if HSTDERR.is_none() { + HSTDERR = Some(hio::hstderr()?); + } + + HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop) + }); +} |