Dawn Framework 1.0
Universal data acquisition framework for embedded systems
saturate.hxx
1// dawn/include/dawn/prog/saturate.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <atomic>
9#include <cstdint>
10
11#include "dawn/porting/config.hxx"
12#include "dawn/prog/common.hxx"
13#include "dawn/prog/process.hxx"
14
15namespace dawn
16{
23
24class CProgSaturate : public CProgProcess
25{
26public:
27 enum
28 {
31 };
32
33 explicit CProgSaturate(CDescObject &desc)
34 : CProgProcess(desc)
35 , minRaw(0)
36 , maxRaw(0)
37 , hasMin(false)
38 , hasMax(false)
39 {
40 }
41
42#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
43 const char *getClassNameStr() const override
44 {
45 return "saturate";
46 }
47#endif
48
49 int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len) override;
50
51 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
52 {
54 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_SATURATE, SObjectId::DTYPE_ANY, 0, inst);
55 }
56
57 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint16_t size, uint8_t id)
58 {
60 CProgCommon::PROG_CLASS_SATURATE,
62 rw,
63 size,
64 id);
65 }
66
67 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size = 2)
68 {
69 return CProgSaturate::cfgId(false, size, PROG_STATS_CFG_IOBIND);
70 }
71
72 constexpr static SObjectCfg::ObjectCfgId cfgIdMin(bool rw = false)
73 {
74 return CProgSaturate::cfgId(rw, 1, PROG_SATURATE_CFG_MIN);
75 }
76
77 constexpr static SObjectCfg::ObjectCfgId cfgIdMax(bool rw = false)
78 {
79 return CProgSaturate::cfgId(rw, 1, PROG_SATURATE_CFG_MAX);
80 }
81
82protected:
83 int configureExtraCfgItem(const CDescObject &desc,
84 const SObjectCfg::SObjectCfgItem *item,
85 size_t &offset) override;
86
87 bool isBatchAware() const override
88 {
89 return true;
90 }
91
92 void handle(CIOCommon *output,
93 io_ddata_t *data,
94 io_ddata_t *ioData,
95 io_ddata_t *outputData,
96 bool &initsample) override;
97
98private:
99 std::atomic<uint32_t> minRaw;
100 std::atomic<uint32_t> maxRaw;
101 bool hasMin;
102 bool hasMax;
103
105
106 template<typename T>
107 void clamp(io_ddata_t *data, io_ddata_t *outputData, T lo, T hi);
108};
109} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:30
Base class for callback-driven sample processing Program objects.
Definition process.hxx:28
CProgProcess(CDescObject &desc)
Construct a a Program from descriptor.
Definition process.hxx:53
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
Definition process.hxx:35
Saturating limiter: clamps input samples into a [min, max] range.
Definition saturate.hxx:25
@ PROG_SATURATE_CFG_MAX
Upper bound.
Definition saturate.hxx:30
@ PROG_SATURATE_CFG_MIN
Lower bound.
Definition saturate.hxx:29
void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)
Process incoming sample.
Definition saturate.cxx:119
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
Definition saturate.cxx:73
bool isBatchAware() const
Whether handle() consumes every batch of a batched source.
Definition saturate.hxx:87
int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
Definition saturate.cxx:37
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