11#include "dawn/io/dummy.hxx"
15static size_t dummyInitvalWordsPerValue(
size_t tlen)
17 if (tlen ==
sizeof(uint64_t))
28 size_t parsed_dim = 1;
29 bool parsed_dim_set =
false;
30 size_t parsed_init_len = 1;
34 for (i = 0; i < desc.
getSize(); i++)
46 DAWNERR(
"unsupported dummy cfg 0x08%" PRIx32
"\n", item->
cfgid.
v);
52 case IO_DUMMY_CFG_INITVAL:
55 size_t word_step = dummyInitvalWordsPerValue(
getDtypeSize());
60 DAWNERR(
"Dummy IO init value dimension must be > 0\n");
64 if (word_count % word_step != 0)
66 DAWNERR(
"Dummy IO init value word count %zu is invalid "
67 "for element size %zu\n",
73 init_len = word_count / word_step;
74 cfgval = &item->
data[0];
75 parsed_init_len = init_len;
77 offset += 1 + word_count;
81 case IO_DUMMY_CFG_DIM:
83 uint32_t dim = item->
data[0];
87 DAWNERR(
"Dummy IO dimension must be > 0\n");
92 parsed_dim_set =
true;
99 DAWNERR(
"unsupported dummy objectCfg 0x%" PRIx32
"\n", item->
cfgid.
v);
105 if (!parsed_dim_set && cfgval !=
nullptr)
107 parsed_dim = parsed_init_len;
110 if (cfgval !=
nullptr && parsed_init_len < parsed_dim)
112 DAWNERR(
"Dummy IO init value dimension %zu is smaller than data "
120 cfglen = parsed_init_len;
125int CIODummy::setVal(
const void *v,
size_t d)
127 DAWNASSERT(dlen * tlen == d,
"invalid input");
128 DAWNASSERT(val !=
nullptr,
"buffer not initialized");
132 std::memcpy(val, v, d);
134#ifdef CONFIG_DAWN_IO_TIMESTAMP
146int CIODummy::applyInitval()
151 if (cfgval ==
nullptr)
156 DAWNASSERT(val !=
nullptr,
"buffer not initialized");
158 word_step = dummyInitvalWordsPerValue(tlen);
160 for (i = 0; i < dlen; i++)
162 std::memcpy(
static_cast<uint8_t *
>(val) + (i * tlen), &cfgval[i * word_step], tlen);
179 return configureDesc(
getDesc());
186 val =
new (std::nothrow) uint8_t[dlen * tlen]();
189 DAWNERR(
"new failed\n");
193 ret = applyInitval();
196 delete[]
static_cast<uint8_t *
>(val);
208 delete[]
static_cast<uint8_t *
>(val);
219 for (i = 0; i < len; i++)
223#ifdef CONFIG_DAWN_IO_TIMESTAMP
226 std::memcpy(data.
getDataPtr(i), val, dlen * tlen);
236 return setVal(data.
getDataPtr(), dlen * tlen);
239#ifdef CONFIG_DAWN_IO_NOTIFY
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.
uint64_t getTimestamp()
Get current timestamp.
bool isTimestamp() const
Check if I/O supports timestamp.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
@ IO_CLASS_ANY
Any I/O class.
@ IO_CLASS_DUMMY
Dummy I/O (for testing)
int deinit()
De-initialize object.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int init()
One-time initialize object after bindings are resolved.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
int configure()
Configure object from descriptor data.
size_t getDataDim() const
Get data vector dimension.
CDescObject & getDesc()
Get descriptor object for this object.
size_t getDtypeSize() const
Get size of this object's data type.
Out-of-tree user-extension hooks for Dawn.
Base interface for I/O data buffers (static and dynamic).
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).
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.