Skip to content

Commit

Permalink
fix: 所有 \n 转义 \r\n
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <ydrml@hotmail.com>
  • Loading branch information
YdrMaster committed Jul 21, 2022
1 parent b93a537 commit 76ae2c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
21 changes: 16 additions & 5 deletions see/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::sync::atomic::{AtomicU8, Ordering};
use hal::{
clint::{msip, mtimecmp},
pac::UART0,
Expand All @@ -17,11 +18,7 @@ pub fn init() {
rustsbi::init_ipi(&Ipi);
}

impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
fn getchar(&self) -> u8 {
unimplemented!()
}

impl LegacyConsole {
fn putchar(&self, ch: u8) {
let uart = unsafe { &*UART0::ptr() };
// 等待 FIFO 空位
Expand All @@ -32,6 +29,20 @@ impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
}
}

impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
fn getchar(&self) -> u8 {
unimplemented!()
}

fn putchar(&self, ch: u8) {
static LAST: AtomicU8 = AtomicU8::new(0);
if ch == b'\n' && LAST.swap(ch, Ordering::Relaxed) != b'\r' {
self.putchar(b'\r');
}
self.putchar(ch);
}
}

impl rustsbi::Timer for Timer {
fn set_timer(&self, stime_value: u64) {
mtimecmp::write(stime_value);
Expand Down
25 changes: 19 additions & 6 deletions spl/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use core::ops::Shl;
use core::{
ops::Shl,
sync::atomic::{AtomicU8, Ordering},
};
use hal::pac::UART0;

pub struct Out;
Expand All @@ -10,17 +13,27 @@ pub enum Hex {
Fmt(usize),
}

impl Out {
fn putchar(&self, ch: u8) {
let uart = unsafe { &*UART0::ptr() };
// 等待 FIFO 空位
while uart.usr.read().tfnf().is_full() {
core::hint::spin_loop();
}
uart.thr().write(|w| w.thr().variant(ch));
}
}

impl Shl<u8> for Out {
type Output = Self;

#[inline]
fn shl(self, rhs: u8) -> Self::Output {
let uart = unsafe { &*UART0::ptr() };
// 等待 FIFO 空位
while uart.usr.read().tfnf().is_full() {
core::hint::spin_loop();
static LAST: AtomicU8 = AtomicU8::new(0);
if rhs == b'\n' && LAST.swap(rhs, Ordering::Relaxed) != b'\r' {
self.putchar(b'\r');
}
uart.thr().write(|w| w.thr().variant(rhs));
self.putchar(rhs);
self
}
}
Expand Down
4 changes: 3 additions & 1 deletion xtask/src/components.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{xfel::Xfel, AsmArg, FlashArgs, Package, Target, XError, DIRS};
use command_ext::{CommandExt, Ext};
use command_ext::{dir, CommandExt, Ext};
use common::uninit;
use std::{
ffi::OsStr,
Expand Down Expand Up @@ -68,6 +68,7 @@ impl Components {
.target
.join(dt.file_stem().unwrap_or_else(|| OsStr::new("nezha")))
.with_extension("dtb");
dir::create_parent(&dtb).unwrap();
Ext::new("dtc").arg("-o").arg(&dtb).arg(&dt).invoke();
ans.dtb.replace(dtb);
} else {
Expand Down Expand Up @@ -98,6 +99,7 @@ impl Components {
let path = if output.is_dir() {
output.join(package.name()).with_extension("asm")
} else {
dir::create_parent(&output).unwrap();
output
};
// 保存
Expand Down

0 comments on commit 76ae2c0

Please sign in to comment.