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>2022-02-14 16:12:33 +0300
committerDavid Crocker <dcrocker@eschertech.com>2022-02-14 16:12:33 +0300
commit4f593f75c86cc035d7cdcd744e6a52ca940aa2d5 (patch)
treef5b48208f940c191b937f8b3efed0281ae942146 /src/Storage
parent252f7739eb448c4a24bfb000a01f72facfe8e019 (diff)
Added SD card partition size to M39 response and object model
Diffstat (limited to 'src/Storage')
-rw-r--r--src/Storage/MassStorage.cpp36
-rw-r--r--src/Storage/MassStorage.h11
2 files changed, 32 insertions, 15 deletions
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp
index 8529c02d..d67ac669 100644
--- a/src/Storage/MassStorage.cpp
+++ b/src/Storage/MassStorage.cpp
@@ -85,13 +85,19 @@ void SdCardInfo::Clear(unsigned int card) noexcept
#define OBJECT_MODEL_FUNC(...) OBJECT_MODEL_FUNC_BODY(SdCardInfo, __VA_ARGS__)
#define OBJECT_MODEL_FUNC_IF(_condition,...) OBJECT_MODEL_FUNC_IF_BODY(SdCardInfo, _condition,__VA_ARGS__)
-static uint64_t GetFreeSpace(size_t slot)
+// These two functions are only called from one place each in the OM table, hence inlined
+static inline uint64_t GetFreeSpace(size_t slot)
{
- uint64_t capacity, freeSpace;
- uint32_t speed;
- uint32_t clSize;
- (void)MassStorage::GetCardInfo(slot, capacity, freeSpace, speed, clSize);
- return freeSpace;
+ MassStorage::SdCardReturnedInfo returnedInfo;
+ (void)MassStorage::GetCardInfo(slot, returnedInfo);
+ return returnedInfo.freeSpace;
+}
+
+static inline uint64_t GetPartitionSize(size_t slot)
+{
+ MassStorage::SdCardReturnedInfo returnedInfo;
+ (void)MassStorage::GetCardInfo(slot, returnedInfo);
+ return returnedInfo.partitionSize;
}
static const char * const VolPathNames[] = { "0:/", "1:/" };
@@ -109,6 +115,7 @@ constexpr ObjectModelTableEntry SdCardInfo::objectModelTable[] =
{ "freeSpace", OBJECT_MODEL_FUNC_IF(self->isMounted, GetFreeSpace(context.GetLastIndex())), ObjectModelEntryFlags::none },
{ "mounted", OBJECT_MODEL_FUNC(self->isMounted), ObjectModelEntryFlags::none },
{ "openFiles", OBJECT_MODEL_FUNC_IF(self->isMounted, MassStorage::AnyFileOpen(&(self->fileSystem))), ObjectModelEntryFlags::none },
+ { "partitionSize", OBJECT_MODEL_FUNC_IF(self->isMounted, GetPartitionSize(context.GetLastIndex())), ObjectModelEntryFlags::none },
{ "path", OBJECT_MODEL_FUNC_NOSELF(VolPathNames[context.GetLastIndex()]), ObjectModelEntryFlags::verbose },
{ "speed", OBJECT_MODEL_FUNC_IF(self->isMounted, (int32_t)sd_mmc_get_interface_speed(context.GetLastIndex())), ObjectModelEntryFlags::none },
};
@@ -119,7 +126,7 @@ constexpr ObjectModelTableEntry SdCardInfo::objectModelTable[] =
path = null
*/
-constexpr uint8_t SdCardInfo::objectModelTableDescriptor[] = { 1, 6 };
+constexpr uint8_t SdCardInfo::objectModelTableDescriptor[] = { 1, 7 };
DEFINE_GET_OBJECT_MODEL_TABLE(SdCardInfo)
@@ -1207,7 +1214,7 @@ void MassStorage::RecordSimulationTime(const char *printingFilePath, uint32_t si
}
// Get information about the SD card and interface speed
-MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity, uint64_t& freeSpace, uint32_t& speed, uint32_t& clSize) noexcept
+MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, SdCardReturnedInfo& returnedInfo) noexcept
{
if (slot >= GetNumVolumes())
{
@@ -1220,8 +1227,8 @@ MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity
return InfoResult::noCard;
}
- capacity = (uint64_t)sd_mmc_get_capacity(slot) * 1024;
- speed = sd_mmc_get_interface_speed(slot);
+ returnedInfo.cardCapacity = (uint64_t)sd_mmc_get_capacity(slot) * 1024;
+ returnedInfo.speed = sd_mmc_get_interface_speed(slot);
String<StringLength50> path;
path.printf("%u:/", slot);
uint32_t freeClusters;
@@ -1229,13 +1236,14 @@ MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity
const FRESULT fr = f_getfree(path.c_str(), &freeClusters, &fs);
if (fr == FR_OK)
{
- clSize = fs->csize * 512;
- freeSpace = (uint64_t)freeClusters * clSize;
+ returnedInfo.clSize = fs->csize * 512;
+ returnedInfo.partitionSize = (uint64_t)(fs->n_fatent - 2) * returnedInfo.clSize;
+ returnedInfo.freeSpace = (uint64_t)freeClusters * returnedInfo.clSize;
}
else
{
- clSize = 0;
- freeSpace = 0;
+ returnedInfo.clSize = 0;
+ returnedInfo.cardCapacity = returnedInfo.partitionSize = returnedInfo.freeSpace = 0;
}
return InfoResult::ok;
}
diff --git a/src/Storage/MassStorage.h b/src/Storage/MassStorage.h
index 551bbe6a..2d351569 100644
--- a/src/Storage/MassStorage.h
+++ b/src/Storage/MassStorage.h
@@ -102,7 +102,16 @@ namespace MassStorage
ok = 2
};
- InfoResult GetCardInfo(size_t slot, uint64_t& capacity, uint64_t& freeSpace, uint32_t& speed, uint32_t& clSize) noexcept;
+ struct SdCardReturnedInfo
+ {
+ uint64_t cardCapacity;
+ uint64_t partitionSize;
+ uint64_t freeSpace;
+ uint32_t clSize;
+ uint32_t speed;
+ };
+
+ InfoResult GetCardInfo(size_t slot, SdCardReturnedInfo& returnedInfo) noexcept;
# ifdef DUET3_MB6HC
GCodeResult ConfigureSdCard(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException); // Configure additional SD card slots