6#include "dawn/prog/sampling.hxx"
10#include "dawn/debug.hxx"
11#include "dawn/io/common.hxx"
12#include "dawn/io/ddata.hxx"
16int CProgSampling::configureDesc(
const CDescObject &desc)
26 for (
size_t i = 0; i < desc.
getSize(); i++)
32 DAWNERR(
"Unsupported sampling config 0x%08" PRIx32
"\n", item->
cfgid.
v);
42 DAWNERR(
"Invalid IOBIND size %d, must be even\n", item->
cfgid.
s.
size);
49 for (j = 0; j < nbind; j++)
51 ret = allocObject(ids[j * 2].v, ids[j * 2 + 1].v);
65 DAWNERR(
"Invalid INTERVAL size %d\n", item->
cfgid.
s.
size);
69 data =
reinterpret_cast<const uint32_t *
>(item->
data);
76 DAWNERR(
"Unsupported sampling config 0x%08" PRIx32
"\n", item->
cfgid.
v);
89 DAWNINFO(
"allocate sampling 0x%" PRIx32
" -> 0x%" PRIx32
"\n", srcId, targetId);
91 b =
new (std::nothrow) SSamplingBind();
98 b->targetId = targetId;
110void CProgSampling::thread()
116 DAWNINFO(
"start sampling thread\n");
122 for (i = 0; i < binds.size(); i++)
126 ret = b->src->getData(*b->iodata, 1);
129 DAWNERR(
"getData failed for src %zu (error %d)\n", i, ret);
133 ret = b->target->setData(*b->iodata);
136 DAWNERR(
"setData failed for target %zu (error %d)\n", i, ret);
144 while (!threadCtl.shouldQuit());
147CProgSampling::~CProgSampling()
158 ret = configureDesc(
getDesc());
161 DAWNERR(
"Sampling configure failed (error %d)\n", ret);
176 for (i = 0; i < binds.size(); i++)
178 delete binds[i]->iodata;
195 for (i = 0; i < binds.size(); i++)
199 b->src =
getIO(b->srcId);
202 DAWNERR(
"Source IO 0x%" PRIx32
" not found\n", b->srcId);
206 if (!b->src->isRead())
208 DAWNERR(
"Source IO 0x%" PRIx32
" is not readable\n", b->srcId);
212 b->target =
getIO(b->targetId);
215 DAWNERR(
"Target IO 0x%" PRIx32
" not found\n", b->targetId);
219 if (b->target->getDtype() != b->src->getDtype())
221 DAWNERR(
"Target IO 0x%" PRIx32
" dtype mismatch\n", b->targetId);
227 ret = prepareWritableTarget(b->target,
228 b->src->getDataDim(),
229#ifdef CONFIG_DAWN_IO_NOTIFY
237 DAWNERR(
"Failed to initialize target %zu (error %d)\n", i, ret);
241 if (b->target->getDataDim() != b->src->getDataDim() ||
242 b->target->getDataSize() != b->src->getDataSize())
244 DAWNERR(
"Target IO 0x%" PRIx32
" shape mismatch\n", b->targetId);
250 b->iodata = b->src->ddata_alloc(1);
253 DAWNERR(
"Failed to allocate data buffer for src %zu\n", i);
CIOCommon * getIO(SObjectId::ObjectId id)
Get an I/O object by ID.
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
CDescObject & getDesc()
Get descriptor object for this object.
@ PROG_CLASS_SAMPLING
Periodic data sampler.
int doStart()
Start implementation hook.
bool hasThread() const
Check if a background thread is active.
int configure()
Configure object from descriptor data.
int init()
One-time initialize object after bindings are resolved.
int doStop()
Stop implementation hook.
int deinit()
De-initialize object.
@ PROG_SAMPLING_CFG_INTERVAL
Sampling interval (microseconds).
@ PROG_SAMPLING_CFG_IOBIND
I/O binding configuration.
bool isRunning() const
Check if the worker thread is running.
int threadStop()
Stop the worker thread.
int threadStart()
Start the worker thread.
void setThreadFunc(Func &&func)
Assign the function executed by threadStart().
Out-of-tree user-extension hooks for Dawn.
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).
uint32_t ObjectId
ObjectID type - single 32-bit value.
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.
32-bit encoded object identifier (union with bit field).