/*
 * sav_init.h
 *
 *  Created on: 04 March 2020
 *      Author: lx
 */

#ifndef SAV_INIT_H_
#define SAV_INIT_H_

#include <stdint.h>
#include "lwipopts.h"

#define MEMP_SAV_MSG_API     8

/**
 * SAV_THREAD_NAME: The name assigned to the main sav thread.
 */
#if !defined SAV_THREAD_NAME || defined __DOXYGEN__
#define SAV_THREAD_NAME              "sav_thread"
#endif

#define SAV_MBOX_SIZE                 64
#define SAV_THREAD_STACKSIZE	      2048
#define SAV_THREAD_PRIO	              (DEFAULT_THREAD_PRIO + 5)


typedef void (*sav_callback_fn)(uint16_t, void *ctx);
typedef bool (*sav_tx_callback_fn) (void);
typedef	void(*enable_trans_callback_fn) (void);

enum sav_msg_type {
  SAV_TRANSMIT_CALLBACK,

  SAV_RECEIVE_CALLBACK
};

struct trans_savif
{
    sav_tx_callback_fn sav_tx_enabled;
  	enable_trans_callback_fn enable_ready_to_transfer;
};


struct sav_msg {
  enum sav_msg_type type;
  uint16_t length;
  sav_callback_fn function;

  void *ctx;
};

void set_trans_interface(struct trans_savif *trans_sav_intf);
void sav_init(void);
int8_t sav_callback_with_block(uint8_t, sav_callback_fn, uint16_t, void *, uint8_t);

#endif /* SAV_INIT_H_ */
