| // Copyright 2022 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| //! Unsafe synchronous dump-string-to-uart impl and macro for debugging. |
| |
| use core::fmt; |
| use core2::io::{Cursor, Write}; |
| |
| // Convenience wrapper since capsules can't use unsafe{} |
| pub fn send_sync(buf: &[u8], len: usize) { |
| unsafe { |
| crate::uart_hal::UART0.transmit_sync(&buf[..len]); |
| } |
| } |
| |
| 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(); |
| send_sync(&uart_buf, pos as usize); |
| } |
| } |
| |
| #[macro_export] |
| macro_rules! dprintf { |
| ($msg:expr) => ({ |
| $crate::dprintf_hal::vdprintf(format_args!($msg)) |
| }); |
| ($fmt:expr, $($arg:tt)+) => ({ |
| $crate::dprintf_hal::vdprintf(format_args!($fmt, $($arg)+)) |
| }); |
| } |