LinuxBinaryFileFlash 类,用于从二进制文件加载闪存数据 LinuxBinaryFileFlash class for loading flash data from a binary file.
More...
#include <linux_flash.hpp>
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()
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.
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. 构造函数,初始化闪存属性。
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
◆ Erase()
擦除闪存区域
- 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()
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()
写入数据 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
102
103 if (write_as_one_check_)
104 {
105 for (size_t i = 0; i < data.size_; ++i)
106 {
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_
◆ flash_area_
◆ write_as_one_check_
◆ write_order_check_
The documentation for this class was generated from the following file: