arm: async uart writes & fixes

This commit is contained in:
2022-05-17 10:17:56 -07:00
parent e9f623e754
commit e39cdc5709
13 changed files with 232 additions and 190 deletions

View File

@@ -15,7 +15,8 @@ struct RingBuffer {
return false;
}
const size_t to_copy = std::min(buffer.size() - write_ptr, data.size());
std::copy(data.begin(), data.begin() + to_copy, buffer.begin() + write_ptr);
std::copy(data.begin(), data.begin() + to_copy,
buffer.begin() + write_ptr);
if (to_copy < data.size()) {
std::copy(data.begin() + to_copy, data.end(), buffer.begin());
}
@@ -29,9 +30,11 @@ struct RingBuffer {
return false;
}
const size_t to_copy = std::min(buffer.size() - read_ptr, out.size());
std::copy(buffer.begin() + read_ptr, buffer.begin() + read_ptr + to_copy, out.begin());
std::copy(buffer.begin() + read_ptr,
buffer.begin() + read_ptr + to_copy, out.begin());
if (to_copy < out.size()) {
std::copy(buffer.begin(), buffer.begin() + out.size() - to_copy, out.begin() + to_copy);
std::copy(buffer.begin(), buffer.begin() + out.size() - to_copy,
out.begin() + to_copy);
}
Pop(out.size());
return true;
@@ -59,9 +62,7 @@ struct RingBuffer {
return true;
}
size_t FreeSpace() const {
return buffer.size() - AvailableData();
}
size_t FreeSpace() const { return buffer.size() - AvailableData(); }
size_t AvailableData() const {
if (read_ptr == write_ptr) {