| //! App-side dprintf macro that calls through to the debug_uart capsule. |
| |
| use core2::io::{Cursor, Write}; |
| use core::fmt; |
| use libtock::syscalls; |
| use matcha_config::*; |
| |
| #[macro_export] |
| macro_rules! dprintf { |
| ($msg:expr) => ({ |
| $crate::dprintf::vdprintf(format_args!($msg)) |
| }); |
| ($fmt:expr, $($arg:tt)+) => ({ |
| $crate::dprintf::vdprintf(format_args!($fmt, $($arg)+)) |
| }); |
| } |
| |
| pub fn vdprintf(args: fmt::Arguments) { |
| let mut uart_buf = [0u8; 256]; |
| let mut cur = Cursor::new(&mut uart_buf[..]); |
| if cur.write_fmt(args).is_ok() { |
| let pos = cur.position(); |
| drop(cur); |
| let allow = syscalls::allow(CAPSULE_DPRINTF, 0, &mut uart_buf); |
| let _result = syscalls::command(CAPSULE_DPRINTF, CMD_DPRINTF_PRINT, pos as usize, 0); |
| drop(allow); |
| } |
| } |