Dawn Framework 1.0
Universal data acquisition framework for embedded systems
sequencer.hxx
1// dawn/include/dawn/prog/sequencer.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <mutex>
9#include <vector>
10
11#include "dawn/common/thread.hxx"
12#include "dawn/prog/common.hxx"
13
14namespace dawn
15{
16// Forward declaration
17
18class CIOCommon;
19class io_ddata_t;
20
29{
30public:
31 enum
32 {
33 PROG_SEQUENCER_CFG_FIRST = 0,
34 PROG_SEQUENCER_CFG_TARGET = 1,
35 PROG_SEQUENCER_CFG_STATE = 2,
36 PROG_SEQUENCER_CFG_START = 3,
37 PROG_SEQUENCER_CFG_LAST = 31
38 };
39
40 explicit CProgSequencer(CDescObject &desc)
41 : CProgCommon(desc)
42 , iodata(nullptr)
43 , startIndex(0)
44 , currentIndex(0)
45 , targetSize(0)
46 , targetDtype(SObjectId::DTYPE_ANY)
47 {
48 }
49
50 ~CProgSequencer() override;
51
52#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
53 const char *getClassNameStr() const override
54 {
55 return "sequencer";
56 }
57#endif
58
59 int configure() override;
60 int init() override;
61 int deinit() override;
62 int doStart() override;
63 int doStop() override;
64 bool hasThread() const override;
65 int trigger(uint8_t cmd) override;
66
67 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
68 {
71 }
72
73 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
74 {
78 rw,
79 size,
80 id);
81 }
82
83 constexpr static SObjectCfg::ObjectCfgId cfgIdTargets(uint16_t size)
84 {
85 return CProgSequencer::cfgId(false, size, PROG_SEQUENCER_CFG_TARGET);
86 }
87
88 constexpr static SObjectCfg::ObjectCfgId cfgIdStates(uint16_t size)
89 {
90 return CProgSequencer::cfgId(true, size, PROG_SEQUENCER_CFG_STATE);
91 }
92
93 constexpr static SObjectCfg::ObjectCfgId cfgIdStartIndex()
94 {
95 return CProgSequencer::cfgId(true, 1, PROG_SEQUENCER_CFG_START);
96 }
97
98private:
99 int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len) override;
100
101 struct SState
102 {
103 uint32_t value;
104 uint32_t dwellUs;
105 };
106
107 int configureDesc(const CDescObject &desc);
108 int allocObject(SObjectId::ObjectId targetId);
109 int reloadRuntimeConfig(bool resetCurrent,
110 SObjectCfg::ObjectCfgId overrideCfg = 0,
111 const uint32_t *overrideData = nullptr,
112 size_t overrideLen = 0);
113 int applyState(size_t index);
114 void thread();
115
116 std::vector<SObjectId::ObjectId> targetIds;
117 std::vector<CIOCommon *> targets;
118 std::vector<SState> states;
119 io_ddata_t *iodata;
120 CThreadedObject threadCtl;
121 std::mutex stateLock;
122 size_t startIndex;
123 size_t currentIndex;
124 size_t targetSize;
125 uint8_t targetDtype;
126};
127} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all PROG (processing) objects.
Definition common.hxx:27
@ PROG_CLASS_SEQUENCER
Periodic state sequencer.
Definition common.hxx:107
Periodic state sequencer Program.
Definition sequencer.hxx:29
bool hasThread() const
Check if a background thread is active.
int init()
One-time initialize object after bindings are resolved.
int configure()
Configure object from descriptor data.
int deinit()
De-initialize object.
int doStop()
Stop implementation hook.
int doStart()
Start implementation hook.
int trigger(uint8_t cmd)
Execute a trigger command.
Portable thread owner abstraction for Dawn components.
Definition thread.hxx:32
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