Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-12-16 19:08:16 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-12-16 19:08:16 +0300
commit95fcaa1d4264d7a11225b2450f8aee553c66f7d5 (patch)
tree42e0ab8dad2852b4882223e2947a9ea721de319d /src/Storage
parentb546702e73667a4ca9c42d7a8ef2b2c1b65ef29f (diff)
File write buffers moved to non-cached memory for SAME70
Diffstat (limited to 'src/Storage')
-rw-r--r--src/Storage/FileStore.cpp4
-rw-r--r--src/Storage/FileWriteBuffer.h16
-rw-r--r--src/Storage/MassStorage.cpp24
3 files changed, 29 insertions, 15 deletions
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp
index 516065cf..57d335e7 100644
--- a/src/Storage/FileStore.cpp
+++ b/src/Storage/FileStore.cpp
@@ -93,7 +93,7 @@ bool FileStore::Open(const char* filePath, OpenMode mode, uint32_t preAllocSize)
// Also try to allocate a write buffer so we can perform faster writes
// We only do this if the mode is write, not append, because we don't want to use up a large buffer to append messages to the log file,
// especially as we need to flush messages to SD card regularly.
- // Currently, append mode is used for the log file and for appending simulated print times to GCodes files (which required read access too).
+ // Currently, append mode is used for the log file and for appending simulated print times to GCodes files (which require read access too).
if (mode == OpenMode::write || mode == OpenMode::writeWithCrc)
{
writeBuffer = MassStorage::AllocateWriteBuffer();
@@ -497,7 +497,7 @@ bool FileStore::Write(const char *s, size_t len) noexcept
{
do
{
- size_t bytesStored = writeBuffer->Store(s + totalBytesWritten, len - totalBytesWritten);
+ const size_t bytesStored = writeBuffer->Store(s + totalBytesWritten, len - totalBytesWritten);
if (writeBuffer->BytesLeft() == 0)
{
const size_t bytesToWrite = writeBuffer->BytesStored();
diff --git a/src/Storage/FileWriteBuffer.h b/src/Storage/FileWriteBuffer.h
index bd3804db..0708f042 100644
--- a/src/Storage/FileWriteBuffer.h
+++ b/src/Storage/FileWriteBuffer.h
@@ -32,13 +32,17 @@ const size_t FileWriteBufLen = 4096;
class FileWriteBuffer
{
public:
+#if SAME70
+ FileWriteBuffer(FileWriteBuffer *n, char *storage) noexcept : next(n), index(0), buf(storage) { }
+#else
FileWriteBuffer(FileWriteBuffer *n) noexcept : next(n), index(0) { }
+#endif
FileWriteBuffer *Next() const noexcept { return next; }
void SetNext(FileWriteBuffer *n) noexcept { next = n; }
- char *Data() noexcept { return reinterpret_cast<char *>(data32); }
- const char *Data() const noexcept { return reinterpret_cast<const char *>(data32); }
+ char *Data() noexcept { return buf; }
+ const char *Data() const noexcept { return buf; }
const size_t BytesStored() const noexcept { return index; }
const size_t BytesLeft() const noexcept { return FileWriteBufLen - index; }
@@ -50,13 +54,17 @@ private:
FileWriteBuffer *next;
size_t index;
- uint32_t data32[FileWriteBufLen / sizeof(uint32_t)]; // 32-bit aligned buffer for better HSMCI performance
+#if SAME70
+ char *buf;
+#else
+ alignas(4) char buf[FileWriteBufLen]; // 32-bit aligned buffer for better HSMCI performance
+#endif
};
inline size_t FileWriteBuffer::Store(const char *data, size_t length) noexcept
{
size_t bytesToStore = min<size_t>(BytesLeft(), length);
- memcpy(Data() + index, data, bytesToStore);
+ memcpy(buf + index, data, bytesToStore);
index += bytesToStore;
return bytesToStore;
}
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp
index dbfe0cf2..dbb8c7db 100644
--- a/src/Storage/MassStorage.cpp
+++ b/src/Storage/MassStorage.cpp
@@ -29,9 +29,10 @@ static_assert(SD_MMC_MEM_CNT == NumSdCards);
// Private data and methods
-#if SAME70
-alignas(4) static __nocache uint8_t sectorBuffers[512][NumSdCards];
-#endif
+# if SAME70
+alignas(4) static __nocache uint8_t sectorBuffers[NumSdCards][512];
+alignas(4) static __nocache char writeBufferStorage[NumFileWriteBuffers][FileWriteBufLen];
+# endif
enum class CardDetectState : uint8_t
{
@@ -121,6 +122,7 @@ static FileInfoParser infoParser;
static DIR findDir;
static FileWriteBuffer *freeWriteBuffers;
#endif
+
#if HAS_MASS_STORAGE || HAS_LINUX_INTERFACE
static Mutex fsMutex;
static FileStore files[MAX_FILES];
@@ -167,14 +169,14 @@ static FileStore files[MAX_FILES];
FileWriteBuffer *MassStorage::AllocateWriteBuffer() noexcept
{
MutexLocker lock(fsMutex);
- if (freeWriteBuffers == nullptr)
- {
- return nullptr;
- }
FileWriteBuffer * const buffer = freeWriteBuffers;
- freeWriteBuffers = buffer->Next();
- buffer->SetNext(nullptr);
+ if (buffer != nullptr)
+ {
+ freeWriteBuffers = buffer->Next();
+ buffer->SetNext(nullptr);
+ buffer->DataTaken(); // make sure that the write pointer is clear
+ }
return buffer;
}
@@ -271,7 +273,11 @@ void MassStorage::Init() noexcept
freeWriteBuffers = nullptr;
for (size_t i = 0; i < NumFileWriteBuffers; ++i)
{
+#if SAME70
+ freeWriteBuffers = new FileWriteBuffer(freeWriteBuffers, writeBufferStorage[i]);
+#else
freeWriteBuffers = new FileWriteBuffer(freeWriteBuffers);
+#endif
}
for (size_t card = 0; card < NumSdCards; ++card)