35#define AI_MAX_CLASSES (8u)
36#define AI_MAX_LABEL_LEN (16u)
99#define AI_PARALLEL_MIC (255)
105#define AI_PARALLEL_ROOM (254)
106#define AI_PARALLEL_INTRUDER (253)
109#define AI_PARALLEL_ALL (252)
115#define AI_PARALLEL_FIRST AI_PARALLEL_ALL
123#if defined(MODEL_LINK_SET_MIC)
124_Static_assert(
AI_PARALLEL_ALL == MODEL_LINK_SET_ALL,
"set index drift");
127_Static_assert(
AI_PARALLEL_MIC == MODEL_LINK_SET_MIC,
"set index drift");
291static inline int ai_result_top_positive(
const ai_result_t *r, uint8_t *which)
293 if (which != NULL) { *which = 1u; }
294 if ((r == NULL) || (r->
class_count < 2u)) {
return 0; }
295 float best = r->
scores[1];
300 if (r->
scores[c] > best) { best = r->
scores[c]; arg = c; }
302 if (which != NULL) { *which = arg; }
303 int pct = (int)(best * 100.0f + 0.5f);
304 if (pct < 0) { pct = 0; }
305 if (pct > 100) { pct = 100; }
#define AI_MAX_CLASSES
Definition ai_engine.h:35
uint32_t ai_engine_dyn_capacity(void)
#define AI_PARALLEL_ROOM
Definition ai_engine.h:105
#define AI_PARALLEL_INTRUDER
Definition ai_engine.h:106
#define AI_PARALLEL_MIC
Definition ai_engine.h:99
int ai_engine_register(const ai_model_desc_t *desc)
#define AI_PARALLEL_ALL
Definition ai_engine.h:109
ai_sensor_t
Definition ai_engine.h:39
@ AI_SENSOR_IMU
Definition ai_engine.h:40
@ AI_SENSOR_RADAR
Definition ai_engine.h:41
@ AI_SENSOR_MIC
Definition ai_engine.h:42
uint32_t ai_engine_dyn_count(void)
uint32_t ai_engine_init_returns(void)
Model init() calls that RETURNED; always read as the pair.
int32_t ai_engine_last_init_rc(void)
Return code of the last model init(): 0x7FFFFFFF = never called; 0 = ok.
uint32_t ai_engine_feeds(void)
Samples accepted by the model; take the delta over at least 1 s.
uint32_t ai_engine_inits(void)
Successful model initialisations; a packed nibble in the heartbeat word.
uint32_t ai_engine_dq_ok(void)
Successful dequeues; frozen while dq_calls climbs = NPU stall.
uint32_t ai_engine_init_calls(void)
Model init() calls entered; read together with ai_engine_init_returns().
uint64_t ai_engine_npu_cycles(void)
NPU cycles accumulated so far; not proof any inference completed.
uint32_t ai_engine_dq_calls(void)
Dequeue attempts; pair with ai_engine_dq_ok() for stall detection.
uint32_t ai_engine_stale_drops(void)
Verdicts discarded past the Ethos-U wait bound; must stay flat while npu_cycles advances.
int ai_engine_active(void)
The LOADED model (s_current), or -1; lags requested by a cold-init window.
uint32_t ai_engine_stack_free_words(void)
All-time minimum of unused stack words; O(stack) scan — read at ~1 Hz at most.
int ai_engine_requested(void)
The REQUESTED model (s_active), or -1; the correct guard for a fallback.
uint32_t ai_engine_stack_words(void)
Stack the inference task got, in words; 0 = engine never started — the universal gate.
void ai_engine_stop(void)
Stop the active model (idempotent); pair with a sensor-rate walk-down.
bool ai_engine_start(uint32_t index)
Activate a model (or set) by index and begin inferring; check the return.
bool ai_engine_init(void)
Create the inference task (idempotent); it must precede ai_engine_start().
bool ai_engine_snapshot(ai_result_t *out)
Copy the latest published result; last-writer-wins — not valid inside a set.
uint32_t ai_engine_mic_settle_pct(void)
Settle progress 0..100; only meaningful inside a set (100 otherwise).
bool ai_engine_mic_settling(void)
True while a parallel set is still filling its windows; verdicts are withheld.
uint32_t ai_engine_model_count(void)
How many models are registered; the count leads the rows.
const ai_model_desc_t * ai_engine_model(uint32_t index)
Registry entry, NULL if out of range — and NULL for a set pseudo-index.
bool ai_engine_snapshot_model(uint32_t index, ai_result_t *out)
One model's last verdict — the reader to use inside a parallel set.
void ai_engine_set_sensor_rate(uint32_t interval_ms)
Set the accelerometer feed interval; the only legal sender on s_rate_msg.
void ai_engine_resume_sensor(void)
Standalone resume of the default cadence; never back-to-back with a rate set.
uint32_t ai_engine_set_members(uint8_t *idx, uint32_t max)
Registry indices of the ACTIVE set's members; test each member's sensor.
uint32_t ai_engine_set_members_defined(uint32_t set_index, uint8_t *out, uint32_t max)
The explicit membership if defined, else 0 — the only ack for set_define.
uint32_t ai_engine_set_models(uint32_t set_index, uint8_t *idx, uint32_t max)
Members of any set, in registry order; explicit membership wins outright.
int ai_engine_set_define(uint32_t set_index, const uint8_t *members, uint32_t n)
Give a set an explicit run-time membership; task context, all-or-nothing.
const char * ai_engine_set_name(uint32_t set_index)
Human name for a set; NULL for a non-set index.
void ai_engine_unload(uint32_t idx)
Asynchronous unload request — refused unless the engine is idle.
uint32_t ai_engine_unload_done(void)
Cumulative count of completed unloads; read as a pair with refused.
uint32_t ai_engine_unload_refused(void)
Cumulative count of refused unloads; read with ai_engine_unload_done().
Definition ai_engine.h:46
uint8_t class_count
Definition ai_engine.h:50
const char * name
Definition ai_engine.h:47
const char * class_labels[AI_MAX_CLASSES]
Definition ai_engine.h:61
uint16_t period_ms
Definition ai_engine.h:63
const char * description
Definition ai_engine.h:48
int(*) dequeue(float *out)
Definition ai_engine.h:70
ai_sensor_t sensor
Definition ai_engine.h:49
uint32_t flash_bytes
Definition ai_engine.h:62
void(*) finalize(void)
Definition ai_engine.h:71
int(*) init(void)
Definition ai_engine.h:68
int(*) enqueue(const float *in)
Definition ai_engine.h:69
Definition ai_engine.h:75
uint32_t inference_us
Definition ai_engine.h:81
uint32_t seq
Definition ai_engine.h:84
uint8_t running
Definition ai_engine.h:79
uint8_t class_count
Definition ai_engine.h:77
uint8_t model_index
Definition ai_engine.h:76
uint8_t top_class
Definition ai_engine.h:78
float scores[AI_MAX_CLASSES]
Definition ai_engine.h:80
uint32_t inference_us_max
Definition ai_engine.h:82
uint32_t inferences
Definition ai_engine.h:83