Dawn Framework 1.0
Universal data acquisition framework for embedded systems
bitmerge.hxx
1// dawn/include/dawn/prog/bitmerge.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9#include <inttypes.h>
10#include <mutex>
11#include <vector>
12
13#include "dawn/io/ddata.hxx"
14#include "dawn/porting/config.hxx"
15#include "dawn/prog/common.hxx"
16
17namespace dawn
18{
19// Forward declaration
20
21class CIOCommon;
22
28
29class CProgBitMerge : public CProgCommon
30{
31public:
32 enum
33 {
34 PROG_BITMERGE_CFG_FIRST = 0,
35 PROG_BITMERGE_CFG_INPUTS = 1,
36 PROG_BITMERGE_CFG_OUTPUT = 2,
37 PROG_BITMERGE_CFG_LAST = 31
38 };
39
40 explicit CProgBitMerge(CDescObject &desc);
41
42 ~CProgBitMerge() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "bitmerge";
48 }
49#endif
50
51 int configure() override;
52 int init() override;
53 int deinit() override;
54 int doStart() override;
55 int doStop() override;
56 bool hasThread() const override;
57
58 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
59 {
61 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_BITMERGE, SObjectId::DTYPE_ANY, 0, inst);
62 }
63
64 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint16_t size, uint8_t id)
65 {
67 CProgCommon::PROG_CLASS_BITMERGE,
69 rw,
70 size,
71 id);
72 }
73
74 constexpr static SObjectCfg::ObjectCfgId cfgIdInputs(uint16_t size)
75 {
76 return CProgBitMerge::cfgId(false, size, PROG_BITMERGE_CFG_INPUTS);
77 }
78
79 constexpr static SObjectCfg::ObjectCfgId cfgIdOutput()
80 {
81 return CProgBitMerge::cfgId(false, 1, PROG_BITMERGE_CFG_OUTPUT);
82 }
83
84private:
85 struct SMergeInput
86 {
87 CProgBitMerge *owner;
88 CIOCommon *io;
90 uint32_t shift;
91 uint32_t mask;
92 io_ddata_t *currentData;
93 };
94
95 static constexpr size_t NO_STREAM = static_cast<size_t>(-1);
96
97 CIOCommon *output;
98 SObjectId::ObjectId outputId;
99 std::vector<SMergeInput> inputs;
100 io_ddata_t *outputData;
101 size_t streamIdx;
102 size_t batch;
103 bool active;
104 bool registered;
105 std::mutex mergeLock;
106
108
109 static int ioNotifierCb(void *priv, io_ddata_t *data);
110
112
113 void mergeBatch(const void *in, void *out, size_t items, const SMergeInput *src, uint32_t orval);
114
116
117 int configureDesc(const CDescObject &desc);
118
120
121 int allocInput(SObjectId::ObjectId ioId, uint32_t shift, uint32_t mask);
122
124
125 int checkFieldLayout(uint32_t width) const;
126
132
133 int mergeConstant(size_t skip, uint32_t &acc);
134
136
137 void updateScalar();
138
140
141 void updateStream(io_ddata_t *data);
142};
143} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:30
int init()
One-time initialize object after bindings are resolved.
Definition bitmerge.cxx:324
bool hasThread() const
Check if a background thread is active.
Definition bitmerge.cxx:568
int doStart()
Start implementation hook.
Definition bitmerge.cxx:502
int configure()
Configure object from descriptor data.
Definition bitmerge.cxx:276
int deinit()
De-initialize object.
Definition bitmerge.cxx:456
int doStop()
Stop implementation hook.
Definition bitmerge.cxx:549
CProgCommon(CDescObject &desc)
Constructor.
Definition common.cxx:17
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