LinuxBinaryFileFlash 类,用于从二进制文件加载闪存数据 LinuxBinaryFileFlash class for loading flash data from a binary file.
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) |
| LinuxBinaryFileFlash 构造函数 LinuxBinaryFileFlash constructor.
|
|
ErrorCode | Erase (size_t offset, size_t size) override |
| 擦除闪存区域
|
|
ErrorCode | Write (size_t offset, ConstRawData data) override |
| 写入数据 Write data
|
|
| Flash (size_t min_erase_size, size_t min_write_size, RawData flash_area) |
| Constructs a Flash object with specified properties. 构造函数,初始化闪存属性。
|
|
template<size_t FLASH_SIZE>
class LibXR::LinuxBinaryFileFlash< FLASH_SIZE >
LinuxBinaryFileFlash 类,用于从二进制文件加载闪存数据 LinuxBinaryFileFlash class for loading flash data from a binary file.
- Template Parameters
-
FLASH_SIZE | 闪存大小 Flash size |
Definition at line 23 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 |
LinuxBinaryFileFlash 构造函数 LinuxBinaryFileFlash constructor.
- 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 36 of file linux_flash.hpp.
40 :
Flash(min_erase_size, min_write_size, RawData(&flash_area_,
sizeof(flash_area_))),
41 file_path_(file_path),
42 write_order_check_(write_order_check),
43 write_as_one_check_(write_as_one_check)
44 {
45 std::ifstream file(file_path_, std::ios::binary);
46 if (file)
47 {
48 file.read(reinterpret_cast<char*>(flash_area_.data()),
49 static_cast<std::streamsize>(flash_area_.size()));
50 }
51 }
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>
擦除闪存区域
- Parameters
-
offset | 距离闪存区域起始位置的偏移量 Offset from the start of the flash area |
size | 要擦除的大小 Size to erase |
- Returns
- ErrorCode
Implements LibXR::Flash.
Definition at line 60 of file linux_flash.hpp.
61 {
64
65 if ((offset + size) > flash_area_.size())
66 {
67 return ErrorCode::OUT_OF_RANGE;
68 }
69
70 std::memset(flash_area_.data() + offset, 0xFF, size);
71
72 return SyncToFile();
73 }
size_t min_erase_size_
Minimum erasable block size in bytes. 最小可擦除块大小(字节)。
◆ SyncToFile()
template<size_t FLASH_SIZE>
Definition at line 125 of file linux_flash.hpp.
126 {
127 std::ofstream file(file_path_, std::ios::binary | std::ios::trunc);
128 if (!file)
129 {
130 return ErrorCode::FAILED;
131 }
132 file.write(reinterpret_cast<const char*>(flash_area_.data()),
133 static_cast<std::streamsize>(flash_area_.size()));
134 return ErrorCode::OK;
135 }
◆ Write()
template<size_t FLASH_SIZE>
写入数据 Write data
- Parameters
-
offset | 距离闪存区域起始位置的偏移量 Offset from the start of the flash area |
data | 要写入的数据 Data to write |
- Returns
- ErrorCode
Implements LibXR::Flash.
Definition at line 82 of file linux_flash.hpp.
83 {
84 if ((offset + data.size_) > flash_area_.size())
85 {
86 return ErrorCode::OUT_OF_RANGE;
87 }
88
90 {
91 ASSERT(false);
92 return ErrorCode::FAILED;
93 }
94
95 if (write_order_check_)
96 {
98 }
99
100 uint8_t* dst = flash_area_.data() + offset;
101 const uint8_t* src = static_cast<const uint8_t*>(data.addr_);
102
103 if (write_as_one_check_)
104 {
105 for (size_t i = 0; i < data.size_; ++i)
106 {
107 if ((~dst[i] & src[i]))
108 {
109 ASSERT(false);
110 return ErrorCode::FAILED;
111 }
112 }
113 }
114
115 std::memcpy(dst, src, data.size_);
116 return SyncToFile();
117 }
size_t min_write_size_
Minimum writable block size in bytes. 最小可写块大小(字节)。
◆ 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: