#ifndef TRBERROR_H
#define TRBERROR_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
  TRB_NONE = 0,
  TRB_TX_BUSY = 1,
  TRB_FIFO_NOT_EMPTY = 2,
  TRB_FIFO_TIMEOUT = 3,
  TRB_FIFO_HEADERS = 4,
  TRB_FIFO_SEQUENZ = 5,
  TRB_FIFO_INVALID_MODE = 6,
  TRB_FIFO_INCOMPLETE_PACKAGE = 7,
  TRB_FIFO_INVALID_HEADER = 8,
  TRB_FIFO_MISSING_TERM_HEADER = 9,
  TRB_FAILED_WAIT_IS_VALID = 10,
  TRB_FAILED_WAIT_IS_NOT_VALID = 11,
  TRB_USER_BUFFER_OVF = 12,
  TRB_INVALID_CHANNEL = 13,
  TRB_INVALID_PKG_NUMBER = 14,
  TRB_STATUS_ERROR = 15,
  TRB_INVALID_ADDRESS = 16,
  TRB_INVALID_LENGTH = 17,
  TRB_ENDPOINT_NOT_REACHED = 18,
  TRB_DMA_UNAVAILABLE = 19,
  TRB_DMA_TIMEOUT = 20,
  TRB_READMEM_INVALID_SIZE = 21,
  TRB_HDR_DLEN = 22,
  TRB_FIFO_INCOMPLETE = 23,
  TRB_SEMAPHORE = 24,
  TRB_FIFO_SHARED_MEM = 25,
  TRB_STATUS_WARNING = 26,
  TRB_RPC_ERROR = 27
} TRB_ERROR;

/* last TRBNet-TermPackage */
typedef struct {
  uint16_t status_common;
  uint16_t status_channel;
  uint16_t sequence;
  uint8_t channel;
} TRB_TERM;

extern int trb_errno;

extern TRB_TERM trb_term;

void trb_error(const char *s);

const char* trb_strerror();


const char* trb_errorstr(int trberrno);

const char* trb_termstr(TRB_TERM term);

#ifdef __cplusplus
}
#endif

#endif
