Dawn Framework 1.0
Universal data acquisition framework for embedded systems
limits.hxx
1// dawn/include/dawn/io/limits.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstddef>
9#include <cstdint>
10
11#include "dawn/common/object.hxx"
12#include "dawn/porting/config.hxx"
13
14namespace dawn
15{
24{
25public:
30 enum
31 {
35 };
36
42 {
43 reset();
44 }
45
50 void reset()
51 {
52#ifdef CONFIG_DAWN_IO_LIMITS
53 minData = nullptr;
54 maxData = nullptr;
55 stepData = nullptr;
56 nWords = 0;
57 cfgDtype = SObjectId::DTYPE_ANY;
58#endif
59 }
60
71 int bind(uint8_t id, uint8_t dtype, size_t words, const uint32_t *data);
72
77 bool isConfigured() const
78 {
79#ifdef CONFIG_DAWN_IO_LIMITS
80 return nWords > 0;
81#else
82 return false;
83#endif
84 }
85
95 int validate(const uint32_t *data, size_t words, uint8_t dtype) const;
96
101 const uint32_t *getMin() const
102 {
103#ifdef CONFIG_DAWN_IO_LIMITS
104 return minData;
105#else
106 return nullptr;
107#endif
108 }
109
114 const uint32_t *getMax() const
115 {
116#ifdef CONFIG_DAWN_IO_LIMITS
117 return maxData;
118#else
119 return nullptr;
120#endif
121 }
122
127 const uint32_t *getStep() const
128 {
129#ifdef CONFIG_DAWN_IO_LIMITS
130 return stepData;
131#else
132 return nullptr;
133#endif
134 }
135
140 size_t getWords() const
141 {
142#ifdef CONFIG_DAWN_IO_LIMITS
143 return nWords;
144#else
145 return 0;
146#endif
147 }
148
149private:
150#ifdef CONFIG_DAWN_IO_LIMITS
151 const uint32_t *minData;
152 const uint32_t *maxData;
153 const uint32_t *stepData;
154 size_t nWords;
155 uint8_t cfgDtype;
156#endif
157};
158
159#ifndef CONFIG_DAWN_IO_LIMITS
164inline int CIOLimits::bind(uint8_t id, uint8_t dtype, size_t words, const uint32_t *data)
165{
166 (void)id;
167 (void)dtype;
168 (void)words;
169 (void)data;
170 return OK;
171}
172
177inline int CIOLimits::validate(const uint32_t *data, size_t words, uint8_t dtype) const
178{
179 (void)data;
180 (void)words;
181 (void)dtype;
182 return OK;
183}
184#endif
185} // Namespace dawn
Common IO runtime limits container and validator.
Definition limits.hxx:24
size_t getWords() const
Get configured limit array size in words.
Definition limits.hxx:140
bool isConfigured() const
Check whether any limits are configured.
Definition limits.hxx:77
const uint32_t * getMax() const
Get maximum limit words pointer.
Definition limits.hxx:114
const uint32_t * getStep() const
Get step limit words pointer.
Definition limits.hxx:127
int validate(const uint32_t *data, size_t words, uint8_t dtype) const
Validate payload against configured limits.
Definition limits.hxx:177
CIOLimits()
Construct empty limits.
Definition limits.hxx:41
@ CFG_LIMIT_STEP
Step limit words.
Definition limits.hxx:34
@ CFG_LIMIT_MIN
Minimum limit words.
Definition limits.hxx:32
@ CFG_LIMIT_MAX
Maximum limit words.
Definition limits.hxx:33
const uint32_t * getMin() const
Get minimum limit words pointer.
Definition limits.hxx:101
int bind(uint8_t id, uint8_t dtype, size_t words, const uint32_t *data)
Bind one limit config item.
Definition limits.hxx:164
void reset()
Reset all configured limits.
Definition limits.hxx:50
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68