Dawn Framework 1.0
Universal data acquisition framework for embedded systems
counter.hxx
1// dawn/include/dawn/prog/counter.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9#include <inttypes.h>
10#include <vector>
11
12#include "dawn/io/sdata.hxx"
13#include "dawn/porting/config.hxx"
14#include "dawn/prog/common.hxx"
15
16namespace dawn
17{
18class CIOCommon;
19class io_ddata_t;
20
31{
32public:
33 enum
34 {
35 PROG_COUNTER_CFG_FIRST = 0,
36 PROG_COUNTER_CFG_IOBIND = 1,
37 PROG_COUNTER_CFG_PARAMS = 2,
38 PROG_COUNTER_CFG_LAST = 31
39 };
40
41 explicit CProgCounter(CDescObject &desc);
42 ~CProgCounter() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "counter";
48 }
49#endif
50
51 int configure() override;
52 int init() override;
53 int deinit() override;
54 int doStart() override;
55 int doStop() override;
56 bool hasThread() const override;
57 int trigger(uint8_t cmd) override;
58
59 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
60 {
62 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_COUNTER, SObjectId::DTYPE_ANY, 0, inst);
63 }
64
65 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t size, uint8_t id)
66 {
68 SObjectId::OBJTYPE_PROG, CProgCommon::PROG_CLASS_COUNTER, SObjectId::DTYPE_ANY, rw, size, id);
69 }
70
71 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size = 2)
72 {
73 return CProgCounter::cfgId(false, size, PROG_COUNTER_CFG_IOBIND);
74 }
75
76 constexpr static SObjectCfg::ObjectCfgId cfgIdParams(uint16_t size = 4)
77 {
78 return CProgCounter::cfgId(false, size, PROG_COUNTER_CFG_PARAMS);
79 }
80
81private:
82 struct SCounterBind
83 {
84 CProgCounter *owner;
85 SObjectId::ObjectId sourceId;
86 SObjectId::ObjectId outputId;
87 CIOCommon *source;
88 CIOCommon *output;
89 io_ddata_t *sourceData;
91 uint32_t prevInput;
92 };
93
94 std::vector<SCounterBind *> binds;
95 uint32_t countMin;
96 uint32_t countMax;
97 uint32_t countStep;
98 uint32_t countInit;
99 uint32_t count;
100 bool active;
101 bool registered;
102
103 static int ioNotifierCb(void *priv, io_ddata_t *data);
104
105 int configureDesc(const CDescObject &desc);
106 int allocBind(SObjectId::ObjectId sourceId, SObjectId::ObjectId outputId);
107 uint32_t readInput(SCounterBind *bind, io_ddata_t *data);
108 void writeCount(SCounterBind *bind);
109 void refresh(SCounterBind *bind, io_ddata_t *data);
110};
111} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
Base class for all PROG (processing) objects.
Definition common.hxx:27
Event counter with configurable wrap-around.
Definition counter.hxx:31
bool hasThread() const
Check if a background thread is active.
Definition counter.cxx:323
int configure()
Configure object from descriptor data.
Definition counter.cxx:153
int trigger(uint8_t cmd)
Execute a trigger command.
Definition counter.cxx:328
int doStart()
Start implementation hook.
Definition counter.cxx:270
int deinit()
De-initialize object.
Definition counter.cxx:199
int doStop()
Stop implementation hook.
Definition counter.cxx:304
int init()
One-time initialize object after bindings are resolved.
Definition counter.cxx:158
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
Static (compile-time) I/O data buffer (no timestamp).
Definition sdata.hxx:39