Dawn Framework 1.0
Universal data acquisition framework for embedded systems
rand.hxx
1// dawn/include/dawn/io/rand.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{
23 : public CIOCommon
24 , public CIOTimerfd
25{
26public:
27 enum
28 {
29 IO_RAND_CFG_FIRST = 0,
31 IO_RAND_CFG_LAST = 31
32 };
33
34 explicit CIORand(CDescObject &desc)
35 : CIOCommon(desc)
36 , fd(-1)
37 , tlen(getDtypeSize())
38 , val(nullptr)
39 {
40 }
41
42 ~CIORand() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "rand";
48 }
49#endif
50
51 int doStart() override;
52 int doStop() override;
53 int configure() override;
54 int deinit() override;
55 int getDataImpl(IODataCmn &data, size_t len) override;
56
57#ifdef CONFIG_DAWN_IO_NOTIFY
58 int getFd() const override;
59#endif
60
61 size_t getDataSize() const override;
62 size_t getDataDim() const override;
63
64 bool isRead() const override
65 {
66 return true;
67 };
68
69 bool isWrite() const override
70 {
71 return false;
72 };
73
74 bool isNotify() const override
75 {
76 return true;
77 };
78
79 bool isBatch() const override
80 {
81 return false;
82 };
83
85
86 constexpr static SObjectId::ObjectId objectId(SObjectId::EObjectDataType dtype,
87 bool ts,
88 uint16_t inst)
89 {
90 return ObjectIdHelper::create(dtype, ts, inst);
91 }
92
93 constexpr static SObjectCfg::ObjectCfgId cfgInterval(bool rw)
94 {
98 rw,
99 1,
101 }
102
103private:
104 int fd;
105 size_t tlen;
106 void *val;
107
108 int configureDesc(const CDescObject &desc);
109};
110} // 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_RAND
Random number generator.
Definition common.hxx:104
Random number generator I/O type.
Definition rand.hxx:25
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition rand.cxx:122
@ IO_RAND_CFG_INTERVAL
Interval configuration in microseconds.
Definition rand.hxx:30
bool isBatch() const
Check if IO supports batch operations.
Definition rand.hxx:79
bool isRead() const
Check if IO supports read operations.
Definition rand.hxx:64
bool isWrite() const
Check if IO supports write operations.
Definition rand.hxx:69
size_t getDataSize() const
Get data size in bytes.
Definition rand.cxx:168
int configure()
Configure object from descriptor data.
Definition rand.cxx:77
size_t getDataDim() const
Get data vector dimension.
Definition rand.cxx:175
int doStart()
Start implementation hook.
Definition rand.cxx:158
int doStop()
Stop implementation hook.
Definition rand.cxx:163
bool isNotify() const
Check if IO supports notifications.
Definition rand.hxx:74
int deinit()
De-initialize object.
Definition rand.cxx:106
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
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
EObjectDataType
Data types supported by Dawn framework.
Definition objectid.hxx:61
@ 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