6#include "dawn/io/pulsecount.hxx"
19constexpr uint64_t PULSECOUNT_MAX_PERIOD_NS = 1000000000ull;
22int CIOPulseCount::validateTimings(uint32_t high, uint32_t low)
const
26 if (high == 0 || low == 0)
28 DAWNERR(
"pulsecount timings must be > 0\n");
32 period =
static_cast<uint64_t
>(high) +
static_cast<uint64_t
>(low);
33 if (period > PULSECOUNT_MAX_PERIOD_NS)
35 DAWNERR(
"pulsecount period too large: %" PRIu64
" ns\n", period);
42int CIOPulseCount::configureDesc(
const CDescObject &desc)
48 for (
size_t i = 0; i < desc.
getSize(); i++)
64 DAWNERR(
"invalid pulsecount config size %d\n", item->
cfgid.
s.
size);
72 highNs = *
reinterpret_cast<const uint32_t *
>(&item->
data);
79 lowNs = *
reinterpret_cast<const uint32_t *
>(&item->
data);
86 DAWNERR(
"Unsupported pulsecount config 0x%08" PRIx32
"\n", item->
cfgid.
v);
96 DAWNERR(
"Unsupported pulsecount config 0x%08" PRIx32
"\n", item->
cfgid.
v);
102 ret = validateTimings(highNs, lowNs);
111int CIOPulseCount::writeCurrentConfig(uint32_t count)
115 info.high_ns = highNs;
119 return pulsecount_write(fd, &info);
122CIOPulseCount::~CIOPulseCount()
131 ret = configureDesc(
getDesc());
134 DAWNERR(
"pulsecount configure failed (error %d)\n", ret);
140 DAWNERR(
"pulsecount device number not configured\n");
144 snprintf(path,
sizeof(path), PULSECOUNT_PATH_FMT,
getCmnDevno());
146 fd = pulsecount_open(path);
149 DAWNERR(
"failed to open file %d\n", -errno);
162 DAWNERR(
"pulsecount requires DTYPE_UINT32\n");
173 pulsecount_close(fd);
182 uint32_t *tmp =
static_cast<uint32_t *
>(data.
getDataPtr());
195 ret = writeCurrentConfig(tmp[0]);
198 DAWNERR(
"pulsecount_write failed %d\n", ret);
202 ret = pulsecount_start(fd);
205 DAWNERR(
"pulsecount_start failed %d\n", ret);
211#ifdef CONFIG_DAWN_IO_TIMESTAMP
227 if (len != 1 || data ==
nullptr)
248 ret = validateTimings(newHigh, newLow);
254 if (lastCount != 0 && fd >= 0)
256 uint32_t oldHigh = highNs;
257 uint32_t oldLow = lowNs;
261 ret = writeCurrentConfig(lastCount);
277 return sizeof(uint32_t);
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.
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.
@ IO_CLASS_PULSECOUNT
Finite pulse-train output.
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.
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.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
int configure()
Configure object from descriptor data.
int deinit()
De-initialize object.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
Out-of-tree user-extension hooks for Dawn.
Base interface for I/O data buffers (static and dynamic).
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).
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).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Pulse-count output settings.
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
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.