Dawn Framework 1.0
Universal data acquisition framework for embedded systems
selector.hxx
1// dawn/include/dawn/prog/selector.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9#include <inttypes.h>
10#include <vector>
11
12#include "dawn/io/ddata.hxx"
13#include "dawn/porting/config.hxx"
14#include "dawn/prog/common.hxx"
15
16namespace dawn
17{
18// Forward declaration
19
20class CIOCommon;
21
31{
32public:
33 enum
34 {
35 PROG_SELECTOR_CFG_FIRST = 0,
36 PROG_SELECTOR_CFG_CONTROL = 1,
37 PROG_SELECTOR_CFG_DATA = 2,
38 PROG_SELECTOR_CFG_TARGET = 3,
39 PROG_SELECTOR_CFG_LAST = 31
40 };
41
42 explicit CProgSelector(CDescObject &desc);
43
44 ~CProgSelector() override;
45
46#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
47 const char *getClassNameStr() const override
48 {
49 return "selector";
50 }
51#endif
52
53 int configure() override;
54 int init() override;
55 int deinit() override;
56 int doStart() override;
57 int doStop() override;
58 bool hasThread() const override;
59
60 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
61 {
63 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_SELECTOR, SObjectId::DTYPE_ANY, 0, inst);
64 }
65
66 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
67 {
69 CProgCommon::PROG_CLASS_SELECTOR,
71 rw,
72 size,
73 id);
74 }
75
76 constexpr static SObjectCfg::ObjectCfgId cfgIdControl()
77 {
78 return CProgSelector::cfgId(false, 1, PROG_SELECTOR_CFG_CONTROL);
79 }
80
81 constexpr static SObjectCfg::ObjectCfgId cfgIdData(uint16_t size)
82 {
83 return CProgSelector::cfgId(false, size, PROG_SELECTOR_CFG_DATA);
84 }
85
86 constexpr static SObjectCfg::ObjectCfgId cfgIdTarget()
87 {
88 return CProgSelector::cfgId(false, 1, PROG_SELECTOR_CFG_TARGET);
89 }
90
91 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t = 0)
92 {
93 return CProgSelector::cfgId(false, 0, 0);
94 }
95
96private:
97 struct SDataBind
98 {
99 CProgSelector *owner;
100 size_t index;
101 };
102
103 CIOCommon *ctrlIo;
104 std::vector<CIOCommon *> dataIos;
105 std::vector<SDataBind> dataBinds;
106 std::vector<SObjectId::ObjectId> dataIds;
107 CIOCommon *target;
108 SObjectId::ObjectId ctrlId;
109 SObjectId::ObjectId targetId;
110 io_ddata_t *iodata;
111 uint32_t currentIndex;
112 bool active;
113 bool registered;
114
115 static int ctrlNotifierCb(void *priv, io_ddata_t *data);
116 static int dataNotifierCb(void *priv, io_ddata_t *data);
117
118 int configureDesc(const CDescObject &desc);
119 void applyRoute(uint32_t index);
120};
121} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
Base class for all PROG (processing) objects.
Definition common.hxx:27
Data selector: routes one of N data inputs to a target IO based on the value of a control input.
Definition selector.hxx:31
int init()
One-time initialize object after bindings are resolved.
Definition selector.cxx:127
int configure()
Configure object from descriptor data.
Definition selector.cxx:122
int deinit()
De-initialize object.
Definition selector.cxx:211
int doStop()
Stop implementation hook.
Definition selector.cxx:325
int doStart()
Start implementation hook.
Definition selector.cxx:274
bool hasThread() const
Check if a background thread is active.
Definition selector.cxx:349
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ OBJTYPE_PROG
Program/algorithm object type.
Definition objectid.hxx:202
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290
Heap-allocated dynamic I/O data buffer.
Definition ddata.hxx:21