6#include "dawn/io/limits.hxx"
14static size_t limitsDtypeSize(uint8_t dtype)
20 return sizeof(uint32_t);
26 return sizeof(uint32_t);
32static size_t limitsWordsPerValue(uint8_t dtype)
34 size_t dsize = limitsDtypeSize(dtype);
40int CIOLimits::bind(uint8_t
id, uint8_t dtype,
size_t words,
const uint32_t *data)
42 if (data ==
nullptr || words == 0)
54 if (nWords != words || cfgDtype != dtype)
95 if (data ==
nullptr || minData ==
nullptr || maxData ==
nullptr || stepData ==
nullptr)
100 if (dtype != cfgDtype)
110 step_words = limitsWordsPerValue(dtype);
111 if (step_words == 0 || words % step_words != 0)
116 items = words / step_words;
118 for (i = 0; i < items; i++)
122#if defined(CONFIG_DAWN_DTYPE_BOOL) || defined(CONFIG_DAWN_DTYPE_UINT8) || \
123 defined(CONFIG_DAWN_DTYPE_UINT16) || defined(CONFIG_DAWN_DTYPE_UINT32) || \
124 defined(CONFIG_DAWN_DTYPE_CHAR)
125# ifdef CONFIG_DAWN_DTYPE_BOOL
128# ifdef CONFIG_DAWN_DTYPE_UINT8
131# ifdef CONFIG_DAWN_DTYPE_UINT16
134# ifdef CONFIG_DAWN_DTYPE_UINT32
137# ifdef CONFIG_DAWN_DTYPE_CHAR
145 size_t off = i * step_words;
150 step = stepData[off];
152 if (v < min || v > max)
157 if (step > 0 && ((v - min) % step) != 0)
166#if defined(CONFIG_DAWN_DTYPE_INT8) || defined(CONFIG_DAWN_DTYPE_INT16) || \
167 defined(CONFIG_DAWN_DTYPE_INT32)
168# ifdef CONFIG_DAWN_DTYPE_INT8
171# ifdef CONFIG_DAWN_DTYPE_INT16
174# ifdef CONFIG_DAWN_DTYPE_INT32
185 size_t off = i * step_words;
187 std::memcpy(&v, &data[i],
sizeof(v));
189 std::memcpy(&min32, &minData[off],
sizeof(min32));
190 std::memcpy(&max32, &maxData[off],
sizeof(max32));
191 std::memcpy(&step32, &stepData[off],
sizeof(step32));
196 if (v < min || v > max)
201 if (step > 0 && ((v - min) % step) != 0)
210#if defined(CONFIG_DAWN_DTYPE_B16) || defined(CONFIG_DAWN_DTYPE_UB16)
211# ifdef CONFIG_DAWN_DTYPE_B16
214# ifdef CONFIG_DAWN_DTYPE_UB16
222 size_t off = i * step_words;
224 std::memcpy(&v, &data[i],
sizeof(v));
225 std::memcpy(&min, &minData[off],
sizeof(min));
226 std::memcpy(&max, &maxData[off],
sizeof(max));
227 std::memcpy(&step, &stepData[off],
sizeof(step));
229 if (v < min || v > max)
234 if (step > 0 && ((v - min) % step) != 0)
243#ifdef CONFIG_DAWN_DTYPE_FLOAT
252 size_t off = i * step_words;
259 if (v < min || v > max)
266 rem = std::fmod(v - min, step);
269 if (!(std::fabs(rem) <= eps || std::fabs(rem - step) <= eps))
bool isConfigured() const
Check whether any limits are configured.
int validate(const uint32_t *data, size_t words, uint8_t dtype) const
Validate payload against configured limits.
@ CFG_LIMIT_STEP
Step limit words.
@ CFG_LIMIT_MIN
Minimum limit words.
@ CFG_LIMIT_MAX
Maximum limit words.
int bind(uint8_t id, uint8_t dtype, size_t words, const uint32_t *data)
Bind one limit config item.
static float cfgToF(ObjectCfgData_t x)
Convert ObjectCfgData_t to float.
Out-of-tree user-extension hooks for Dawn.
EObjectDataType
Data types supported by Dawn framework.
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
@ DTYPE_ANY
Wildcard data type (matches any actual type).
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
@ DTYPE_UB16
Unsigned 16.16 fixed-point (32-bit).
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
@ DTYPE_B16
Signed 16.16 fixed-point (32-bit).
static int getDtypeSize_(const EObjectDataType dtype)
Get byte size for a specific data type.