/*
********************************************************************************
*       COPYRIGHT (c)                                 ERICSSON AB,  2005     --
*                                                                            --
*       The  copyright  to  the document(s)  herein  is  the property of     --
*       Ericsson Mobile Platforms, Sweden.                                   --
*                                                                            --
*       The document(s) may be used  and/or copied only with the written     --
*       permission from Ericsson Mobile Platforms or in accordance           --
*       with the terms and conditions stipulated in the agreement/contract   --
*       under which the document(s) have been supplied.                      --
********************************************************************************
* Functions and type declarations for epausb wrapper dll in use with meflash. --
********************************************************************************
*/

#ifdef EPAUSB_EXPORTS
#define EPIXUSB_API __declspec(dllexport)
#else
#define EPIXUSB_API __declspec(dllimport)
#endif


typedef enum
{
  USB_OK                       = 0,
  USB_ALREADY_OPENED           = 500,
  USB_NOT_OPENED               = 501,
  USB_EVENT_UNKNOWN            = 502,
  USB_EVENT_NOT_REGISTERED     = 503,
  USB_EVENT_ALREADY_REGISTERED = 504,
  USB_PORT_IS_OPEN             = 1000,
  USB_OPEN_FAILED              = 1001,
  USB_PORT_IN_USE              = 1002,
  USB_PORT_NOT_VALID           = 1003,
  USB_NO_FREE_INDEX            = 1005,
  USB_PORT_CLOSE_FAIL          = 1006,
  USB_PORT_NOT_OPEN            = 1007,
  USB_FAIL                     = 1008,
  USB_BUFFER_FULL              = 1009,
  USB_CHANNEL_NOT_SUPPORTED    = 1010,
  USB_LOCKFAIL                 = 1011,
  USB_INPARAM_NULL             = 1012,
  USB_SIZEZERO                 = 1013,
  USB_TIMEOUT                  = 1014,
  USB_INTERNAL_ERROR           = 5000
};
typedef long ErrorCode_t;

typedef enum
{
  EVENT_CONNECT = 0,
  EVENT_RXDATA = 1,
  EVENT_DISCONNECT = 2,
  EVENT_LAST = 3 // Must be the last one and the number must be one less than number of events in the enum (incl. EVENT_LAST).
};
typedef long CallbackEvent_t;

typedef long (CallbackFunc_t)(long, long, long);

extern EPIXUSB_API ErrorCode_t RegisterCallback(CallbackFunc_t*  const func_p, 
                                                 CallbackEvent_t eventtype);

extern EPIXUSB_API ErrorCode_t UnregisterCallback(CallbackEvent_t eventtype);

extern EPIXUSB_API ErrorCode_t OpenPort(int usbPort);
extern EPIXUSB_API ErrorCode_t ClosePort(int usbPort);

extern EPIXUSB_API ErrorCode_t DebugToggle(int usbPort);

extern EPIXUSB_API ErrorCode_t WriteBuff(int usbPort, 
                                          unsigned char* const buffer_p, 
                                          int size);

extern EPIXUSB_API ErrorCode_t GetRxBuffCount(int usbPort, int* const count_p);

extern EPIXUSB_API ErrorCode_t FlushRxBuff(int usbPort);

extern EPIXUSB_API ErrorCode_t GetRxBuff(int usbPort, 
                                          unsigned char* const buffer_p, 
                                          int* const buffsize_p);

extern EPIXUSB_API ErrorCode_t SetRxTimeout(int usbPort, int timeoutms);
extern EPIXUSB_API ErrorCode_t SetTxTimeout(int usbPort, int timeoutms);
extern EPIXUSB_API ErrorCode_t GetRxTimeout(int usbPort, int* const timeoutms);
extern EPIXUSB_API ErrorCode_t GetTxTimeout(int usbPort, int* const timeoutms);

extern EPIXUSB_API ErrorCode_t GetErrorString(ErrorCode_t statuscode, 
                                               const char** const str_pp);
