6#include "dawn/io/adc_base.hxx"
16CIOAdcBase::~CIOAdcBase()
21int CIOAdcBase::configureCommonDesc(
const CDescObject &desc)
26 for (
size_t i = 0; i < desc.
getSize(); i++)
32 DAWNERR(
"Unsupported ADC config 0x%08" PRIx32
"\n", item->
cfgid.
v);
42int CIOAdcBase::configureDevice()
48 DAWNERR(
"ADC device number not configured\n");
52 std::snprintf(path,
sizeof(path), ADC_PATH_FMT,
getCmnDevno());
57 DAWNERR(
"failed to open ADC device %d\n", -fd);
61 ret = adc_get_nchans(fd);
66 DAWNERR(
"invalid number of channels %d\n", ret);
67 return ret < 0 ? ret : -EIO;
70 chans =
static_cast<uint8_t
>(ret);
78 ret = configureCommonDesc(
getDesc());
81 DAWNERR(
"ADC configure failed (error %d)\n", ret);
85 return configureDevice();
92 DAWNERR(
"ADC requires DTYPE_INT32\n");
122int CIOAdcBase::ensureReadBuffer(
size_t samples)
136 if (rdata !=
nullptr && batch >= samples)
154int CIOAdcBase::readSamples(
IODataCmn &data,
size_t len)
156 size_t bytesPerBatch;
173 expected = len * bytesPerBatch;
178 dst =
static_cast<uint8_t *
>(data.
getDataPtr());
182 ret = ensureReadBuffer(len);
188 dst =
reinterpret_cast<uint8_t *
>(rdata);
191 while (total < expected)
205 total +=
static_cast<size_t>(ret);
210 for (
size_t i = 0; i < len; i++)
212 std::memcpy(data.
getDataPtr(i), &rdata[i * chans], bytesPerBatch);
214#ifdef CONFIG_DAWN_IO_TIMESTAMP
219#ifdef CONFIG_DAWN_IO_TIMESTAMP
222 for (
size_t i = 0; i < len; i++)
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 init()
One-time initialize object after bindings are resolved.
int deinit()
De-initialize object.
size_t getDataDim() const
Get data vector dimension.
int configure()
Configure object from descriptor data.
size_t getDataSize() const
Get data size in bytes.
uint64_t getTimestamp()
Get current timestamp.
bool isTimestamp() const
Check if I/O supports timestamp.
int getCmnDevno() const
Get device number for this I/O.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
@ IO_CLASS_ANY
Any I/O class.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
Out-of-tree user-extension hooks for Dawn.
Base interface for I/O data buffers (static and dynamic).
virtual bool hasTimestamp()=0
Check if this data buffer has per-batch timestamp storage.
virtual size_t getItems()=0
Get number of items per batch.
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.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.