Question/Issue:
when i deploy c++ lib to my tdk-721x mcu, i allways get -22 error when call run_classifier. what can i do ?? i get nothing funcall log like get_signal_data\ei_read_timer_us\ei_read_timer_ms\ei_malloc\ei_free\ei_calloc\ei_sleep\ei_printf\ei_printf_float
my log like this:
[0065]bef
[0066][MEM] Free Heap: 6656 bytes | Min Ever Free: 6656 bytes
[0067]after
[0068][MEM] Free Heap: 6656 bytes | Min Ever Free: 6656 bytes
[0069]run_classifier returned: -22 len:588
[006a]Timing: DSP 0 ms, inference 0 ms, anomaly 0 ms
the functions all need define like this:
signal_t signal; // Wrapper for raw input buffer
ei_impulse_result_t result; // Used to store inference output
EI_IMPULSE_ERROR res; // Return code from inference
// Calculate the length of the buffer
// size_t buf_len = sizeof(input_buf) / sizeof(input_buf[0]);
if (buf_len == EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE) {
// Assign callback function to fill buffer used for preprocessing/inference
signal.total_length = EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE;
signal.get_data = &get_signal_data;
tlkapi_printf(APP_LOG_EN, "bef \n");
print_heap_info();
// Perform DSP pre-processing and inference
res = run_classifier(&signal, &result, true);
tlkapi_printf(APP_LOG_EN, "after \n");
print_heap_info();
// Print return code and how long it took to perform inference
tlkapi_printf(APP_LOG_EN, "run_classifier returned: %d len:%d\n", res, buf_len);
tlkapi_printf(APP_LOG_EN, "Timing: DSP %d ms, inference %d ms, anomaly %d ms\n",
result.timing.dsp,
result.timing.classification,
result.timing.anomaly);
static int get_signal_data(size_t offset, size_t length, float *out_ptr) {
tlkapi_printf(APP_LOG_EN, “get_signal_data:\n”);
for (size_t i = 0; i < length; i++) {
out_ptr[i] = (input_buf + offset)[i];
// tlkapi_printf(APP_LOG_EN, "input_buf %f\n", out_ptr[i]);
}
return EIDSP_OK;
}
uint64_t ei_read_timer_us()
{
tlkapi_printf(APP_LOG_EN, “ei_read_timer_us:\n”);
static uint64_t us_base = 0;
static uint32_t last_tick = 0;
uint32_t cur_tick = clock_time();
if (cur_tick < last_tick) {
us_base += ((uint64_t)1 << 32) / 24;
}
last_tick = cur_tick;
return us_base + (cur_tick / 24);
return 0;
}
uint64_t ei_read_timer_ms()
{
tlkapi_printf(APP_LOG_EN, “ei_read_timer_ms:\n”);
return ei_read_timer_us()/1000;
// return 0;
}
#ifdef __cplusplus
extern “C” {
#endif
extern void vPortFree(void *pv);
extern void *pvPortMalloc(size_t xWantedSize);
#ifdef __cplusplus
}
#endif
void* ei_malloc(size_t size) {
tlkapi_printf(APP_LOG_EN, “ei_malloc \n”);
return pvPortMalloc(size);
}
void ei_free(void* ptr) {
tlkapi_printf(APP_LOG_EN, “ei_free \n”);
vPortFree(ptr);
}
void* ei_calloc(size_t n, size_t size) {
tlkapi_printf(APP_LOG_EN, “ei_calloc \n”);
void* p = ei_malloc(n * size);
if(p)
memset(p, 0, n * size);
return p;
}
EI_IMPULSE_ERROR ei_sleep(
int32_t time_ms
)
{
tlkapi_printf(APP_LOG_EN, “ei_sleep \n”);
vTaskDelay(pdMS_TO_TICKS(time_ms));
}
attribute((weak)) void ei_printf(const char* format, …)
{
tlkapi_printf(APP_LOG_EN, “ei_printf \n”);
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
void ei_printf_float(
float f
)
{
tlkapi_printf(APP_LOG_EN, “ei_printf_float %f\n”, f);
}