libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::LinuxBinaryFileFlash< FLASH_SIZE > Class Template Reference

Linux 二进制文件闪存实现 / Linux binary-file flash implementation. More...

#include <linux_flash.hpp>

Inheritance diagram for LibXR::LinuxBinaryFileFlash< FLASH_SIZE >:
[legend]
Collaboration diagram for LibXR::LinuxBinaryFileFlash< FLASH_SIZE >:
[legend]

Public Member Functions

 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
 
- Public Member Functions inherited from LibXR::Flash
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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.
Definition flash.cpp:7

Member Function Documentation

◆ Erase()

template<size_t FLASH_SIZE>
ErrorCode LibXR::LinuxBinaryFileFlash< FLASH_SIZE >::Erase ( size_t offset,
size_t size )
inlineoverridevirtual

擦除闪存区域 / 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 {
60 ASSERT(offset % MinEraseSize() == 0);
61 ASSERT(size % MinEraseSize() == 0);
62
63 if ((offset + size) > flash_area_.size())
64 {
66 }
67
68 Memory::FastSet(flash_area_.data() + offset, 0xFF, size);
69
70 return SyncToFile();
71 }
size_t MinEraseSize() const
获取最小可擦除块大小(字节)。 Returns the minimum erasable block size in bytes.
Definition flash.hpp:76
static void FastSet(void *dst, uint8_t value, size_t size)
快速内存填充 / Fast memory fill
@ OUT_OF_RANGE
超出范围 / Out of range

◆ Write()

template<size_t FLASH_SIZE>
ErrorCode LibXR::LinuxBinaryFileFlash< FLASH_SIZE >::Write ( size_t offset,
ConstRawData data )
inlineoverridevirtual

写入闪存数据 / 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 {
85 }
86
87 if (offset % MinWriteSize() != 0 || data.size_ % MinWriteSize() != 0)
88 {
89 return ErrorCode::FAILED;
90 }
91
92 if (write_order_check_)
93 {
94 ASSERT(offset % MinEraseSize() == 0);
95 }
96
97 uint8_t* dst = flash_area_.data() + offset;
98 const uint8_t* src = static_cast<const uint8_t*>(data.addr_);
99
100 if (write_as_one_check_)
101 {
102 for (size_t i = 0; i < data.size_; ++i)
103 {
104 if ((~dst[i] & src[i]))
105 {
106 return ErrorCode::FAILED;
107 }
108 }
109 }
110
111 Memory::FastCopy(dst, src, data.size_);
112 return SyncToFile();
113 }
size_t MinWriteSize() const
获取最小可写块大小(字节) / Returns the minimum writable block size in bytes.
Definition flash.hpp:83
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
@ FAILED
操作失败 / Operation failed

The documentation for this class was generated from the following file: