14#include "dawn/io/ddata.hxx"
15#include "dawn/io/common.hxx"
16#include "dawn/porting/config.hxx"
17#include "dawn/prog/common.hxx"
18#include "dawn/prog/process.hxx"
29 PROG_THRESHOLD_CFG_MODE = 2,
30 PROG_THRESHOLD_CFG_LOW = 3,
31 PROG_THRESHOLD_CFG_HIGH = 4,
63 size_t &offset)
override
73 DAWNERR(
"threshold: invalid config size %u\n", item->
cfgid.
s.
size);
82 case PROG_THRESHOLD_CFG_MODE:
84 if (val > MODE_WINDOW)
86 DAWNERR(
"threshold: invalid mode %" PRIu32
"\n", val);
94 case PROG_THRESHOLD_CFG_LOW:
100 case PROG_THRESHOLD_CFG_HIGH:
119 bool &initsample)
override
125 DAWNERR(
"threshold: invalid output dtype %d for input dtype %d\n",
133#ifdef CONFIG_DAWN_DTYPE_INT8
136 handleTyped<int8_t>(output,
140 static_cast<int8_t
>(low),
141 static_cast<int8_t
>(high));
146#ifdef CONFIG_DAWN_DTYPE_UINT8
149 handleTyped<uint8_t>(output,
153 static_cast<uint8_t
>(low),
154 static_cast<uint8_t
>(high));
159#ifdef CONFIG_DAWN_DTYPE_INT16
162 handleTyped<int16_t>(output,
166 static_cast<int16_t
>(low),
167 static_cast<int16_t
>(high));
172#ifdef CONFIG_DAWN_DTYPE_UINT16
175 handleTyped<uint16_t>(output,
179 static_cast<uint16_t
>(low),
180 static_cast<uint16_t
>(high));
185#ifdef CONFIG_DAWN_DTYPE_INT32
188 handleTyped<int32_t>(output,
198#ifdef CONFIG_DAWN_DTYPE_UINT32
201 handleTyped<uint32_t>(output,
211#ifdef CONFIG_DAWN_DTYPE_INT64
214 handleTyped<int64_t>(output,
218 static_cast<int64_t
>(low),
219 static_cast<int64_t
>(high));
224#ifdef CONFIG_DAWN_DTYPE_UINT64
227 handleTyped<uint64_t>(output,
231 static_cast<uint64_t
>(low),
232 static_cast<uint64_t
>(high));
237#ifdef CONFIG_DAWN_DTYPE_FLOAT
246#ifdef CONFIG_DAWN_DTYPE_DOUBLE
249 handleTyped<double>(output,
261 DAWNERR(
"threshold: unsupported dtype %d\n", data->
getDtype());
267 virtual bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const = 0;
268 virtual int emitOutput(
CIOCommon *output,
278 std::vector<uint8_t> last;
282 bool evaluate(T x, T lowT, T highT, uint8_t prev)
const
293 return x >= lowT && x <= highT;
295 case MODE_HYSTERESIS:
314 void handleTyped(CIOCommon *output,
317 io_ddata_t *outputData,
323 std::memcpy(ioData->getDataPtr(), data->getDataPtr(), ioData->getDataSize());
326 SState &st = state[outputId];
327 const size_t items = ioData->getItems();
329 if (st.items != items || st.last.size() != items)
332 st.last.assign(items, 0);
335 for (
size_t i = 0; i < items; i++)
337 const uint8_t prev = st.last[i];
338 const T x = ioData->get<T>(i);
339 const bool out = evaluate(x, lowT, highT, prev);
341 st.last[i] = out ? 1 : 0;
344 this->alerts = st.last;
345 ret = emitOutput(output, data->getDtype(), items, ioData, outputData);
348 DAWNERR(
"threshold: emit failed %d\n", ret);
356 std::vector<uint8_t> alerts;
359 std::map<SObjectId::ObjectId, SState> state;
374#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
375 const char *getClassNameStr()
const override
404 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_MODE);
409 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_LOW);
414 return CProgThreshold::cfgId(
false, 1, PROG_THRESHOLD_CFG_HIGH);
418 bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const override
433 for (
size_t i = 0; i < items; i++)
435 outputData->
get<uint8_t>(i) = this->alerts[i];
438 return output->
setData(*outputData);
454#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
455 const char *getClassNameStr()
const override
457 return "thresholdvalue";
487 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_MODE);
492 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_LOW);
497 return CProgThresholdValue::cfgId(
false, 1, PROG_THRESHOLD_CFG_HIGH);
501 bool validateOutputDtype(uint8_t inputDtype, uint8_t outputDtype)
const override
503 return outputDtype == inputDtype;
514#ifdef CONFIG_DAWN_DTYPE_INT8
517 return emitOutputTyped<int8_t>(output, items, ioData, outputData);
521#ifdef CONFIG_DAWN_DTYPE_UINT8
524 return emitOutputTyped<uint8_t>(output, items, ioData, outputData);
528#ifdef CONFIG_DAWN_DTYPE_INT16
531 return emitOutputTyped<int16_t>(output, items, ioData, outputData);
535#ifdef CONFIG_DAWN_DTYPE_UINT16
538 return emitOutputTyped<uint16_t>(output, items, ioData, outputData);
542#ifdef CONFIG_DAWN_DTYPE_INT32
545 return emitOutputTyped<int32_t>(output, items, ioData, outputData);
549#ifdef CONFIG_DAWN_DTYPE_UINT32
552 return emitOutputTyped<uint32_t>(output, items, ioData, outputData);
556#ifdef CONFIG_DAWN_DTYPE_INT64
559 return emitOutputTyped<int64_t>(output, items, ioData, outputData);
563#ifdef CONFIG_DAWN_DTYPE_UINT64
566 return emitOutputTyped<uint64_t>(output, items, ioData, outputData);
570#ifdef CONFIG_DAWN_DTYPE_FLOAT
573 return emitOutputTyped<float>(output, items, ioData, outputData);
577#ifdef CONFIG_DAWN_DTYPE_DOUBLE
580 return emitOutputTyped<double>(output, items, ioData, outputData);
595 for (
size_t i = 0; i < items; i++)
597 if (this->alerts[i] != 0)
599 outputData->
get<T>(i) = ioData->
get<T>(i);
603 outputData->
get<T>(i) =
static_cast<T
>(0);
607 return output->
setData(*outputData);
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
@ CMD_RESET
Reset object internal state.
@ PROG_CLASS_THRESHOLD_VALUE
Threshold comparator returning gated source value.
@ PROG_CLASS_THRESHOLD
Threshold and hysteresis comparator.
Base class for callback-driven sample processing Program objects.
int trigger(uint8_t cmd)
Execute a trigger command.
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
Shared threshold logic for derived threshold programs.
int trigger(uint8_t cmd)
Execute a trigger command.
int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)
Process incoming sample.
Threshold comparator returning gated source values.
Threshold comparator returning boolean alert output.
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.
uint32_t ObjectCfgData_t
Configuration data element - single 32-bit word.
static float cfgToF(ObjectCfgData_t x)
Convert ObjectCfgData_t to float.
static uint32_t cfgToU32(ObjectCfgData_t x)
Convert ObjectCfgData_t to uint32_t.
static int32_t cfgtoi32(ObjectCfgData_t x)
Convert ObjectCfgData_t to int32_t.
Out-of-tree user-extension hooks for Dawn.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ OBJTYPE_PROG
Program/algorithm object type.
@ 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_UINT64
Unsigned 64-bit integer.
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
@ DTYPE_INT64
Signed 64-bit integer.
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
uint32_t ObjectId
ObjectID type - single 32-bit value.
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.
Heap-allocated dynamic I/O data buffer.
uint8_t getDtype() const
Get data type enum for introspection.
T & get(size_t index, size_t batch=0)
Get data element by index and batch (type-safe).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.