libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
layout.hpp
1
10 enum class BlockType : uint8_t
11 {
12 MAIN = 0,
13 BACKUP = 1
14 };
15
16LIBXR_PACKED_BEGIN
22 template <size_t BlockSize>
24 {
25 uint8_t data[BlockSize];
26 };
27LIBXR_PACKED_END
28
34 template <size_t BlockSize>
36 {
37 public:
43 static void SetFlag(BlockBoolData<BlockSize>& obj, bool value)
44 {
45 Memory::FastSet(obj.data, 0xFF, BlockSize);
46 if (!value)
47 {
48 obj.data[BlockSize - 1] &= 0xF0;
49 }
50 }
51
57 static bool ReadFlag(const BlockBoolData<BlockSize>& obj)
58 {
59 uint8_t last_4bits = obj.data[BlockSize - 1] & 0x0F;
60 return last_4bits == 0x0F;
61 }
62
69 static bool Valid(const BlockBoolData<BlockSize>& obj)
70 {
71 if (BlockSize == 0)
72 {
73 return false;
74 }
75
76 for (size_t i = 0; i < BlockSize - 1; ++i)
77 {
78 if (obj.data[i] != 0xFF)
79 {
80 return false;
81 }
82 }
83
84 uint8_t last_byte = obj.data[BlockSize - 1];
85 if ((last_byte & 0xF0) != 0xF0)
86 {
87 return false;
88 }
89
90 uint8_t last_4bits = last_byte & 0x0F;
91 if (!(last_4bits == 0x0F || last_4bits == 0x00))
92 {
93 return false;
94 }
95
96 return true;
97 }
98 };
99
100LIBXR_PACKED_BEGIN
105 struct KeyInfo
106 {
110
111 uint32_t raw_info = 0;
113
124
129 void SetNameLength(uint8_t len)
130 {
131 raw_info = (raw_info & 0x01FFFFFF) | ((len & 0x7F) << 25);
132 }
133
138 uint8_t GetNameLength() const { return (raw_info >> 25) & 0x7F; }
139
144 void SetDataSize(uint32_t size)
145 {
146 raw_info = (raw_info & 0xFE000000) | (size & 0x01FFFFFF);
147 }
148
153 uint32_t GetDataSize() const { return raw_info & 0x01FFFFFF; }
154 };
155LIBXR_PACKED_END
156
157LIBXR_PACKED_BEGIN
163 {
169 {
170 header = 0xFFFFFFFF;
171 Memory::FastSet(padding, 0xFF, MinWriteSize);
172 }
173
179 union
180 {
181 uint32_t header;
182 uint8_t padding[MinWriteSize];
183 };
185 };
186LIBXR_PACKED_END
读写对齐布尔位图块的工具 (Helpers for reading and writing aligned boolean flag blocks).
Definition layout.hpp:36
static bool Valid(const BlockBoolData< BlockSize > &obj)
检查位图块内容是否仍是合法编码 (Check whether a flag block still contains a valid encoding).
Definition layout.hpp:69
static void SetFlag(BlockBoolData< BlockSize > &obj, bool value)
把一个布尔值编码进位图块 (Encode one boolean value into a flag block).
Definition layout.hpp:43
static bool ReadFlag(const BlockBoolData< BlockSize > &obj)
从位图块读取布尔值 (Decode one boolean value from a flag block).
Definition layout.hpp:57
按最小写入单元存放布尔位图块 (Boolean flag block stored in one aligned write unit span).
Definition layout.hpp:24
Flash 存储的块信息结构 (Structure representing a Flash storage block).
Definition layout.hpp:163
uint8_t padding[MinWriteSize]
按最小写入单元对齐的原始块前缀 / Raw block prefix aligned to one minimum write unit.
Definition layout.hpp:182
KeyInfo key
紧跟在块头后的首个键头 / First key header stored right after the block header.
Definition layout.hpp:184
FlashInfo()
构造一个擦除态 FlashInfo 缓冲对象 (Construct one erased-state FlashInfo buffer object).
Definition layout.hpp:168
uint32_t header
Flash 块头签名 / Flash block-header signature.
Definition layout.hpp:181
键信息结构,存储键的元数据 (Structure containing key metadata).
Definition layout.hpp:106
BlockBoolData< MinWriteSize > uninit
该键是否未初始化
Definition layout.hpp:109
BlockBoolData< MinWriteSize > available_flag
该键是否有效
Definition layout.hpp:108
uint32_t GetDataSize() const
获取数据字节数 (Get the payload size in bytes).
Definition layout.hpp:153
uint32_t raw_info
Definition layout.hpp:111
void SetNameLength(uint8_t len)
设置键名长度 (Set the key name length).
Definition layout.hpp:129
BlockBoolData< MinWriteSize > no_next_key
是否是最后一个键
Definition layout.hpp:107
void SetDataSize(uint32_t size)
设置数据字节数 (Set the payload size in bytes).
Definition layout.hpp:144
KeyInfo()
构造一个默认可写的键头元数据 (Construct one default writable key-header metadata object).
Definition layout.hpp:118
uint8_t GetNameLength() const
获取键名长度 (Get the key name length).
Definition layout.hpp:138