aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-08-08 14:41:00 -0400
committerBrian Cully <bjc@kublai.com>2022-08-08 14:41:00 -0400
commit299d06dad9c4bfc8eef70271204a4f9f7379e5ce (patch)
tree4e2a011eab1ebd9d5bb684b099fa4b40baefaa07 /src/log.rs
parente84a0d01a0c1633a2cd15bf4bab7eb934f374c68 (diff)
downloadluchie-299d06dad9c4bfc8eef70271204a4f9f7379e5ce.tar.gz
luchie-299d06dad9c4bfc8eef70271204a4f9f7379e5ce.zip
update log inteface, add (and use) ‘log!’ macro.
Diffstat (limited to 'src/log.rs')
-rw-r--r--src/log.rs34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/log.rs b/src/log.rs
index 07525cc..b6204d6 100644
--- a/src/log.rs
+++ b/src/log.rs
@@ -1,16 +1,36 @@
-use core::fmt::Write;
+use core::fmt::{write, Arguments};
use gd32vf103xx_hal::{
- pac::USART1,
serial::Tx,
+ pac::USART1,
};
+use riscv::interrupt::{self, Mutex};
+
+#[macro_export]
+macro_rules! log {
+ ($($args:tt)+) => {
+ $crate::log::log_args(core::format_args!($($args)+));
+ }
+}
+
+#[macro_export]
+macro_rules! logln {
+ () => ({ kprint!("\r\n") });
+ ($fmt: literal $(, $($arg: tt)+)?) => {
+ log!(concat!($fmt, "\n") $(, $($arg)+)?);
+ }
+}
-static mut TX: Option<Tx<USART1>> = None;
+static mut TX: Mutex<Option<Tx<USART1>>> = Mutex::new(None);
-pub unsafe fn new(tx: Tx<USART1>) {
- TX = Some(tx);
+pub fn init(tx: Tx<USART1>) {
+ interrupt::free(|_cs| {
+ unsafe { TX.get_mut().insert(tx) };
+ });
}
-pub unsafe fn log(str: &str) {
- TX.as_mut().map(|tx| tx.write_str(str));
+pub fn log_args(args: Arguments) {
+ interrupt::free(|_cs| {
+ unsafe { TX.get_mut().as_mut().map(|tx| write(tx, args)) };
+ });
}