libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
layout.hpp
1
10enum class BlockType : uint8_t
11{
12 MAIN = 0,
13 BACKUP = 1
14};
15
16LIBXR_PACKED_BEGIN
22template <size_t BlockSize>
24{
25 uint8_t data[BlockSize];
26};
27LIBXR_PACKED_END
28
34template <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
106{
110
111 uint32_t raw_info =
112 0;
114
125
130 void SetNameLength(uint8_t len)
131 {
132 raw_info = (raw_info & 0x01FFFFFF) | ((len & 0x7F) << 25);
133 }
134
139 uint8_t GetNameLength() const { return (raw_info >> 25) & 0x7F; }
140
145 void SetDataSize(uint32_t size)
146 {
147 raw_info = (raw_info & 0xFE000000) | (size & 0x01FFFFFF);
148 }
149
154 uint32_t GetDataSize() const { return raw_info & 0x01FFFFFF; }
155};
156LIBXR_PACKED_END
157
158LIBXR_PACKED_BEGIN
164{
170 {
171 header = 0xFFFFFFFF;
172 Memory::FastSet(padding, 0xFF, MinWriteSize);
173 }
174
180 union
181 {
182 uint32_t header;
183 uint8_t padding[MinWriteSize];
185 };
188};
189LIBXR_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:164
uint8_t padding[MinWriteSize]
Definition layout.hpp:183
KeyInfo key
Definition layout.hpp:186
FlashInfo()
构造一个擦除态 FlashInfo 缓冲对象 (Construct one erased-state FlashInfo buffer object).
Definition layout.hpp:169
uint32_t header
Flash 块头签名 / Flash block-header signature.
Definition layout.hpp:182
键信息结构,存储键的元数据 (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:154
uint32_t raw_info
Definition layout.hpp:111
void SetNameLength(uint8_t len)
设置键名长度 (Set the key name length).
Definition layout.hpp:130
BlockBoolData< MinWriteSize > no_next_key
是否是最后一个键
Definition layout.hpp:107
void SetDataSize(uint32_t size)
设置数据字节数 (Set the payload size in bytes).
Definition layout.hpp:145
KeyInfo()
构造一个默认可写的键头元数据 (Construct one default writable key-header metadata object).
Definition layout.hpp:119
uint8_t GetNameLength() const
获取键名长度 (Get the key name length).
Definition layout.hpp:139