From b268fe015af2f100aaad470d6c6b4a3ab0f8bb82 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 17 Aug 2020 19:38:41 +0200 Subject: [PATCH] stdio::drop_uart(): add delay --- libboard_zynq/src/stdio.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libboard_zynq/src/stdio.rs b/libboard_zynq/src/stdio.rs index 24f43bd..6005b76 100644 --- a/libboard_zynq/src/stdio.rs +++ b/libboard_zynq/src/stdio.rs @@ -1,5 +1,5 @@ use core::ops::{Deref, DerefMut}; -use libcortex_a9::mutex::{Mutex, MutexGuard}; +use libcortex_a9::{asm, mutex::{Mutex, MutexGuard}}; use crate::uart::Uart; const UART_RATE: u32 = 115_200; @@ -10,7 +10,15 @@ pub fn get_uart<'a>() -> MutexGuard<'a, LazyUart> { unsafe { UART.lock() } } +/// Deinitialize so that the Uart will be reinitialized on next +/// output. +/// +/// Delays so that an outstanding transmission can finish. pub fn drop_uart() { + for _ in 0..1_000_000 { + asm::nop(); + } + unsafe { UART = Mutex::new(LazyUart::Uninitialized); } }