Dawn Framework 1.0
Universal data acquisition framework for embedded systems
dummy_notify.hxx
1// dawn/include/dawn/io/dummy_notify.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/io/timerfd.hxx"
12#include "dawn/porting/config.hxx"
13
14namespace dawn
15{
25 : public CIOCommon
26 , public CIOTimerfd
27{
28public:
29 enum
30 {
31 IO_DUMMY_NOTIFY_CFG_FIRST = 0,
32 IO_DUMMY_NOTIFY_CFG_INITVAL = 1,
33 IO_DUMMY_NOTIFY_CFG_INTERVAL = 2,
34 IO_DUMMY_NOTIFY_CFG_DIM = 3,
35 IO_DUMMY_NOTIFY_CFG_NOTIFY_ON_WRITE = 4,
36 IO_DUMMY_NOTIFY_CFG_LAST = 31
37 };
38
39 static_assert(IO_DUMMY_NOTIFY_CFG_LAST - 1 <= SObjectCfg::ID_MAX);
40
41 explicit CIODummyNotify(CDescObject &desc)
42 : CIOCommon(desc)
43 , cfgval(nullptr)
44 , val(nullptr)
45 , writeData(nullptr)
46 , notifyOnWrite(false)
47 , dlen(1)
48 , cfglen(1)
49 , tlen(getDtypeSize())
50#ifdef CONFIG_DAWN_IO_TIMESTAMP
51 , ts(0)
52#endif
53 {
54 }
55
56 ~CIODummyNotify() override;
57
58#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
59 const char *getClassNameStr() const override
60 {
61 return "dummy_notify";
62 }
63#endif
64
65 int doStart() override;
66 int doStop() override;
67 int configure() override;
68 int init() override;
69 int deinit() override;
70 int getDataImpl(IODataCmn &data, size_t len) override;
71 int setDataImpl(IODataCmn &data) override;
72
73#ifdef CONFIG_DAWN_IO_NOTIFY
74 int getFd() const override;
75 int notify();
76#endif
77
78 size_t getDataSize() const override;
79 size_t getDataDim() const override;
80
81 bool isRead() const override
82 {
83 return true;
84 };
85
86 bool isWrite() const override
87 {
88 return true;
89 };
90
91 bool isNotify() const override
92 {
93#ifdef CONFIG_DAWN_IO_NOTIFY
94 return true;
95#else
96 return false;
97#endif
98 };
99
100 bool isBatch() const override
101 {
102 return false;
103 };
104
105 using ObjectIdHelper =
107
108 constexpr static SObjectId::ObjectId objectId(SObjectId::EObjectDataType dtype,
109 bool ts,
110 uint16_t inst)
111 {
112 return ObjectIdHelper::create(dtype, ts, inst);
113 }
114
115 constexpr static SObjectCfg::ObjectCfgId cfgIdInitval(uint8_t dtype, bool rw, uint8_t dim)
116 {
117 uint8_t words = dim;
118
119 if (dtype == SObjectId::DTYPE_UINT64 || dtype == SObjectId::DTYPE_INT64 ||
121 {
122 words = dim * 2;
123 }
124
127 dtype,
128 rw,
129 words,
130 IO_DUMMY_NOTIFY_CFG_INITVAL);
131 }
132
133 constexpr static SObjectCfg::ObjectCfgId cfgInterval(bool rw)
134 {
138 rw,
139 1,
140 IO_DUMMY_NOTIFY_CFG_INTERVAL);
141 }
142
143 constexpr static SObjectCfg::ObjectCfgId cfgIdDim()
144 {
148 false,
149 1,
150 IO_DUMMY_NOTIFY_CFG_DIM);
151 }
152
153 constexpr static SObjectCfg::ObjectCfgId cfgNotifyOnWrite(bool rw = false)
154 {
158 rw,
159 1,
160 IO_DUMMY_NOTIFY_CFG_NOTIFY_ON_WRITE);
161 }
162
163private:
164 const uint32_t *cfgval;
165 void *val;
166 io_ddata_t *writeData;
167 bool notifyOnWrite;
168 std::mutex mutex;
169 size_t dlen;
170 size_t cfglen;
171 size_t tlen;
172
173#ifdef CONFIG_DAWN_IO_TIMESTAMP
174 uint64_t ts;
175#endif
176
177 int configureDesc(const CDescObject &desc);
178 int setVal(const void *v, size_t d);
179 int applyInitval();
180};
181} // 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_NOTIFY
Timer-driven dummy IO.
Definition common.hxx:105
Timer-driven dummy I/O with notification support.
int init()
One-time initialize object after bindings are resolved.
bool isNotify() const
Check if IO supports notifications.
int deinit()
De-initialize object.
bool isWrite() const
Check if IO supports write operations.
int configure()
Configure object from descriptor data.
bool isBatch() const
Check if IO supports batch operations.
int doStart()
Start implementation hook.
size_t getDataSize() const
Get data size in bytes.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
bool isRead() const
Check if IO supports read operations.
int doStop()
Stop implementation hook.
size_t getDataDim() const
Get data vector dimension.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Internal helper for timer-based I/O notifications.
Definition timerfd.hxx:22
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