Dawn Framework 1.0
Universal data acquisition framework for embedded systems
descriptor.hxx
1// dawn/include/dawn/common/descriptor.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <functional>
9#include <vector>
10
11#include "dawn/common/descobject.hxx"
12#include "dawn/common/handler.hxx"
13#include "dawn/common/object.hxx"
14#include "dawn/porting/config.hxx"
15
16namespace dawn
17{
21{
22public:
25 constexpr static uint32_t DAWN_DESCRIPTOR_HDR = 0x0d0a0302;
26
29 constexpr static uint32_t DAWN_DESCRIPTOR_FOOT = 0x02030a0d;
30
33 struct
34 {
35 uint32_t magic; // Header magic (0x0d0a0302)
36 uint32_t size : 16; // Number of objects
37 uint32_t _reserved : 16; // Reserved
38 } typedef SDescriptorBinHdr;
39
42 struct
43 {
44 uint32_t magic; // Footer magic (0x02030a0d)
45 uint32_t sum; // CRC32 checksum
46 } typedef SDescriptorBinFtr;
47
50 struct
51 {
52 SDescriptorBinHdr hdr; // Header (8 bytes)
53 SObjectCfg::SObjectCfgData objects; // Objects
54 } typedef SDescriptorBin;
55
58 enum
59 {
60 DESC_CFG_FIRST = 0,
61 DESC_CFG_VERSION = 1,
62 DESC_CFG_STRING = 2,
63 DESC_CFG_NO_IDLE_QUIT = 3,
64 DESC_CFG_LAST = 31
65 };
66
76 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
77 {
79 }
80
91 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
92 {
93 return SObjectCfg::objectCfg(SObjectId::OBJTYPE_ANY, 0, dtype, rw, size, id);
94 }
95
103 constexpr static SObjectCfg::ObjectCfgId cfgIdVersion(bool rw = false)
104 {
105 return CDescriptor::cfgId(rw, SObjectId::DTYPE_UINT32, 1, DESC_CFG_VERSION);
106 }
107
116 constexpr static SObjectCfg::ObjectCfgId cfgIdString(uint16_t size, bool rw = false)
117 {
118 return CDescriptor::cfgId(rw, SObjectId::DTYPE_CHAR, size, DESC_CFG_STRING);
119 }
120
121 constexpr static SObjectCfg::ObjectCfgId cfgIdNoIdleQuit()
122 {
123 return CDescriptor::cfgId(false, SObjectId::DTYPE_UINT8, 1, DESC_CFG_NO_IDLE_QUIT);
124 }
125
129 : bindesc(nullptr)
130 , bindescLen(0)
131 , noIdleQuit(false)
132 {
133 }
134
137 bool getNoIdleQuit() const
138 {
139 return noIdleQuit;
140 }
141
144 ~CDescriptor();
145
156 int loadBin(uint32_t *bin, size_t len, bool force_valid = false, bool dump = false);
157
164 void reset();
165
172 SDescriptorBin *getBin();
173
180 size_t getBinLen();
181
191 typedef std::function<void(CHandler &obj, CDescObject &desc)> allocobj_func_t;
192 void alloc_objects(CHandler &h, const allocobj_func_t &func);
193
202
211
219 static void binDump(const uint32_t *bin, size_t len);
220
229 static int binValid(const uint32_t *bin, size_t len);
230
239 static bool binCheckValid(const uint32_t *bin, size_t len);
240
249 static int binCheckFill(uint32_t *bin, size_t len);
250
251private:
252 SDescriptorBin *bindesc; // Pointer to loaded descriptor binary structure
253 std::vector<CDescObject *> vobjcfg; // Vector of CDescObject wrappers
254 size_t bindescLen; // Length of loaded descriptor in 32-bit words
255 bool noIdleQuit; // no quit from idle flag
256
259 void parseMeta();
260 size_t objectWords() const;
261 bool objectWordAt(size_t offset, uint32_t *value) const;
262};
263} // Namespace dawn
Descriptor wrapper for individual object configuration.
Binary device descriptor manager.
void reset()
Clear currently loaded descriptor state.
static uint32_t DAWN_DESCRIPTOR_FOOT
Footer magic number (0x02030a0d).
~CDescriptor()
Destructor - release loaded descriptor resources.
SObjectCfg::UObjectCfgId * objectCfgIdAtOffset(size_t offset)
Get configuration ID at offset.
static uint32_t DAWN_DESCRIPTOR_HDR
Header magic number (0x0d0a0302).
CDescriptor()
Constructor - initialize empty descriptor.
static SObjectCfg::ObjectCfgId cfgIdVersion(bool rw=false)
Create ConfigID for firmware version.
SObjectCfg::SObjectCfgData * objectCfgAtOffset(size_t offset)
Get object configuration at offset.
std::function< void(CHandler &obj, CDescObject &desc)> allocobj_func_t
Thread function callback storage.
bool getNoIdleQuit() const
Return true if the descriptor requests no idle quit.
static void binDump(const uint32_t *bin, size_t len)
Print descriptor contents to console (debug).
static SObjectCfg::ObjectCfgId cfgIdString(uint16_t size, bool rw=false)
Create ConfigID for device string.
static int binCheckFill(uint32_t *bin, size_t len)
Calculate and store descriptor CRC32 checksum.
int loadBin(uint32_t *bin, size_t len, bool force_valid=false, bool dump=false)
Load binary descriptor from memory.
static SObjectId::ObjectId objectId(uint16_t inst)
Construct 32-bit ObjectID from component fields.
size_t getBinLen()
Get loaded descriptor size in bytes.
static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
Create ConfigID for metadata.
static int binValid(const uint32_t *bin, size_t len)
Validate binary descriptor integrity.
static bool binCheckValid(const uint32_t *bin, size_t len)
Validate descriptor CRC32 checksum.
SDescriptorBin * getBin()
Get loaded descriptor binary structure.
Base implementation of IHandler interface.
Definition handler.hxx:110
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Binary descriptor footer structure.
Binary descriptor header structure.
Complete binary descriptor container.
Object configuration data container.
@ OBJTYPE_ANY
Wildcard/metadata object type.
Definition objectid.hxx:176
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
Definition objectid.hxx:80
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
Definition objectid.hxx:144
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290
32-bit encoded configuration identifier (union with bit field).
Definition objectcfg.hxx:79