// Copyright 2025-2026 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <platform.h>
#include <xcore/channel.h>
#include <flash_server.h>

#include "inference.hpp"
#include "model.tflite.h"

static
void run(chanend_t c_flash) {
  // Model Init
  model_init((void*)c_flash);
  const size_t input_size = model_input_size(0);
  const size_t output_size = model_output_size(0);
  printf("Model input size: %zu\n", input_size);
  printf("Model output size: %zu\n", output_size);

  // Input Set
  int8_t* inputs = (int8_t*)model_input_ptr(0);
  memset(inputs, 10, input_size);

  // Invoke
  model_invoke();
}

// C wrapper for inferencer
void inference(chanend_t c_flash) {
  run(c_flash);
  chan_out_word(c_flash, FLASH_SERVER_QUIT);
}
