SysMem.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * SysMem.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "Device.h"
14 
15 namespace Storage
16 {
20 class SysMem : public Device
21 {
22 public:
23  String getName() const override
24  {
25  return F("SysMem");
26  }
27 
28  size_t getBlockSize() const override
29  {
30  return sizeof(uint32_t);
31  }
32 
33  storage_size_t getSize() const override
34  {
35  return 0x80000000;
36  }
37 
38  Type getType() const override
39  {
40  return Type::sysmem;
41  }
42 
43  bool read(storage_size_t address, void* buffer, size_t len) override
44  {
45  if(isFlashPtr(reinterpret_cast<const void*>(address))) {
46  memcpy_P(buffer, reinterpret_cast<const void*>(address), len);
47  } else {
48  memcpy(buffer, reinterpret_cast<const void*>(address), len);
49  }
50  return true;
51  }
52 
53  bool write(storage_size_t address, const void* data, size_t len) override
54  {
55  if(isFlashPtr(reinterpret_cast<const void*>(address))) {
56  return false;
57  }
58 
59  memcpy(reinterpret_cast<void*>(address), data, len);
60  return true;
61  }
62 
63  bool erase_range(storage_size_t address, storage_size_t len) override
64  {
65  if(isFlashPtr(reinterpret_cast<const void*>(address))) {
66  return false;
67  }
68 
69  memset(&address, 0xFF, len);
70  return true;
71  }
72 
74  {
75  public:
76  using PartitionTable::add;
77 
81  Partition add(const String& name, const FSTR::ObjectBase& fstr, Partition::FullType type)
82  {
83  return PartitionTable::add(name, type, reinterpret_cast<uint32_t>(fstr.data()), fstr.size(),
85  }
86  };
87 
89  {
90  return static_cast<SysMemPartitionTable&>(mPartitions);
91  }
92 };
93 
94 extern SysMem sysMem;
95 
96 } // namespace Storage
#define isFlashPtr(ptr)
Simple check to determine if a pointer refers to flash memory.
Definition: Arch/Esp32/Components/libc/src/include/sys/pgmspace.h:24
void * memcpy_P(void *dest, const void *src_P, size_t length)
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
Used when defining data structures.
Definition: ObjectBase.hpp:33
size_t size() const
Get the object data size in bytes.
Definition: ObjectBase.hpp:44
const uint8_t * data() const
Get a pointer to the flash data.
Represents a storage device (e.g. flash memory)
Definition: Components/Storage/src/include/Storage/Device.h:34
PartitionTable mPartitions
Definition: Components/Storage/src/include/Storage/Device.h:188
Type
Storage type.
Definition: Components/Storage/src/include/Storage/Device.h:42
Definition: PartitionTable.h:19
Partition add(const Partition::Info *info)
Add new partition using given Info.
Definition: PartitionTable.h:106
Represents a flash partition.
Definition: Partition.h:86
@ readOnly
Write/erase prohibited.
Partition add(const String &name, const FSTR::ObjectBase &fstr, Partition::FullType type)
Add partition entry for FlashString data access.
Definition: SysMem.h:81
Storage device to access system memory, e.g. RAM.
Definition: SysMem.h:21
Type getType() const override
Obtain device type.
Definition: SysMem.h:38
SysMemPartitionTable & editablePartitions()
Definition: SysMem.h:88
bool write(storage_size_t address, const void *data, size_t len) override
Write data to the storage device.
Definition: SysMem.h:53
size_t getBlockSize() const override
Obtain smallest allocation unit for erase operations.
Definition: SysMem.h:28
storage_size_t getSize() const override
Obtain addressable size of this device.
Definition: SysMem.h:33
String getName() const override
Obtain unique device name.
Definition: SysMem.h:23
bool read(storage_size_t address, void *buffer, size_t len) override
Read data from the storage device.
Definition: SysMem.h:43
bool erase_range(storage_size_t address, storage_size_t len) override
Erase a region of storage in preparation for writing.
Definition: SysMem.h:63
The String class.
Definition: WString.h:137
Definition: FileDevice.h:26
SysMem sysMem
Express both partition type and subtype together.
Definition: Partition.h:139