libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Flash Class Referenceabstract

抽象基类,表示闪存接口。 Abstract base class representing a flash memory interface. More...

#include <flash.hpp>

Inheritance diagram for LibXR::Flash:
[legend]

Public Member Functions

 Flash (size_t min_erase_size, size_t min_write_size, RawData flash_area)
 构造函数,初始化闪存属性。 Constructs a Flash object with specified properties.
 
virtual ErrorCode Erase (size_t offset, size_t size)=0
 擦除闪存的指定区域 / Erases a section of the flash memory.
 
virtual ErrorCode Write (size_t offset, ConstRawData data)=0
 向闪存写入数据 / Writes data to the flash memory.
 
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

抽象基类,表示闪存接口。 Abstract base class representing a flash memory interface.

Definition at line 31 of file flash.hpp.

Constructor & Destructor Documentation

◆ Flash()

Flash::Flash ( size_t min_erase_size,
size_t min_write_size,
RawData flash_area )

构造函数,初始化闪存属性。 Constructs a Flash object with specified properties.

Parameters
min_erase_size最小可擦除块大小(字节)。 Minimum erasable block size in bytes.
min_write_size最小可写块大小(字节) / Minimum writable block size in bytes.
flash_area用于闪存操作的存储区域。 Memory area allocated for flash operations.

Definition at line 7 of file flash.cpp.

8 : min_erase_size_(min_erase_size),
9 min_write_size_(min_write_size),
10 flash_area_(flash_area)
11{
12}

Member Function Documentation

◆ Erase()

virtual ErrorCode LibXR::Flash::Erase ( size_t offset,
size_t size )
pure virtual

擦除闪存的指定区域 / Erases a section of the flash memory.

Parameters
offset要擦除的起始偏移地址 / The starting offset of the section to erase.
size要擦除的区域大小 / The size of the section to erase.
Returns
返回操作结果的错误码 / ErrorCode indicating success or failure.

Implemented in LibXR::CH32Flash, LibXR::LinuxBinaryFileFlash< FLASH_SIZE >, and LibXR::STM32Flash.

◆ MinEraseSize()

size_t LibXR::Flash::MinEraseSize ( ) const
inline

获取最小可擦除块大小(字节)。 Returns the minimum erasable block size in bytes.

Returns
最小可擦除块大小(字节) / size_t Minimum erasable block size in bytes.

Definition at line 76 of file flash.hpp.

76{ return min_erase_size_; }

◆ MinWriteSize()

size_t LibXR::Flash::MinWriteSize ( ) const
inline

获取最小可写块大小(字节) / Returns the minimum writable block size in bytes.

Returns
最小可写块大小(字节) / size_t Minimum writable block size in bytes.

Definition at line 83 of file flash.hpp.

83{ return min_write_size_; }

◆ Read()

ErrorCode Flash::Read ( size_t offset,
RawData data )
virtual

从闪存中读取数据 / Reads data from the flash memory.

Parameters
offset数据读取的起始偏移地址 / The starting offset to read data.
data存储读取数据的缓冲区 / Data buffer to store the read data.
Returns
返回操作结果的错误码 / ErrorCode indicating success or failure.

Definition at line 14 of file flash.cpp.

15{
16 ASSERT(offset + data.size_ <= flash_area_.size_);
18 reinterpret_cast<const uint8_t*>(flash_area_.addr_) + offset,
19 data.size_);
20
21 return ErrorCode::OK;
22}
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
@ OK
操作成功 / Operation successful

◆ Size()

size_t LibXR::Flash::Size ( ) const
inline

获取闪存存储区域的大小 / Returns the size of the flash memory area.

Returns
闪存存储区域的大小 / size_t Size of the flash memory area.

Definition at line 90 of file flash.hpp.

90{ return flash_area_.size_; }

◆ Write()

virtual ErrorCode LibXR::Flash::Write ( size_t offset,
ConstRawData data )
pure virtual

向闪存写入数据 / Writes data to the flash memory.

Parameters
offset数据写入的起始偏移地址 / The starting offset to write data.
data需要写入的数据 / The data to be written.
Returns
返回操作结果的错误码 / ErrorCode indicating success or failure.

Implemented in LibXR::CH32Flash, LibXR::LinuxBinaryFileFlash< FLASH_SIZE >, and LibXR::STM32Flash.


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