Dawn Framework 1.0
Universal data acquisition framework for embedded systems
descselector.cxx
1// dawn/src/io/descselector.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/descselector.hxx"
7
8#include <errno.h>
9
10using namespace dawn;
11
12int CIODescSelector::configureDesc(const CDescObject &desc)
13{
14 const SObjectCfg::SObjectCfgItem *item = nullptr;
15 size_t offset = 0;
16 size_t i = 0;
17
18 for (i = 0; i < desc.getSize(); i++)
19 {
20 item = desc.objectCfgItemAtOffset(offset);
21
22 switch (item->cfgid.s.cls)
23 {
25 {
26 offset += cfgCmnOffset(item);
27 break;
28 }
29
30 default:
31 {
32 DAWNERR("unsupported descselector cfg 0x08%" PRIx32 "\n", item->cfgid.v);
33 return -EINVAL;
34 }
35 }
36 }
37
38 return OK;
39}
40
41CIODescSelector::~CIODescSelector()
42{
43 deinit();
44}
45
47{
48 return configureDesc(getDesc());
49}
50
52{
53 return OK;
54}
55
57{
58 uint32_t *slot;
59
60 if (len != 1)
61 {
62 return -EINVAL;
63 }
64
65 slot = reinterpret_cast<uint32_t *>(data.getDataPtr());
66 *slot = static_cast<uint32_t>(CDescSwitch::getActiveSlot());
67
68 return OK;
69}
70
72{
74 const uint32_t *bin;
75 uint32_t slot;
76 int ret;
77
78 slot = *reinterpret_cast<const uint32_t *>(data.getDataPtr());
79
80 if (slot >= CONFIG_DAWN_DESC_SLOTS)
81 {
82 return -EINVAL;
83 }
84
85 if (slot == static_cast<uint32_t>(CDescSwitch::getActiveSlot()))
86 {
87 return OK;
88 }
89
90 ret = CDevDescriptor::getInst()->getDescriptor(static_cast<int>(slot), reg);
91 if (ret < 0)
92 {
93 return ret;
94 }
95
96 if (reg.ptr == nullptr || reg.len == 0)
97 {
98 return -ENODATA;
99 }
100
101 if ((reg.len % sizeof(uint32_t)) != 0)
102 {
103 return -EINVAL;
104 }
105
106 bin = static_cast<const uint32_t *>(reg.ptr);
107
108 if (!CDescriptor::binCheckValid(bin, reg.len))
109 {
110 return -EBADMSG;
111 }
112
113 ret = CDescriptor::binValid(bin, reg.len);
114 if (ret < 0)
115 {
116 return ret;
117 }
118
119 CDescSwitch::requestSwitch(static_cast<uint8_t>(slot));
120 return OK;
121}
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.
static uint8_t getActiveSlot()
Get currently active descriptor slot.
static void requestSwitch(uint8_t slot)
Request descriptor switch to a slot.
static int binValid(const uint32_t *bin, size_t len)
Validate binary descriptor integrity.
static bool binCheckValid(const uint32_t *bin, size_t len)
Validate descriptor CRC32 checksum.
int getDescriptor(int inst, SDescriptorReg &reg)
Get registered descriptor data for an instance.
static CDevDescriptor * getInst()
Get singleton instance.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int deinit()
De-initialize object.
int configure()
Configure object from descriptor data.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Registered descriptor information.
size_t len
Descriptor length in bytes.
void * ptr
Pointer to descriptor data.
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.