Dawn Framework 1.0
Universal data acquisition framework for embedded systems
switch.hxx
1// dawn/include/dawn/prog/switch.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
32{
33public:
34 enum
35 {
36 PROG_SWITCH_CFG_FIRST = 0,
37 PROG_SWITCH_CFG_INPUTS = 1,
38 PROG_SWITCH_CFG_TARGET = 2,
39 PROG_SWITCH_CFG_LAST = 31
40 };
41
42 explicit CProgSwitch(CDescObject &desc);
43
44 ~CProgSwitch() override;
45
46#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
47 const char *getClassNameStr() const override
48 {
49 return "switch";
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_SWITCH, SObjectId::DTYPE_ANY, 0, inst);
64 }
65
66 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
67 {
69 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_SWITCH, SObjectId::DTYPE_ANY, rw, size, id);
70 }
71
72 constexpr static SObjectCfg::ObjectCfgId cfgIdInputs(uint16_t size)
73 {
74 return CProgSwitch::cfgId(false, size, PROG_SWITCH_CFG_INPUTS);
75 }
76
77 constexpr static SObjectCfg::ObjectCfgId cfgIdTarget()
78 {
79 return CProgSwitch::cfgId(false, 3, PROG_SWITCH_CFG_TARGET);
80 }
81
82 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t = 0)
83 {
84 return CProgSwitch::cfgId(false, 0, 0);
85 }
86
87private:
89 struct SSwitchInput
90 {
91 CProgSwitch *owner;
92 CIOCommon *io;
94 uint32_t match;
95 uint32_t current;
96 };
97
98 CIOCommon *target;
99 SObjectId::ObjectId targetId;
100 io_ddata_t *iodata;
101 uint8_t onCmd;
102 uint8_t offCmd;
103 std::vector<SSwitchInput> inputs;
104 bool lastAndState;
105 bool active;
106 bool registered;
107
108 static int ioNotifierCb(void *priv, io_ddata_t *data);
109
110 int configureDesc(const CDescObject &desc);
111 int allocInput(SObjectId::ObjectId ioId, uint32_t match);
112 bool allInputsMatch() const;
113 void evaluate();
114};
115} // 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
Multi-input AND-gate switch: writes on/off commands to a target IO when all control inputs match thei...
Definition switch.hxx:32
int deinit()
De-initialize object.
Definition switch.cxx:202
bool hasThread() const
Check if a background thread is active.
Definition switch.cxx:313
int init()
One-time initialize object after bindings are resolved.
Definition switch.cxx:143
int doStart()
Start implementation hook.
Definition switch.cxx:229
int doStop()
Stop implementation hook.
Definition switch.cxx:294
int configure()
Configure object from descriptor data.
Definition switch.cxx:138
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