Dawn Framework 1.0
Universal data acquisition framework for embedded systems
sampling.hxx
1// dawn/include/dawn/prog/sampling.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <atomic>
9#include <semaphore.h>
10#include <vector>
11
12#include "dawn/common/thread.hxx"
13#include "dawn/porting/config.hxx"
14#include "dawn/prog/common.hxx"
15
16namespace dawn
17{
18// Forward declaration
19
20class CIOCommon;
21class io_ddata_t;
22
29
30class CProgSampling : public CProgCommon
31{
32public:
33 constexpr static uint32_t INTERVAL_DEFAULT = CONFIG_DAWN_PROG_SAMPLING_INTERVAL;
34
35 enum
36 {
37 PROG_SAMPLING_CFG_FIRST = 0,
42 PROG_SAMPLING_CFG_LAST = 31
43 };
44
45 enum
46 {
47 FLAG_AUTO_START = (1u << 0),
48 };
49
51 : CProgCommon(desc)
52 , interval(INTERVAL_DEFAULT)
53 , priority(CThreadedObject::THREAD_PRIORITY_DEFAULT)
54 , flags(FLAG_AUTO_START)
55 , active(false)
56 , stopping(false)
57 {
58 sem_init(&wakeup, 0, 0);
59 }
60
61 ~CProgSampling() override;
62
63#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
64 const char *getClassNameStr() const override
65 {
66 return "sampling";
67 }
68#endif
69
70 int configure() override;
71 int init() override;
72 int deinit() override;
73 int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len) override;
74 int doStart() override;
75 int doStop() override;
76 bool hasThread() const override;
77 int trigger(uint8_t cmd) override;
78
79 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
80 {
83 }
84
85 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint16_t size, uint8_t id)
86 {
90 rw,
91 size,
92 id);
93 }
94
95 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size)
96 {
97 return CProgSampling::cfgId(false, size, PROG_SAMPLING_CFG_IOBIND);
98 }
99
100 constexpr static SObjectCfg::ObjectCfgId cfgIdIOInterval()
101 {
102 return CProgSampling::cfgId(true, 1, PROG_SAMPLING_CFG_INTERVAL);
103 }
104
105 constexpr static SObjectCfg::ObjectCfgId cfgIdPriority()
106 {
107 return CProgSampling::cfgId(false, 1, PROG_SAMPLING_CFG_PRIORITY);
108 }
109
110 constexpr static SObjectCfg::ObjectCfgId cfgIdFlags()
111 {
112 return CProgSampling::cfgId(false, 1, PROG_SAMPLING_CFG_FLAGS);
113 }
114
115private:
116 struct SSamplingBind
117 {
119 SObjectId::ObjectId targetId;
120 class CIOCommon *src;
121 class CIOCommon *target;
122 io_ddata_t *iodata;
123 };
124
125 std::vector<SSamplingBind *> binds;
126 std::atomic<uint32_t> interval;
127 int priority;
128 uint32_t flags;
129 std::atomic<bool> active;
130 std::atomic<bool> stopping;
131 sem_t wakeup;
132 CThreadedObject threadCtl;
133
134 int configureDesc(const CDescObject &desc);
135 int allocObject(SObjectId::ObjectId srcId, SObjectId::ObjectId targetId);
136 void thread();
137};
138} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:30
Base class for all PROG (processing) objects.
Definition common.hxx:28
@ PROG_CLASS_SAMPLING
Periodic data sampler.
Definition common.hxx:64
CProgCommon(CDescObject &desc)
Constructor.
Definition common.cxx:17
Periodic data sampling and buffering Program.
Definition sampling.hxx:31
int trigger(uint8_t cmd)
Execute a trigger command.
Definition sampling.cxx:384
int doStart()
Start implementation hook.
Definition sampling.cxx:357
bool hasThread() const
Check if a background thread is active.
Definition sampling.cxx:402
@ FLAG_AUTO_START
Sample from start, without a trigger.
Definition sampling.hxx:47
int configure()
Configure object from descriptor data.
Definition sampling.cxx:248
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
Definition sampling.cxx:136
int init()
One-time initialize object after bindings are resolved.
Definition sampling.cxx:283
int doStop()
Stop implementation hook.
Definition sampling.cxx:375
int deinit()
De-initialize object.
Definition sampling.cxx:266
@ PROG_SAMPLING_CFG_INTERVAL
Sampling interval (microseconds).
Definition sampling.hxx:39
@ PROG_SAMPLING_CFG_IOBIND
I/O binding configuration.
Definition sampling.hxx:38
@ PROG_SAMPLING_CFG_PRIORITY
Sampling thread priority (0 = default).
Definition sampling.hxx:40
@ PROG_SAMPLING_CFG_FLAGS
Behavior flags.
Definition sampling.hxx:41
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