Skip to content

Commit 3d14e3b

Browse files
authored
Merge pull request #46 from diondokter/upchannel-flush
Add flush function to `UpChannel`
2 parents a1bae7c + aa91518 commit 3d14e3b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

rtt-target/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ impl UpChannel {
241241

242242
Some(UpChannel(ptr))
243243
}
244+
245+
/// Wait until all data has been read by the debugger.
246+
///
247+
/// *Note: This means that if no debugger is connected or if it isn't reading the rtt data,*
248+
/// *this function will wait indefinitely.*
249+
pub fn flush(&self) {
250+
loop {
251+
let (write, read) = self.channel().read_pointers();
252+
if write == read {
253+
break;
254+
}
255+
core::hint::spin_loop();
256+
}
257+
}
244258
}
245259

246260
impl fmt::Write for UpChannel {

rtt-target/src/rtt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl RttChannel {
146146
}
147147
}
148148

149-
fn read_pointers(&self) -> (usize, usize) {
149+
pub(crate) fn read_pointers(&self) -> (usize, usize) {
150150
let write = self.write.load(SeqCst);
151151
let read = self.read.load(SeqCst);
152152

0 commit comments

Comments
 (0)