Dawn Framework 1.0
Universal data acquisition framework for embedded systems
pulsecount.hxx
1// dawn/include/dawn/io/pulsecount.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/io/common.hxx"
9#include "dawn/porting/config.hxx"
10#include "dawn/porting/pulsecount.hxx"
11
12namespace dawn
13{
22{
23public:
24 enum
25 {
30 };
31
32 explicit CIOPulseCount(CDescObject &desc)
33 : CIOCommon(desc)
34 , path()
35 , fd(-1)
36 , highNs(CONFIG_DAWN_IO_PULSECOUNT_DEFAULT_HIGH_NS)
37 , lowNs(CONFIG_DAWN_IO_PULSECOUNT_DEFAULT_LOW_NS)
38 , lastCount(0)
39 {
40 }
41
42 ~CIOPulseCount() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "pulsecount";
48 }
49#endif
50
51 int configure() override;
52 int init() override;
53 int deinit() override;
54 int setDataImpl(IODataCmn &data) override;
55 size_t getDataSize() const override;
56 size_t getDataDim() const override;
57
58 bool isRead() const override
59 {
60 return false;
61 };
62
63 bool isWrite() const override
64 {
65 return true;
66 };
67
68 bool isNotify() const override
69 {
70 return false;
71 };
72
73 bool isBatch() const override
74 {
75 return false;
76 };
77
79
80 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
81 {
82 return ObjectIdHelper::create(ts, inst);
83 }
84
85 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
86 {
89 }
90
91 constexpr static SObjectCfg::ObjectCfgId cfgIdHighNs(bool rw = false)
92 {
93 return CIOPulseCount::cfgId(rw, SObjectId::DTYPE_UINT32, 1, IO_PULSECOUNT_CFG_HIGH_NS);
94 }
95
96 constexpr static SObjectCfg::ObjectCfgId cfgIdLowNs(bool rw = false)
97 {
98 return CIOPulseCount::cfgId(rw, SObjectId::DTYPE_UINT32, 1, IO_PULSECOUNT_CFG_LOW_NS);
99 }
100
101protected:
102 int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len) override;
103
104private:
105 char path[PATH_MAX];
106 int fd;
107 uint32_t highNs;
108 uint32_t lowNs;
109 uint32_t lastCount;
110#ifdef CONFIG_DAWN_IO_TIMESTAMP
111 uint64_t ts;
112#endif
113
114 int configureDesc(const CDescObject &desc);
115 int validateTimings(uint32_t high, uint32_t low) const;
116 int writeCurrentConfig(uint32_t count);
117};
118} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:255
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:265
Base class for all I/O objects.
Definition common.hxx:27
@ IO_CLASS_PULSECOUNT
Finite pulse-train output.
Definition common.hxx:181
Finite pulse-train output backed by the NuttX PULSECOUNT driver.
size_t getDataDim() const
Get data vector dimension.
@ IO_PULSECOUNT_CFG_HIGH_NS
Pulse high time in nanoseconds.
@ IO_PULSECOUNT_CFG_LOW_NS
Pulse low time in nanoseconds.
@ IO_PULSECOUNT_CFG_FIRST
First config ID (reserved).
@ IO_PULSECOUNT_CFG_LAST
Last config ID marker (reserved).
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
int init()
One-time initialize object after bindings are resolved.
bool isNotify() const
Check if IO supports notifications.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
bool isRead() const
Check if IO supports read operations.
bool isBatch() const
Check if IO supports batch operations.
size_t getDataSize() const
Get data size in bytes.
int configure()
Configure object from descriptor data.
bool isWrite() const
Check if IO supports write operations.
int deinit()
De-initialize object.
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
@ 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