Dawn Framework 1.0
Universal data acquisition framework for embedded systems
common.cxx
1// dawn/src/prog/common.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/prog/common.hxx"
7
8#include "dawn/debug.hxx"
9#include "dawn/io/common.hxx"
10#include "dawn/io/ddata.hxx"
11#ifdef CONFIG_DAWN_IO_VIRT
12# include "dawn/io/virt.hxx"
13#endif
14
15using namespace dawn;
16
18 : CBindableObject(desc)
19{
20 DAWNASSERT(desc.getObjectId().s.cls > PROG_CLASS_ANY &&
21 desc.getObjectId().s.cls < PROG_CLASS_LAST,
22 "invalid class");
23}
24
25size_t CProgCommon::contiguousCount(io_ddata_t *d, size_t nbatch, size_t nitems)
26{
27 if (nitems != d->getItems())
28 {
29 return 0;
30 }
31
32 if (nbatch == 1)
33 {
34 return nitems;
35 }
36
37 if (d->hasTs || d->off != d->getSize() * d->getItems())
38 {
39 return 0;
40 }
41
42 return nbatch * nitems;
43}
44
45int CProgCommon::prepareWritableTarget(CIOCommon *io, size_t dim, bool notify, size_t batch)
46{
47 if (io == nullptr)
48 {
49 return -EINVAL;
50 }
51
52 if (!io->isWrite())
53 {
54 DAWNERR("target 0x%" PRIx32 " is not writable\n", io->getIdV());
55 return -EINVAL;
56 }
57
59 {
60 return OK;
61 }
62
63#ifdef CONFIG_DAWN_IO_VIRT
64 if (io->getDataDim() == 0)
65 {
66 return reinterpret_cast<CIOVirt *>(io)->initialize(dim, batch, notify);
67 }
68
69 if (io->getDataDim() != dim)
70 {
71 DAWNERR("virt target 0x%" PRIx32 " dimension mismatch: expected %zu got %zu\n",
72 io->getIdV(),
73 dim,
74 io->getDataDim());
75 return -EINVAL;
76 }
77
78 if (io->isNotify() != notify)
79 {
80 DAWNERR("virt target 0x%" PRIx32 " notify mismatch: expected %d got %d\n",
81 io->getIdV(),
82 notify,
83 io->isNotify());
84 return -EINVAL;
85 }
86
87# ifdef CONFIG_DAWN_IO_NOTIFY
88 if (io->getNotifyBatch() != batch)
89 {
90 DAWNERR("virt target 0x%" PRIx32 " batch mismatch: expected %zu got %zu\n",
91 io->getIdV(),
92 batch,
93 io->getNotifyBatch());
94 return -EINVAL;
95 }
96# endif
97
98 return OK;
99#else
100 UNUSED(dim);
101 UNUSED(notify);
102 UNUSED(batch);
103 DAWNERR("virtIO target 0x%" PRIx32 " requires CONFIG_DAWN_IO_VIRT\n", io->getIdV());
104 return -ENOTSUP;
105#endif
106}
CBindableObject(CDescObject &desc)
Construct a CBindableObject from a descriptor.
Definition bindable.hxx:33
Descriptor wrapper for individual object configuration.
SObjectId::UObjectId & getObjectId() const
Get object identifier as union structure.
Base class for all I/O objects.
Definition common.hxx:30
virtual bool isWrite() const =0
Check if IO supports write operations.
virtual bool isNotify() const =0
Check if IO supports notifications.
virtual size_t getDataDim() const =0
Get data vector dimension.
@ IO_CLASS_VIRT
Virtual I/O.
Definition common.hxx:217
Virtual I/O type for user-provided data and callbacks.
Definition virt.hxx:26
uint16_t getCls() const
Get object class field.
Definition object.cxx:170
SObjectId::ObjectId getIdV() const
Get object identifier as raw 32-bit value.
Definition object.cxx:155
int prepareWritableTarget(CIOCommon *io, size_t dim, bool notify, size_t batch=1)
Check a writable output; shape a deferred virt output or check an already shaped one.
Definition common.cxx:45
@ PROG_CLASS_ANY
Generic PROG type.
Definition common.hxx:36
CProgCommon(CDescObject &desc)
Constructor.
Definition common.cxx:17
static size_t contiguousCount(io_ddata_t *d, size_t nbatch, size_t nitems)
Count elements of the first nbatch batches stored back to back.
Definition common.cxx:25
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Heap-allocated dynamic I/O data buffer.
Definition ddata.hxx:21
size_t getSize() const
Get element size in bytes.
Definition ddata.hxx:121
size_t getItems()
Get number of items per batch.
Definition ddata.hxx:128
uint32_t cls
Object class field (bits 21-29, max 511).
Definition objectid.hxx:265
struct dawn::SObjectId::UObjectId::@305255014053264215072363020330017273014233040275 s
Bit-field structure for named member access.