From 2474df886c5b357af0f3a59988cb79715187b06b Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Mon, 3 Feb 2020 10:33:00 +0800 Subject: [PATCH] Add data flush in uart put function --- risc_v/ch6/src/uart.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/risc_v/ch6/src/uart.rs b/risc_v/ch6/src/uart.rs index de54a91..9441610 100755 --- a/risc_v/ch6/src/uart.rs +++ b/risc_v/ch6/src/uart.rs @@ -101,7 +101,14 @@ impl Uart { pub fn put(&mut self, c: u8) { let ptr = self.base_address as *mut u8; + loop { + // Wait until previous data is flushed + if unsafe { ptr.add(5).read_volatile() } & (1 << 5) != 0 { + break; + } + } unsafe { + // Write data ptr.add(0).write_volatile(c); } }