Dawn Framework 1.0
Universal data acquisition framework for embedded systems
adc_stream.cxx
1// dawn/src/io/adc_stream.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/adc_stream.hxx"
7
8#include <cinttypes>
9
10using namespace dawn;
11
12int CIOAdcStream::configureDesc(const CDescObject &desc)
13{
14 const SObjectCfg::SObjectCfgItem *item = nullptr;
15 size_t offset = 0;
16
17 for (size_t i = 0; i < desc.getSize(); i++)
18 {
19 item = desc.objectCfgItemAtOffset(offset);
20
21 switch (item->cfgid.s.cls)
22 {
24 {
25 offset += cfgCmnOffset(item);
26 break;
27 }
28
30 {
31 switch (item->cfgid.s.id)
32 {
33 case IO_ADC_STREAM_CFG_BATCH_SIZE:
34 {
35 if (item->cfgid.s.size != 1)
36 {
37 DAWNERR("invalid adc_stream batch cfg size %d\n", item->cfgid.s.size);
38 return -EINVAL;
39 }
40
41 batchSize = *reinterpret_cast<const uint32_t *>(&item->data);
42 if (batchSize == 0)
43 {
44 DAWNERR("adc_stream batch size must be > 0\n");
45 return -EINVAL;
46 }
47
48 offset += 2;
49 break;
50 }
51
52 default:
53 {
54 DAWNERR("unsupported adc_stream cfg 0x%08" PRIx32 "\n", item->cfgid.v);
55 return -EINVAL;
56 }
57 }
58 break;
59 }
60
61 default:
62 {
63 DAWNERR("unsupported adc_stream cfg 0x%08" PRIx32 "\n", item->cfgid.v);
64 return -EINVAL;
65 }
66 }
67 }
68
69 return OK;
70}
71
73{
74 int ret;
75
76 ret = configureDesc(getDesc());
77 if (ret != OK)
78 {
79 DAWNERR("adc_stream configure failed (error %d)\n", ret);
80 return ret;
81 }
82
83 ret = configureDevice();
84 if (ret != OK)
85 {
86 return ret;
87 }
88
89 return ensureReadBuffer(batchSize);
90}
91
93{
94 if (len == 0)
95 {
96 return -EINVAL;
97 }
98
99 if (len > batchSize)
100 {
101 return -EINVAL;
102 }
103
104 return readSamples(data, len);
105}
106
108{
109 return adc_start(getFdInternal());
110}
111
113{
114 return adc_stop(getFdInternal());
115}
116
117int CIOAdcStream::trigger(uint8_t cmd)
118{
119 UNUSED(cmd);
120 return adc_start(getFdInternal());
121}
122
123int CIOAdcStream::onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
124{
125 int ret;
126
127 if (SObjectCfg::objectCfgGetId(objcfg) != IO_ADC_STREAM_CFG_BATCH_SIZE)
128 {
129 return OK;
130 }
131
132 if (len != 1 || data[0] == 0)
133 {
134 return -EINVAL;
135 }
136
137 batchSize = data[0];
138 ret = ensureReadBuffer(batchSize);
139 if (ret < 0)
140 {
141 return ret;
142 }
143
144 return OK;
145}
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.
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
int doStart()
Start implementation hook.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
int configure()
Configure object from descriptor data.
int trigger(uint8_t cmd)
Execute a trigger command.
int doStop()
Stop implementation hook.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ADC_STREAM
ADC stream (batch/high-throughput)
Definition common.hxx:179
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
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
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.