SDK for TESAIoT Dev Kit
API reference & tutorials (ModusToolbox)
Loading...
Searching...
No Matches
ai_model_staged.h
Go to the documentation of this file.
1#ifndef AI_MODEL_STAGED_H
2#define AI_MODEL_STAGED_H
3
4/* A model built at run time from bytes CM33 staged in shared memory.
5 *
6 * The loader accepts one pipeline shape: a fixed window slid over a sensor
7 * stream, quantized, inferred, dequantized. Motion models are that shape.
8 * Audio and radar models are not — their feature front ends are ordered code
9 * and coefficient tables that no .tflite carries — and the loader cannot
10 * detect the difference, so the limit is stated here rather than discovered
11 * as a wrong answer on screen. Load only IMU models; the checks below refuse
12 * the cases they can see.
13 *
14 * Each loaded model owns one slot, and slots are not reused within a boot: a
15 * descriptor a slot has published, and the strings it points at, stay valid
16 * for the life of the boot.
17 *
18 * The staging ABI — the manifest layout these bytes must follow — is
19 * ipc_model_stage_defs.h. */
20
21#include <stdbool.h>
22#include <stdint.h>
23
24/* How many staged models can be built in one boot. A slot is claimed for the
25 * life of the boot, exactly as a registry row is. */
26#define AI_STAGED_MAX (24u)
27
28/* Build a model from the manifest at `header_addr` and register it.
29 *
30 * Returns the new registry index, or a negative code:
31 * -1 bad manifest (magic, version, CRC, bounds, alignment, not TFL3)
32 * -2 no free slot, OR the registry refused the row — which it also does for
33 * a DUPLICATE MODEL NAME, so loading the same file twice looks exactly
34 * like hitting the ceiling
35 * -3 mtb_ml_model_init() failed — usually an arena too small for the model,
36 * but also plain CM55 heap exhaustion
37 * -4 sensor not supported by this loader (only IMU: window + quantize)
38 * -5 axis convention absent or not the one this firmware applies
39 * -6 training sample rate is not the rate this firmware can feed
40 * -7 frame width is not the six floats this firmware supplies. A
41 * nine-channel export satisfies every other check and then reads past
42 * the caller's stack array on every frame
43 *
44 * These are the LOADER's codes, reported by diag()['staged_last_rc']. Signature
45 * verdicts are a different namespace on a different field — stage_info()
46 * ['sig_rc'] — and deliberately do not overlap these values.
47 *
48 * Runs in TASK CONTEXT ONLY. It allocates from the CM55 heap that LVGL also
49 * draws from, and it takes a critical section. An IPC callback must queue this
50 * call, not make it. */
51int ai_model_staged_load(uint32_t header_addr);
52
53/* Counters, for diagnosis off-core. A refused load that looked like a
54 * completed one would make any staging measurement unreadable. */
55/* Free bytes on the CM55 heap, including unclaimed sbrk headroom. */
57
58uint32_t ai_model_staged_count(void);
61
62#endif /* AI_MODEL_STAGED_H */
uint32_t ai_model_staged_heap_free(void)
Free bytes on the CM55 heap; the one ISR-safe read on this topic.
uint32_t ai_model_staged_count(void)
Models built this boot — the ack-by-observation signal for staged_load.
int ai_model_staged_load(uint32_t header_addr)
Build and register a model CM33 staged in shared memory; task context only.
int32_t ai_model_staged_last_rc(void)
The loader's last return code (-1..-7, or the registry index on success).
uint32_t ai_model_staged_rejects(void)
Loads refused this boot; pair with ai_model_staged_last_rc().