Dawn Framework 1.0
Universal data acquisition framework for embedded systems
dummy.hxx
1// dawn/include/dawn/io/dummy.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <mutex>
9
10#include "dawn/io/common.hxx"
11#include "dawn/porting/config.hxx"
12
13namespace dawn
14{
22class CIODummy : public CIOCommon
23{
24public:
25 enum
26 {
27 IO_DUMMY_CFG_FIRST = 0,
28 IO_DUMMY_CFG_INITVAL = 1,
29 IO_DUMMY_CFG_DIM = 2,
30 IO_DUMMY_CFG_LAST = 31
31 };
32
33 static_assert(IO_DUMMY_CFG_LAST - 1 <= SObjectCfg::ID_MAX);
34
35 explicit CIODummy(CDescObject &desc)
36 : CIOCommon(desc)
37 , cfgval(nullptr)
38 , val(nullptr)
39 , dlen(1)
40 , cfglen(1)
41 , tlen(getDtypeSize())
42#ifdef CONFIG_DAWN_IO_TIMESTAMP
43 , ts(0)
44#endif
45 {
46 }
47
48 ~CIODummy() override;
49
50#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
51 const char *getClassNameStr() const override
52 {
53 return "dummy";
54 }
55#endif
56
57 int configure() override;
58 int init() override;
59 int deinit() override;
60 int getDataImpl(IODataCmn &data, size_t len) override;
61 int setDataImpl(IODataCmn &data) override;
62
63#ifdef CONFIG_DAWN_IO_NOTIFY
64 int getFd() const override;
65#endif
66
67 size_t getDataSize() const override;
68 size_t getDataDim() const override;
69
70 bool isRead() const override
71 {
72 return true;
73 };
74
75 bool isWrite() const override
76 {
77 return true;
78 };
79
80 bool isNotify() const override
81 {
82 return false;
83 };
84
85 bool isBatch() const override
86 {
87 return false;
88 };
89
91
92 constexpr static SObjectId::ObjectId objectId(SObjectId::EObjectDataType dtype,
93 bool ts,
94 uint16_t inst)
95 {
96 return ObjectIdHelper::create(dtype, ts, inst);
97 }
98
99 constexpr static SObjectCfg::ObjectCfgId cfgIdInitval(uint8_t dtype, bool rw, uint8_t dim)
100 {
101 uint8_t words = dim;
102
103 if (dtype == SObjectId::DTYPE_UINT64 || dtype == SObjectId::DTYPE_INT64 ||
105 {
106 words = dim * 2;
107 }
108
110 SObjectId::OBJTYPE_IO, (CIOCommon::IO_CLASS_DUMMY), dtype, rw, words, IO_DUMMY_CFG_INITVAL);
111 }
112
113 constexpr static SObjectCfg::ObjectCfgId cfgIdDim()
114 {
118 false,
119 1,
120 IO_DUMMY_CFG_DIM);
121 }
122
123private:
124 const uint32_t *cfgval;
125 void *val;
126 std::mutex mutex;
127 size_t dlen;
128 size_t cfglen;
129 size_t tlen;
130
131#ifdef CONFIG_DAWN_IO_TIMESTAMP
132 uint64_t ts;
133#endif
134
135 int setVal(const void *v, size_t d);
136 int applyInitval();
137 int configureDesc(const CDescObject &desc);
138};
139} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:236
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:246
Base class for all I/O objects.
Definition common.hxx:27
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:425
@ IO_CLASS_DUMMY
Dummy I/O (for testing)
Definition common.hxx:99
Dummy I/O type for testing and simulation.
Definition dummy.hxx:23
int deinit()
De-initialize object.
Definition dummy.cxx:204
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition dummy.cxx:234
int init()
One-time initialize object after bindings are resolved.
Definition dummy.cxx:182
bool isBatch() const
Check if IO supports batch operations.
Definition dummy.hxx:85
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition dummy.cxx:215
size_t getDataSize() const
Get data size in bytes.
Definition dummy.cxx:246
int configure()
Configure object from descriptor data.
Definition dummy.cxx:173
bool isWrite() const
Check if IO supports write operations.
Definition dummy.hxx:75
bool isNotify() const
Check if IO supports notifications.
Definition dummy.hxx:80
size_t getDataDim() const
Get data vector dimension.
Definition dummy.cxx:251
bool isRead() const
Check if IO supports read operations.
Definition dummy.hxx:70
size_t getDtypeSize() const
Get size of this object's data type.
Definition object.cxx:195
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
static size_t ID_MAX
Configuration ID field constants and bit shift positions.
Definition objectcfg.hxx:45
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
EObjectDataType
Data types supported by Dawn framework.
Definition objectid.hxx:61
@ DTYPE_UINT64
Unsigned 64-bit integer.
Definition objectid.hxx:104
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
Definition objectid.hxx:120
@ DTYPE_INT64
Signed 64-bit integer.
Definition objectid.hxx:100
@ 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