libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
ch32_flash.hpp
1#pragma once
2
3#include <cstdint>
4#include <cstring>
5
6#include "flash.hpp"
7#include "libxr_def.hpp"
8#include "libxr_type.hpp"
9#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
10
11namespace LibXR
12{
13
20class CH32Flash : public Flash
21{
22 public:
28 static constexpr size_t MIN_WRITE_SIZE = 2;
29
38 CH32Flash(const FlashRegion* regions, size_t region_count, uint32_t start_address);
39
46 CH32Flash(const FlashRegion* regions, size_t region_count);
47
48 ErrorCode Erase(size_t offset, size_t size) override;
49 ErrorCode Write(size_t offset, ConstRawData data) override;
50
51 static constexpr size_t MinWriteSize()
52 {
53 return MIN_WRITE_SIZE;
54 }
55
56 static constexpr uint32_t PageSize()
57 {
58 return 256;
59 }
60
61 private:
62 const FlashRegion* regions_;
63 uint32_t base_address_;
64 size_t region_count_;
65
66 bool IsInRange(uint32_t addr, size_t size) const;
67 static inline void ClearFlashFlagsOnce();
68};
69
70} // namespace LibXR
CH32 闪存驱动实现 / CH32 flash driver implementation.
CH32Flash(const FlashRegion *regions, size_t region_count, uint32_t start_address)
构造闪存对象 / Construct flash object
static constexpr size_t MinWriteSize()
最小写入粒度(半字) / Minimum write size (half-word)
static constexpr size_t MIN_WRITE_SIZE
最小写入单位(字节,半字编程);可直接作为 DatabaseRaw 的模板参数 / Minimum write unit in bytes (half-word programming); usable...
static constexpr uint32_t PageSize()
快速擦除页大小 / Page erase size in fast erase mode
ErrorCode Erase(size_t offset, size_t size) override
擦除闪存的指定区域 / Erases a section of the flash memory.
ErrorCode Write(size_t offset, ConstRawData data) override
向闪存写入数据 / Writes data to the flash memory.
只读原始数据视图 / Immutable raw data view
抽象基类,表示闪存接口。 Abstract base class representing a flash memory interface.
Definition flash.hpp:32
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
一段连续、大小相同的扇区 / A run of contiguous sectors of equal size
Definition flash.hpp:20