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>2017-05-21 15:29:07 +0300
committerDavid Crocker <dcrocker@eschertech.com>2017-05-21 15:33:07 +0300
commit7150f432d5652293c9c09baab9ebd1055a47c3a7 (patch)
treeeac31f94459fce062ddd634aa60deec34f09715e /src/Storage/FileWriteBuffer.h
parentd3b40101ad260b97a42b1c5d9b63ad9d95b880e7 (diff)
Version 1.19beta1
Changes to WiFi server and interface code for better network reliability. FTP and MDNS now working on Duet WiFi. Changed heater tuning to allow more time for the temperature to rise when tuning a bed or chamber heater Toned down the temperaure warning message
Diffstat (limited to 'src/Storage/FileWriteBuffer.h')
-rw-r--r--src/Storage/FileWriteBuffer.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/Storage/FileWriteBuffer.h b/src/Storage/FileWriteBuffer.h
new file mode 100644
index 00000000..1e7130c4
--- /dev/null
+++ b/src/Storage/FileWriteBuffer.h
@@ -0,0 +1,57 @@
+/*
+ * FileWriteBuffer.h
+ *
+ * Created on: 19 May 2017
+ * Author: Christian
+ */
+
+#ifndef SRC_STORAGE_FILEWRITEBUFFER_H_
+#define SRC_STORAGE_FILEWRITEBUFFER_H_
+
+#include "RepRapFirmware.h"
+
+
+#ifdef DUET_NG
+const size_t NumFileWriteBuffers = 2; // Number of write buffers
+const size_t FileWriteBufLen = 8192; // Size of each write buffer
+#else
+const size_t NumFileWriteBuffers = 1;
+const size_t FileWriteBufLen = 4096;
+#endif
+
+
+// Class to cache data that is about to be written to the SD card. This is NOT a ring buffer,
+// instead it just provides simple interfaces to cache a certain amount of data so that fewer
+// f_write() calls are needed. This effectively improves upload speeds.
+class FileWriteBuffer
+{
+public:
+ FileWriteBuffer(FileWriteBuffer *n) : next(n), index(0) { }
+
+ FileWriteBuffer *Next() const { return next; }
+ void SetNext(FileWriteBuffer *n) { next = n; }
+
+ char *Data() { return reinterpret_cast<char *>(data32); }
+ const char *Data() const { return reinterpret_cast<const char *>(data32); }
+ const size_t BytesStored() const { return index; }
+ const size_t BytesLeft() const { return FileWriteBufLen - index; }
+
+ size_t Store(const char *data, size_t length); // Stores some data and returns how much could be stored
+ void DataTaken() { index = 0; } // Called to indicate that the buffer has been written
+
+private:
+ FileWriteBuffer *next;
+
+ size_t index;
+ int32_t data32[FileWriteBufLen / sizeof(int32_t)]; // 32-bit aligned buffer for better HSMCI performance
+};
+
+inline size_t FileWriteBuffer::Store(const char *data, size_t length)
+{
+ size_t bytesToStore = min<size_t>(BytesLeft(), length);
+ memcpy(Data() + index, data, bytesToStore);
+ index += bytesToStore;
+ return bytesToStore;
+}
+
+#endif