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 <vector>
9
10#include "dawn/common/thread.hxx"
11#include "dawn/porting/config.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 constexpr static uint32_t INTERVAL_DEFAULT = CONFIG_DAWN_PROG_SAMPLING_INTERVAL;
32
33 enum
34 {
35 PROG_SAMPLING_CFG_FIRST = 0,
38 PROG_SAMPLING_CFG_LAST = 31
39 };
40
42 : CProgCommon(desc)
43 , interval(INTERVAL_DEFAULT)
44 {
45 }
46
47 ~CProgSampling() override;
48
49#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
50 const char *getClassNameStr() const override
51 {
52 return "sampling";
53 }
54#endif
55
56 int configure() override;
57 int init() override;
58 int deinit() override;
59 int doStart() override;
60 int doStop() override;
61 bool hasThread() const override;
62
63 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
64 {
67 }
68
69 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
70 {
74 rw,
75 size,
76 id);
77 }
78
79 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size)
80 {
81 return CProgSampling::cfgId(false, size, PROG_SAMPLING_CFG_IOBIND);
82 }
83
84 constexpr static SObjectCfg::ObjectCfgId cfgIdIOInterval()
85 {
86 return CProgSampling::cfgId(true, 1, PROG_SAMPLING_CFG_INTERVAL);
87 }
88
89private:
90 struct SSamplingBind
91 {
93 SObjectId::ObjectId targetId;
94 class CIOCommon *src;
95 class CIOCommon *target;
96 io_ddata_t *iodata;
97 };
98
99 std::vector<SSamplingBind *> binds;
100 uint32_t interval;
101 CThreadedObject threadCtl;
102
103 int configureDesc(const CDescObject &desc);
104 int allocObject(SObjectId::ObjectId srcId, SObjectId::ObjectId targetId);
105 void thread();
106};
107} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all PROG (processing) objects.
Definition common.hxx:27
@ PROG_CLASS_SAMPLING
Periodic data sampler.
Definition common.hxx:63
Periodic data sampling and buffering Program.
Definition sampling.hxx:29
int doStart()
Start implementation hook.
Definition sampling.cxx:261
bool hasThread() const
Check if a background thread is active.
Definition sampling.cxx:274
int configure()
Configure object from descriptor data.
Definition sampling.cxx:152
int init()
One-time initialize object after bindings are resolved.
Definition sampling.cxx:187
int doStop()
Stop implementation hook.
Definition sampling.cxx:269
int deinit()
De-initialize object.
Definition sampling.cxx:170
@ PROG_SAMPLING_CFG_INTERVAL
Sampling interval (microseconds).
Definition sampling.hxx:37
@ PROG_SAMPLING_CFG_IOBIND
I/O binding configuration.
Definition sampling.hxx:36
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