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#ifdef CONFIG_DAWN_IO_VIRT
11# include "dawn/io/virt.hxx"
12#endif
13
14using namespace dawn;
15
17 : CBindableObject(desc)
18{
19 DAWNASSERT(desc.getObjectId().s.cls > PROG_CLASS_ANY &&
20 desc.getObjectId().s.cls < PROG_CLASS_LAST,
21 "invalid class");
22}
23
24int CProgCommon::prepareWritableTarget(CIOCommon *io, size_t dim, bool notify)
25{
26 if (io == nullptr)
27 {
28 return -EINVAL;
29 }
30
31 if (!io->isWrite())
32 {
33 DAWNERR("target 0x%" PRIx32 " is not writable\n", io->getIdV());
34 return -EINVAL;
35 }
36
38 {
39 return OK;
40 }
41
42#ifdef CONFIG_DAWN_IO_VIRT
43 if (io->getDataDim() == 0)
44 {
45 return reinterpret_cast<CIOVirt *>(io)->initialize(dim, 1, notify);
46 }
47
48 if (io->getDataDim() != dim)
49 {
50 DAWNERR("virt target 0x%" PRIx32 " dimension mismatch: expected %zu got %zu\n",
51 io->getIdV(),
52 dim,
53 io->getDataDim());
54 return -EINVAL;
55 }
56
57 if (io->isNotify() != notify)
58 {
59 DAWNERR("virt target 0x%" PRIx32 " notify mismatch: expected %d got %d\n",
60 io->getIdV(),
61 notify,
62 io->isNotify());
63 return -EINVAL;
64 }
65
66 return OK;
67#else
68 UNUSED(dim);
69 UNUSED(notify);
70 DAWNERR("virtIO target 0x%" PRIx32 " requires CONFIG_DAWN_IO_VIRT\n", io->getIdV());
71 return -ENOTSUP;
72#endif
73}
Base object with bindable object map support.
Definition bindable.hxx:25
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:27
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:188
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
@ PROG_CLASS_ANY
Generic PROG type.
Definition common.hxx:35
CProgCommon(CDescObject &desc)
Constructor.
Definition common.cxx:16
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
uint32_t cls
Object class field (bits 21-29, max 511).
Definition objectid.hxx:265
struct dawn::SObjectId::UObjectId::@14 s
Bit-field structure for named member access.