Dawn Framework 1.0
Universal data acquisition framework for embedded systems
toggle.hxx
1// dawn/include/dawn/prog/toggle.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
31{
32public:
33 enum
34 {
35 PROG_TOGGLE_CFG_FIRST = 0,
36 PROG_TOGGLE_CFG_IOBIND = 1,
37 PROG_TOGGLE_CFG_VALUES = 2,
38 PROG_TOGGLE_CFG_LAST = 31
39 };
40
41 explicit CProgToggle(CDescObject &desc);
42 ~CProgToggle() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "toggle";
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 int trigger(uint8_t cmd) override;
58
59 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
60 {
62 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_TOGGLE, SObjectId::DTYPE_ANY, 0, inst);
63 }
64
65 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
66 {
68 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_TOGGLE, SObjectId::DTYPE_ANY, rw, size, id);
69 }
70
71 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size = 2)
72 {
73 return CProgToggle::cfgId(false, size, PROG_TOGGLE_CFG_IOBIND);
74 }
75
76 constexpr static SObjectCfg::ObjectCfgId cfgIdValues(uint16_t size = 2)
77 {
78 return CProgToggle::cfgId(false, 2, PROG_TOGGLE_CFG_VALUES);
79 }
80
81private:
82 struct SToggleBind
83 {
84 CProgToggle *owner;
85 SObjectId::ObjectId sourceId;
86 SObjectId::ObjectId outputId;
87 CIOCommon *source;
88 CIOCommon *output;
89 io_ddata_t *sourceData;
91 uint32_t prevInput;
92 };
93
94 std::vector<SToggleBind *> binds;
95 uint32_t onVal;
96 uint32_t offVal;
97 uint32_t curVal;
98 bool active;
99 bool registered;
100
101 static int ioNotifierCb(void *priv, io_ddata_t *data);
102
103 int configureDesc(const CDescObject &desc);
104 int allocBind(SObjectId::ObjectId sourceId, SObjectId::ObjectId outputId);
105 uint32_t readInput(SToggleBind *bind, io_ddata_t *data);
106 void writeValue(SToggleBind *bind);
107 void refresh(SToggleBind *bind, io_ddata_t *data);
108};
109} // 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
Toggle/latch: flips output between two configured values on each rising edge of the input.
Definition toggle.hxx:31
int deinit()
De-initialize object.
Definition toggle.cxx:174
int doStart()
Start implementation hook.
Definition toggle.cxx:244
int trigger(uint8_t cmd)
Execute a trigger command.
Definition toggle.cxx:302
bool hasThread() const
Check if a background thread is active.
Definition toggle.cxx:297
int configure()
Configure object from descriptor data.
Definition toggle.cxx:128
int init()
One-time initialize object after bindings are resolved.
Definition toggle.cxx:133
int doStop()
Stop implementation hook.
Definition toggle.cxx:278
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