Dawn Framework 1.0
Universal data acquisition framework for embedded systems
buffer.hxx
1// dawn/include/dawn/prog/buffer.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/porting/config.hxx"
9#include "dawn/prog/common.hxx"
10
11namespace dawn
12{
13// Forward declaration
14
15class CIOCommon;
16class CIOVirt;
17class io_ddata_t;
18
27{
28public:
29 constexpr static uint32_t DEPTH_DEFAULT = 16;
30
31 enum
32 {
33 PROG_BUFFER_CFG_FIRST = 0,
38 PROG_BUFFER_CFG_LAST = 31
39 };
40
41 enum
42 {
43 FLAG_AUTO_START = (1u << 0),
44 FLAG_MODE_ONESHOT = (1u << 1),
45 FLAG_KEEP_DATA_ON_STOP = (1u << 2),
46 } typedef EProgBufferFlags;
47
57
58 explicit CProgBuffer(CDescObject &desc)
59 : CProgCommon(desc)
60 , bind(nullptr)
61 , depth(DEPTH_DEFAULT)
62 , chunkSize(1)
63 , flags(FLAG_AUTO_START)
64 {
65 }
66
67 ~CProgBuffer() override;
68
69#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
70 const char *getClassNameStr() const override
71 {
72 return "buffer";
73 }
74#endif
75
76 int configure() override;
77 int init() override;
78 int deinit() override;
79 int doStart() override;
80 int doStop() override;
81 bool hasThread() const override;
82 int trigger(uint8_t cmd) override;
83
84 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
85 {
88 }
89
90 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
91 {
94 }
95
96 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size)
97 {
98 return CProgBuffer::cfgId(false, size, PROG_BUFFER_CFG_IOBIND);
99 }
100
101 constexpr static SObjectCfg::ObjectCfgId cfgIdDepth()
102 {
103 return CProgBuffer::cfgId(false, 1, PROG_BUFFER_CFG_DEPTH);
104 }
105
106 constexpr static SObjectCfg::ObjectCfgId cfgIdFlags()
107 {
108 return CProgBuffer::cfgId(false, 1, PROG_BUFFER_CFG_FLAGS);
109 }
110
111 constexpr static SObjectCfg::ObjectCfgId cfgIdChunkSize()
112 {
113 return CProgBuffer::cfgId(false, 1, PROG_BUFFER_CFG_CHUNK_SIZE);
114 }
115
116private:
119 enum
120 {
121 STAT_COUNT = 0,
122 STAT_DEPTH = 1,
123 STAT_HEAD = 2,
124 STAT_OVERFLOW = 3,
125 STAT_SNAPSHOT_SEQ = 4,
126 STAT_RUNTIME_FLAGS = 5,
127 STAT_SELECTED_OFFSET = 6,
128 STAT_RESERVED = 7,
129 STAT_WORDS = 8
130 };
131
134 enum
135 {
136 RUNTIME_RUNNING = (1u << 0),
137 RUNTIME_CAPTURE_ACTIVE = (1u << 1),
138 RUNTIME_FULL = (1u << 2),
139 RUNTIME_ERROR_RANGE = (1u << 3),
140 };
141
144 struct SBufferBind
145 {
146 SObjectId::ObjectId srcId; // source IO ID
147 SObjectId::ObjectId outId; // selected sample IO ID
148 SObjectId::ObjectId selId; // selector IO ID
149 SObjectId::ObjectId statId; // status IO ID
150 CIOCommon *src; // source IO
151 CIOVirt *out; // selected history sample/chunk
152 CIOVirt *sel; // history offset selector.
153 CIOVirt *stat; // status words.
154 io_ddata_t *ring; // ring for captured samples
155 io_ddata_t *outData; // scratch buffer for out
156 io_ddata_t *selData; // scratch buffer for sel
157 io_ddata_t *statData; // scratch buffer for stat
158 uint32_t head; // next write index into ring
159 uint32_t count; // samples in the ring.
160 uint32_t overflow; // overflow counter
161 uint32_t selectedOffset; // selector offset last applied
162 uint32_t snapshotSeq; // snapshot sequence counter
163 bool captureActive; // capture path enabled
164 };
165
166 SBufferBind *bind;
167 uint32_t depth;
168 uint32_t chunkSize;
169 uint32_t flags;
170
171 int configureDesc(const CDescObject &desc);
172 int allocBind(SObjectId::ObjectId src,
176 int validateBind();
177 int allocateBind();
178 void clearBind();
179 int captureBind(io_ddata_t *data);
180 int updateSelected();
181 int updateStat();
182
183 void cmdReset();
184 void cmdStartCapture();
185 void cmdStopCapture();
186
187 static uint32_t resolveRingIndex(const SBufferBind *bind, uint32_t sel, uint32_t depth);
188
189 static int srcNotifyCb(void *priv, io_ddata_t *data);
190 static void outGetCb(CIOVirt *io, void *priv);
191 static void selSetCb(CIOVirt *io, void *priv);
192 static void statGetCb(CIOVirt *io, void *priv);
193};
194} // Namespace dawn
Descriptor wrapper for individual object configuration.
Notify-driven history buffer Program.
Definition buffer.hxx:27
int doStart()
Start implementation hook.
Definition buffer.cxx:572
int deinit()
De-initialize object.
Definition buffer.cxx:555
int init()
One-time initialize object after bindings are resolved.
Definition buffer.cxx:529
int trigger(uint8_t cmd)
Execute a trigger command.
Definition buffer.cxx:672
@ PROG_BUFFER_CFG_IOBIND
I/O binding configuration.
Definition buffer.hxx:34
@ PROG_BUFFER_CFG_CHUNK_SIZE
Output samples per read.
Definition buffer.hxx:37
@ PROG_BUFFER_CFG_FLAGS
Config flags.
Definition buffer.hxx:36
@ PROG_BUFFER_CFG_DEPTH
Buffer depth.
Definition buffer.hxx:35
int configure()
Configure object from descriptor data.
Definition buffer.cxx:486
int doStop()
Stop implementation hook.
Definition buffer.cxx:589
bool hasThread() const
Check if a background thread is active.
Definition buffer.cxx:628
Base class for all PROG (processing) objects.
Definition common.hxx:27
@ PROG_CLASS_BUFFER
Notify-driven history capture buffer.
Definition common.hxx:103
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
One buffer binding payload.
Definition buffer.hxx:51
SObjectId::UObjectId out
Selected history sample to readers.
Definition buffer.hxx:53
SObjectId::UObjectId stat
Buffer status words (see STAT_*).
Definition buffer.hxx:55
SObjectId::UObjectId sel
History offset selector (0 = newest).
Definition buffer.hxx:54
SObjectId::UObjectId src
Source IO providing samples via notify.
Definition buffer.hxx:52
@ 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
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218