Linux 二进制文件闪存实现 / Linux binary-file flash implementation.
More...
#include <linux_flash.hpp>
|
| | LinuxBinaryFileFlash (const std::string &file_path, size_t min_erase_size=FLASH_SIZE/2, size_t min_write_size=sizeof(uint8_t), bool write_order_check=false, bool write_as_one_check=false) |
| | 构造 Linux 文件闪存对象 / Construct Linux file-backed flash
|
| |
| ErrorCode | Erase (size_t offset, size_t size) override |
| | 擦除闪存区域 / Erase flash area
|
| |
| ErrorCode | Write (size_t offset, ConstRawData data) override |
| | 写入闪存数据 / Write flash data
|
| |
| | Flash (size_t min_erase_size, size_t min_write_size, RawData flash_area) |
| | Constructs a Flash object with specified properties. 构造函数,初始化闪存属性。
|
| |
| virtual ErrorCode | Read (size_t offset, RawData data) |
| | Reads data from the flash memory. 从闪存中读取数据。
|
| |
| size_t | MinEraseSize () const |
| | Returns the minimum erasable block size in bytes. 获取最小可擦除块大小(字节)。
|
| |
| size_t | MinWriteSize () const |
| | Returns the minimum writable block size in bytes. 获取最小可写块大小(字节)。
|
| |
| size_t | Size () const |
| | Returns the size of the flash memory area. 获取闪存存储区域的大小。
|
| |
template<size_t FLASH_SIZE>
class LibXR::LinuxBinaryFileFlash< FLASH_SIZE >
Linux 二进制文件闪存实现 / Linux binary-file flash implementation.
- Template Parameters
-
| FLASH_SIZE | 闪存容量(字节) / Flash size in bytes |
Definition at line 22 of file linux_flash.hpp.
◆ LinuxBinaryFileFlash()
template<size_t FLASH_SIZE>
| LibXR::LinuxBinaryFileFlash< FLASH_SIZE >::LinuxBinaryFileFlash |
( |
const std::string & | file_path, |
|
|
size_t | min_erase_size = FLASH_SIZE / 2, |
|
|
size_t | min_write_size = sizeof(uint8_t), |
|
|
bool | write_order_check = false, |
|
|
bool | write_as_one_check = false ) |
|
inline |
构造 Linux 文件闪存对象 / Construct Linux file-backed flash
- Parameters
-
| file_path | 二进制文件路径 / Binary file path |
| min_erase_size | 最小擦除块大小 / Minimum erase block size |
| min_write_size | 最小写入块大小 / Minimum write block size |
| write_order_check | 写入顺序检查开关 / Enable write order check |
| write_as_one_check | 写入一致性检查开关 / Enable write consistency check |
Definition at line 34 of file linux_flash.hpp.
38 :
Flash(min_erase_size, min_write_size, RawData(&flash_area_,
sizeof(flash_area_))),
39 file_path_(file_path),
40 write_order_check_(write_order_check),
41 write_as_one_check_(write_as_one_check)
42 {
43 std::ifstream file(file_path_, std::ios::binary);
44 if (file)
45 {
46 file.read(reinterpret_cast<char*>(flash_area_.data()),
47 static_cast<std::streamsize>(flash_area_.size()));
48 }
49 }
Flash(size_t min_erase_size, size_t min_write_size, RawData flash_area)
Constructs a Flash object with specified properties. 构造函数,初始化闪存属性。
◆ Erase()
template<size_t FLASH_SIZE>
擦除闪存区域 / Erase flash area
- Parameters
-
| offset | 相对闪存起始地址的偏移 / Offset from flash base |
| size | 擦除长度 / Erase size |
- Returns
- ErrorCode 错误码 / Error code
Implements LibXR::Flash.
Definition at line 58 of file linux_flash.hpp.
59 {
62
63 if ((offset + size) > flash_area_.size())
64 {
65 return ErrorCode::OUT_OF_RANGE;
66 }
67
69
70 return SyncToFile();
71 }
size_t MinEraseSize() const
Returns the minimum erasable block size in bytes. 获取最小可擦除块大小(字节)。
static void FastSet(void *dst, uint8_t value, size_t size)
快速内存填充 / Fast memory fill
◆ SyncToFile()
template<size_t FLASH_SIZE>
Definition at line 123 of file linux_flash.hpp.
124 {
125 std::ofstream file(file_path_, std::ios::binary | std::ios::trunc);
126 if (!file)
127 {
128 return ErrorCode::FAILED;
129 }
130 file.write(reinterpret_cast<const char*>(flash_area_.data()),
131 static_cast<std::streamsize>(flash_area_.size()));
132 return ErrorCode::OK;
133 }
◆ Write()
template<size_t FLASH_SIZE>
写入闪存数据 / Write flash data
- Parameters
-
| offset | 相对闪存起始地址的偏移 / Offset from flash base |
| data | 写入数据 / Data to write |
- Returns
- ErrorCode 错误码 / Error code
Implements LibXR::Flash.
Definition at line 80 of file linux_flash.hpp.
81 {
82 if ((offset + data.size_) > flash_area_.size())
83 {
84 return ErrorCode::OUT_OF_RANGE;
85 }
86
88 {
89 ASSERT(false);
90 return ErrorCode::FAILED;
91 }
92
93 if (write_order_check_)
94 {
96 }
97
98 uint8_t* dst = flash_area_.data() + offset;
99 const uint8_t* src = static_cast<const uint8_t*>(data.addr_);
100
101 if (write_as_one_check_)
102 {
103 for (size_t i = 0; i < data.size_; ++i)
104 {
105 if ((~dst[i] & src[i]))
106 {
107 ASSERT(false);
108 return ErrorCode::FAILED;
109 }
110 }
111 }
112
114 return SyncToFile();
115 }
size_t MinWriteSize() const
Returns the minimum writable block size in bytes. 获取最小可写块大小(字节)。
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
◆ file_path_
template<size_t FLASH_SIZE>
◆ flash_area_
template<size_t FLASH_SIZE>
◆ write_as_one_check_
template<size_t FLASH_SIZE>
◆ write_order_check_
template<size_t FLASH_SIZE>
The documentation for this class was generated from the following file: