Dawn Framework 1.0
Universal data acquisition framework for embedded systems
timestamp.cxx
1// dawn/src/io/timestamp.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/timestamp.hxx"
7
8using namespace dawn;
9
10int CIOTimestamp::configureDesc(const CDescObject &desc)
11{
12 const SObjectCfg::SObjectCfgItem *item = nullptr;
13 size_t offset = 0;
14 size_t i = 0;
15
16 for (i = 0; i < desc.getSize(); i++)
17 {
18 item = desc.objectCfgItemAtOffset(offset);
19
21 {
22 offset += cfgCmnOffset(item);
23 continue;
24 }
25
27 {
28 DAWNERR("unsupported timestamp cfg 0x08%" PRIx32 "\n", item->cfgid.v);
29 return -EINVAL;
30 }
31
32 switch (item->cfgid.s.id)
33 {
34 case CIOTimestamp::IO_TIMESTAMP_CFG_INTERVAL:
35 {
36 const uint32_t *tmp = &item->data[0];
37
38 timfd_interval(*tmp);
39 offset += 1 + item->cfgid.s.size;
40 break;
41 }
42
43 default:
44 {
45 DAWNERR("unsupported timestamp objectCfg 0x%" PRIx32 "\n", item->cfgid.v);
46 DAWNERR("Unsupported timestamp source type\n");
47 return -EINVAL;
48 }
49 }
50 }
51
52 return OK;
53}
54
55CIOTimestamp::~CIOTimestamp()
56{
57 deinit();
58}
59
61{
62 int ret;
63
64 // Configure
65
66 ret = configureDesc(getDesc());
67 if (ret != OK)
68 {
69 return ret;
70 }
71
72 return timfd_init();
73}
74
76{
77 // Stop IO
78
79 stop();
80
81 return OK;
82}
83
85{
86 for (size_t i = 0; i < len; i++)
87 {
88 uint64_t ts = getTimestamp();
89 std::memcpy(data.getDataPtr(i), &ts, tlen);
90
91#ifdef CONFIG_DAWN_IO_TIMESTAMP
92 // This is here only to be consistent across IO implementations
93
94 if (isTimestamp())
95 {
96 data.getTs() = ts;
97 }
98#endif
99 }
100
101 // Clear notification event from fd
102
103 timfd_ack();
104
105 return OK;
106}
107
108#ifdef CONFIG_DAWN_IO_NOTIFY
109int CIOTimestamp::getFd() const
110{
111 return timfd_fd();
112};
113#endif
114
116{
117 return timfd_start();
118}
119
121{
122 return timfd_stop();
123}
124
126{
127 // Data size
128
129 return tlen;
130}
131
133{
134 // Data dimmention
135
136 return 1;
137}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:425
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
@ IO_CLASS_TIMESTAMP
Timestamp generator.
Definition common.hxx:103
int deinit()
De-initialize object.
Definition timestamp.cxx:75
size_t getDataSize() const
Get data size in bytes.
int doStart()
Start implementation hook.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition timestamp.cxx:84
int configure()
Configure object from descriptor data.
Definition timestamp.cxx:60
int doStop()
Stop implementation hook.
size_t getDataDim() const
Get data vector dimension.
int stop()
Stop object.
Definition object.hxx:145
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
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
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
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 size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.