Dawn Framework 1.0
Universal data acquisition framework for embedded systems
expression.hxx
1// dawn/include/dawn/prog/expression.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/sdata.hxx"
13#include "dawn/porting/config.hxx"
14#include "dawn/prog/common.hxx"
15
16namespace dawn
17{
18class CIOCommon;
19class io_ddata_t;
20
30{
31public:
32 enum
33 {
34 PROG_EXPRESSION_CFG_FIRST = 0,
35 PROG_EXPRESSION_CFG_IOBIND = 1,
36 PROG_EXPRESSION_CFG_OP = 2,
37 PROG_EXPRESSION_CFG_LAST = 31
38 };
39
40 enum
41 {
42 OP_SHIFT_LEFT = 0,
43 OP_SHIFT_RIGHT = 1,
44 OP_CONST_LEFT_SHIFT = 2,
45 OP_ADD = 3,
46 OP_SUB = 4,
47 };
48
49 explicit CProgExpression(CDescObject &desc);
50 ~CProgExpression() override;
51
52 int configure() override;
53 int init() override;
54 int deinit() override;
55 int doStart() override;
56 int doStop() override;
57 bool hasThread() const override;
58
59#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
60 const char *getClassNameStr() const override
61 {
62 return "expression";
63 }
64#endif
65
66 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
67 {
69 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_EXPRESSION, SObjectId::DTYPE_ANY, 0, inst);
70 }
71
72 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
73 {
75 CProgCommon::PROG_CLASS_EXPRESSION,
77 rw,
78 size,
79 id);
80 }
81
82 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size = 2)
83 {
84 return CProgExpression::cfgId(false, size, PROG_EXPRESSION_CFG_IOBIND);
85 }
86
87 constexpr static SObjectCfg::ObjectCfgId cfgIdOp(uint16_t size = 2)
88 {
89 return CProgExpression::cfgId(false, 2, PROG_EXPRESSION_CFG_OP);
90 }
91
92private:
93 struct SExpressionBind
94 {
95 CProgExpression *owner;
96 SObjectId::ObjectId sourceId;
97 SObjectId::ObjectId outputId;
98 CIOCommon *source;
99 CIOCommon *output;
102 };
103
104 std::vector<SExpressionBind *> binds;
105 uint32_t opType;
106 uint32_t constant;
107 bool active;
108 bool registered;
109
110 static int ioNotifierCb(void *priv, io_ddata_t *data);
111
112 int configureDesc(const CDescObject &desc);
113 int allocBind(SObjectId::ObjectId sourceId, SObjectId::ObjectId outputId);
114 bool compute(uint32_t input, uint32_t &result, const char *phase);
115 void refresh(SExpressionBind *bind, io_ddata_t *data, const char *phase);
116};
117} // 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
Arithmetic expression evaluator on IO values.
int init()
One-time initialize object after bindings are resolved.
int configure()
Configure object from descriptor data.
int doStop()
Stop implementation hook.
int doStart()
Start implementation hook.
bool hasThread() const
Check if a background thread is active.
int deinit()
De-initialize object.
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
Static (compile-time) I/O data buffer (no timestamp).
Definition sdata.hxx:39