Dawn Framework 1.0
Universal data acquisition framework for embedded systems
objectcfg.hxx
1// dawn/include/dawn/common/objectcfg.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/common/objectid.hxx"
9#include "dawn/debug.hxx"
10#include "dawn/porting/config.hxx"
11#include "dawn/porting/fixedmath.hxx"
12
13#include <cstring>
14#include <cstdio>
15
16namespace dawn
17{
37{
38public:
45 constexpr static size_t ID_MAX = 0b11111;
46 constexpr static size_t ID_SHIFT = 0;
47 constexpr static size_t _SIZE_MAX = 0b1111111111;
48 constexpr static size_t SIZE_SHIFT = 5;
49 constexpr static size_t RW_MAX = 0b1;
50 constexpr static size_t RW_SHIFT = 15;
51 constexpr static size_t DTYPE_MAX = 0b1111;
52 constexpr static size_t DTYPE_SHIFT = 16;
53 constexpr static size_t CLS_MAX = 0b111111111;
54 constexpr static size_t CLS_SHIFT = 21;
55 constexpr static size_t TYPE_MAX = 0b11;
56 constexpr static size_t TYPE_SHIFT = 30;
57
60 typedef uint32_t ObjectCfgId;
61
69 typedef uint32_t ObjectCfgData_t;
70
78 union
79 {
83
86 struct
87 {
94 uint32_t id : 5;
95
102 uint32_t size : 10;
103
112 uint32_t rw : 1;
113
120 uint32_t dtype : 4;
121
128 uint32_t ext : 1;
129
136 uint32_t cls : 9;
137
144 uint32_t type : 2;
145 } s;
146 } typedef UObjectCfgId;
147
154 struct
155 {
159
167 } typedef SObjectCfgItem;
168
175 struct
176 {
180
183 uint32_t size;
184
192 } typedef SObjectCfgData;
193
208 constexpr static ObjectCfgId objectCfg(uint8_t type,
209 uint16_t cls,
210 uint8_t dtype,
211 bool rw,
212 uint16_t size,
213 uint8_t id)
214 {
215 DEBUGASSERT(type <= TYPE_MAX);
216 DEBUGASSERT(cls <= CLS_MAX);
217 DEBUGASSERT(dtype <= DTYPE_MAX);
218 DEBUGASSERT(size <= _SIZE_MAX);
219 DEBUGASSERT(id <= ID_MAX);
220
221 return (((type & TYPE_MAX) << TYPE_SHIFT) | ((cls & CLS_MAX) << CLS_SHIFT) |
222 ((dtype & DTYPE_MAX) << DTYPE_SHIFT) | ((id & ID_MAX) << ID_SHIFT) |
223 ((size & _SIZE_MAX) << SIZE_SHIFT) | ((rw & RW_MAX) << RW_SHIFT));
224 }
225
233 constexpr static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
234 {
235 return ((objcfg >> ID_SHIFT) & ID_MAX);
236 }
237
245 constexpr static uint16_t objectCfgGetSize(const ObjectCfgId objcfg)
246 {
247 return ((objcfg >> SIZE_SHIFT) & _SIZE_MAX);
248 }
249
257 constexpr static bool objectCfgGetRw(const ObjectCfgId objcfg)
258 {
259 return ((objcfg >> RW_SHIFT) & RW_MAX);
260 }
261
269 constexpr static uint8_t objectCfgGetDtype(const ObjectCfgId objcfg)
270 {
271 return ((objcfg >> DTYPE_SHIFT) & DTYPE_MAX);
272 }
273
281 constexpr static uint16_t objectCfgGetCls(const ObjectCfgId objcfg)
282 {
283 return ((objcfg >> CLS_SHIFT) & CLS_MAX);
284 }
285
293 constexpr static uint8_t objectCfgGetType(const ObjectCfgId objcfg)
294 {
295 return ((objcfg >> TYPE_SHIFT) & TYPE_MAX);
296 }
297
307 static ObjectCfgData_t u32ToCfg(uint32_t x)
308 {
309 return x;
310 }
311
319 static ObjectCfgData_t i32ToCfg(int32_t x)
320 {
322
323 std::memcpy(&y, &x, sizeof(y));
324 return y;
325 }
326
334 static ObjectCfgData_t fToCfg(float x)
335 {
337
338 std::memcpy(&y, &x, sizeof(y));
339 return y;
340 }
341
349 static uint32_t b16ToCfg(b16_t x)
350 {
352
353 std::memcpy(&y, &x, sizeof(y));
354 return y;
355 }
356
365 {
366 b16_t y = ftob16(x);
367 return b16ToCfg(y);
368 }
369
377 static uint32_t cfgToU32(ObjectCfgData_t x)
378 {
379 return x;
380 }
381
389 static int32_t cfgtoi32(ObjectCfgData_t x)
390 {
391 int32_t y;
392
393 std::memcpy(&y, &x, sizeof(y));
394 return y;
395 }
396
404 static float cfgToF(ObjectCfgData_t x)
405 {
406 float y;
407
408 std::memcpy(&y, &x, sizeof(y));
409 return y;
410 }
411
419 static b16_t cfgToB16(ObjectCfgData_t x)
420 {
421 b16_t y;
422
423 std::memcpy(&y, &x, sizeof(y));
424 return y;
425 }
426
440 static SObjectCfgItem *objectAtOffset(const SObjectCfgData &cfg, size_t offset)
441 {
442 return reinterpret_cast<SObjectCfgItem *>(
443 reinterpret_cast<uint32_t *>(const_cast<SObjectCfgData *>(&cfg)) + offset);
444 }
445
454 static SObjectCfgItem *objectCfgFromCfgId(const SObjectCfgData &cfg, ObjectCfgId id);
455
463 static size_t getSizeBytes(const SObjectCfgData &cfg);
464};
465} // Namespace dawn
Configuration management for Dawn objects.
Definition objectcfg.hxx:37
static SObjectCfgItem * objectAtOffset(const SObjectCfgData &cfg, size_t offset)
Get item from offset.
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
uint32_t ObjectCfgData_t
Configuration data element - single 32-bit word.
Definition objectcfg.hxx:69
static uint16_t objectCfgGetCls(const ObjectCfgId objcfg)
Extract object class from ConfigID.
static float cfgToF(ObjectCfgData_t x)
Convert ObjectCfgData_t to float.
static uint16_t objectCfgGetSize(const ObjectCfgId objcfg)
Extract configuration data size from ConfigID.
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
static ObjectCfgData_t i32ToCfg(int32_t x)
Convert int32_t to ObjectCfgData_t.
static ObjectCfgData_t fToCfg(float x)
Convert float to ObjectCfgData_t.
static uint32_t cfgToU32(ObjectCfgData_t x)
Convert ObjectCfgData_t to uint32_t.
static uint8_t objectCfgGetType(const ObjectCfgId objcfg)
Extract object type from ConfigID.
static uint32_t b16ToCfg(b16_t x)
Convert b16_t to uint32_t.
static size_t ID_MAX
Configuration ID field constants and bit shift positions.
Definition objectcfg.hxx:45
static ObjectCfgData_t u32ToCfg(uint32_t x)
Helper conversion functions: data types to cfg data type.
static uint8_t objectCfgGetDtype(const ObjectCfgId objcfg)
Extract data type from ConfigID.
static b16_t cfgToB16(ObjectCfgData_t x)
Convert ObjectCfgData_t to b16_t.
static SObjectCfgItem * objectCfgFromCfgId(const SObjectCfgData &cfg, ObjectCfgId id)
Get item from configuration ID.
Definition objectcfg.cxx:12
static int32_t cfgtoi32(ObjectCfgData_t x)
Convert ObjectCfgData_t to int32_t.
static size_t getSizeBytes(const SObjectCfgData &cfg)
Get total size in bytes for this object definition.
Definition objectcfg.cxx:38
static bool objectCfgGetRw(const ObjectCfgId objcfg)
Extract read-write access flag from ConfigID.
static ObjectCfgData_t fToB16ToCfg(float x)
Convert float to b16_t and then to ObjectCfgData_t.
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Object configuration data container.
SObjectId::UObjectId objid
Object identifier (type, class, dtype, instance).
SObjectCfgItem items
First configuration item (array continues in memory).
uint32_t size
Number of configuration items for this object (0-32).
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
32-bit encoded configuration identifier (union with bit field).
Definition objectcfg.hxx:79
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
Definition objectcfg.hxx:94
uint32_t ext
Extension flag (bit 20).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
uint32_t dtype
Configuration data type (bits 16-19).
uint32_t type
Object type (bits 30-31).
uint32_t rw
Read-write access flag (bit 15).
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218