diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-08-13 18:40:06 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-08-13 18:40:06 +0300 |
commit | 5fe5917ceb4e00353f7b398dd0b5167a182c1192 (patch) | |
tree | 1e8bbc66948fbd510da2a982a25cb20f2d1a078e /src/Storage/MassStorage.cpp | |
parent | 53ce4b3eb1acbf0dcecaeeae6d4cc4d18dc7fb2d (diff) |
Resolved some missing functions wheh HAS_EMBEDDED_FILES is true
Diffstat (limited to 'src/Storage/MassStorage.cpp')
-rw-r--r-- | src/Storage/MassStorage.cpp | 149 |
1 files changed, 79 insertions, 70 deletions
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp index c96cb221..e29701e2 100644 --- a/src/Storage/MassStorage.cpp +++ b/src/Storage/MassStorage.cpp @@ -119,10 +119,13 @@ static SdCardInfo info[NumSdCards]; static Mutex dirMutex; -static FileInfoParser infoParser; static DIR findDir; #endif +#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES +static FileInfoParser infoParser; +#endif + #if HAS_MASS_STORAGE || HAS_LINUX_INTERFACE static FileWriteBuffer *freeWriteBuffers; #endif @@ -841,6 +844,54 @@ bool MassStorage::SetLastModifiedTime(const char *filePath, time_t time) noexcep return ok; } +// Check if the drive referenced in the specified path is mounted. Return true if it is. +// Ideally we would try to mount it if it is not, however mounting a drive can take a long time, and the functions that call this are expected to execute quickly. +bool MassStorage::CheckDriveMounted(const char* path) noexcept +{ + const size_t card = (strlen(path) >= 2 && path[1] == ':' && isDigit(path[0])) + ? path[0] - '0' + : 0; + return card < NumSdCards && info[card].isMounted; +} + +// Return true if any files are open on the file system +bool MassStorage::AnyFileOpen(const FATFS *fs) noexcept +{ + MutexLocker lock(fsMutex); + for (const FileStore & fil : files) + { + if (fil.IsOpenOn(fs)) + { + return true; + } + } + return false; +} + +// Invalidate all open files on the specified file system, returning the number of files that were invalidated +unsigned int MassStorage::InvalidateFiles(const FATFS *fs, bool doClose) noexcept +{ + unsigned int invalidated = 0; + MutexLocker lock(fsMutex); + for (FileStore & fil : files) + { + if (fil.Invalidate(fs, doClose)) + { + ++invalidated; + } + } + return invalidated; +} + +bool MassStorage::IsCardDetected(size_t card) noexcept +{ + return info[card].cardState == CardDetectState::present; +} + +#endif + +#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES + // Mount the specified SD card, returning true if done, false if needs to be called again. // If an error occurs, return true with the error message in 'reply'. // This may only be called to mount one card at a time. @@ -852,6 +903,7 @@ GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportS return GCodeResult::error; } +# if HAS_MASS_STORAGE SdCardInfo& inf = info[card]; MutexLocker lock1(fsMutex); MutexLocker lock2(inf.volMutex); @@ -932,6 +984,8 @@ GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportS } ++inf.seq; +# endif + return GCodeResult::ok; } @@ -945,6 +999,7 @@ GCodeResult MassStorage::Unmount(size_t card, const StringRef& reply) noexcept return GCodeResult::error; } +# if HAS_MASS_STORAGE reply.printf("SD card %u may now be removed", card); const unsigned int numFilesClosed = InternalUnmount(card, true); if (numFilesClosed != 0) @@ -952,69 +1007,48 @@ GCodeResult MassStorage::Unmount(size_t card, const StringRef& reply) noexcept reply.catf(" (%u file(s) were closed)", numFilesClosed); } ++info[card].seq; - return GCodeResult::ok; -} +# endif -// Check if the drive referenced in the specified path is mounted. Return true if it is. -// Ideally we would try to mount it if it is not, however mounting a drive can take a long time, and the functions that call this are expected to execute quickly. -bool MassStorage::CheckDriveMounted(const char* path) noexcept -{ - const size_t card = (strlen(path) >= 2 && path[1] == ':' && isDigit(path[0])) - ? path[0] - '0' - : 0; - return card < NumSdCards && info[card].isMounted; + return GCodeResult::ok; } -// Return true if any files are open on the file system -bool MassStorage::AnyFileOpen(const FATFS *fs) noexcept +unsigned int MassStorage::GetNumFreeFiles() noexcept { + unsigned int numFreeFiles = 0; MutexLocker lock(fsMutex); for (const FileStore & fil : files) { - if (fil.IsOpenOn(fs)) + if (fil.IsFree()) { - return true; + ++numFreeFiles; } } - return false; + return numFreeFiles; } -// Invalidate all open files on the specified file system, returning the number of files that were invalidated -unsigned int MassStorage::InvalidateFiles(const FATFS *fs, bool doClose) noexcept +GCodeResult MassStorage::GetFileInfo(const char *filePath, GCodeFileInfo& info, bool quitEarly) noexcept { - unsigned int invalidated = 0; - MutexLocker lock(fsMutex); - for (FileStore & fil : files) - { - if (fil.Invalidate(fs, doClose)) - { - ++invalidated; - } - } - return invalidated; + return infoParser.GetFileInfo(filePath, info, quitEarly); } -bool MassStorage::IsCardDetected(size_t card) noexcept +void MassStorage::Diagnostics(MessageType mtype) noexcept { - return info[card].cardState == CardDetectState::present; -} + Platform& platform = reprap.GetPlatform(); -#endif + // Show the number of free entries in the file table + platform.MessageF(mtype, "=== Storage ===\nFree file entries: %u\n", MassStorage::GetNumFreeFiles()); -#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES +# if HAS_HIGH_SPEED_SD + // Show the HSMCI CD pin and speed + platform.MessageF(mtype, "SD card 0 %s, interface speed: %.1fMBytes/sec\n", + (IsCardDetected(0) ? "detected" : "not detected"), (double)((float)sd_mmc_get_interface_speed(0) * 0.000001)); +# elif HAS_MASS_STORAGE + platform.MessageF(mtype, "SD card 0 %s\n", (MassStorage::IsCardDetected(0) ? "detected" : "not detected")); +# endif -unsigned int MassStorage::GetNumFreeFiles() noexcept -{ - unsigned int numFreeFiles = 0; - MutexLocker lock(fsMutex); - for (const FileStore & fil : files) - { - if (fil.IsFree()) - { - ++numFreeFiles; - } - } - return numFreeFiles; + // Show the longest SD card write time + platform.MessageF(mtype, "SD card longest read time %.1fms, write time %.1fms, max retries %u\n", + (double)DiskioGetAndClearLongestReadTime(), (double)DiskioGetAndClearLongestWriteTime(), DiskioGetAndClearMaxRetryCount()); } #endif @@ -1118,31 +1152,6 @@ Mutex& MassStorage::GetVolumeMutex(size_t vol) noexcept return info[vol].volMutex; } -GCodeResult MassStorage::GetFileInfo(const char *filePath, GCodeFileInfo& info, bool quitEarly) noexcept -{ - return infoParser.GetFileInfo(filePath, info, quitEarly); -} - -void MassStorage::Diagnostics(MessageType mtype) noexcept -{ - Platform& platform = reprap.GetPlatform(); - - // Show the number of free entries in the file table - platform.MessageF(mtype, "=== Storage ===\nFree file entries: %u\n", MassStorage::GetNumFreeFiles()); - -# if HAS_HIGH_SPEED_SD - // Show the HSMCI CD pin and speed - platform.MessageF(mtype, "SD card 0 %s, interface speed: %.1fMBytes/sec\n", - (IsCardDetected(0) ? "detected" : "not detected"), (double)((float)sd_mmc_get_interface_speed(0) * 0.000001)); -# else - platform.MessageF(mtype, "SD card 0 %s\n", (MassStorage::IsCardDetected(0) ? "detected" : "not detected")); -# endif - - // Show the longest SD card write time - platform.MessageF(mtype, "SD card longest read time %.1fms, write time %.1fms, max retries %u\n", - (double)DiskioGetAndClearLongestReadTime(), (double)DiskioGetAndClearLongestWriteTime(), DiskioGetAndClearMaxRetryCount()); -} - # if SUPPORT_OBJECT_MODEL const ObjectModel * MassStorage::GetVolume(size_t vol) noexcept |