`defmt-rtt`: Split out common method `write_impl` from both write methods
@@ -57,21 +57,7 @@ impl Channel {
let cursor = write;
let len = bytes.len().min(available);
- unsafe {
- if cursor + len > BUF_SIZE {
- // split memcpy
- let pivot = BUF_SIZE - cursor;
- ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), pivot);
- ptr::copy_nonoverlapping(bytes.as_ptr().add(pivot), self.buffer, len - pivot);
- } else {
- // single memcpy
- ptr::copy_nonoverlapping(bytes.as_ptr(), self.buffer.add(cursor), len);
- }
- }
- self.write
- .store(write.wrapping_add(len) % BUF_SIZE, Ordering::Release);
-
- len
+ self.write_impl(bytes, cursor, len)
}
fn nonblocking_write(&self, bytes: &[u8]) -> usize {
@@ -80,6 +66,10 @@ impl Channel {
// NOTE truncate atBUF_SIZE to avoid more than one "wrap-around" in a single `write` call
let len = bytes.len().min(BUF_SIZE);
+ self.write_impl(bytes, cursor, len)
+ }
+
+ fn write_impl(&self, bytes: &[u8], cursor: usize, len: usize) -> usize {
unsafe {
if cursor + len > BUF_SIZE {
// split memcpy
@@ -92,7 +82,7 @@ impl Channel {
}
}
self.write
- .store(write.wrapping_add(len) % BUF_SIZE, Ordering::Release);
+ .store(cursor.wrapping_add(len) % BUF_SIZE, Ordering::Release);
len
}
