/*
 *  Copyright (c) 1996-2007 Digi International Inc., All Rights Reserved
 *
 *  This software contains proprietary and confidential information of Digi
 *  International Inc.  By accepting transfer of this copy, Recipient agrees
 *  to retain this software in confidence, to prevent disclosure to others,
 *  and to make no use of this software other than that for which it was
 *  delivered.  This is an unpublished copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 */

#ifndef _IOP_PRIVATE_H
#define _IOP_PRIVATE_H

#include <iop_api.h>
#include <iohub_reg.h>

#ifdef __cplusplus
extern "C"
{
#endif

#define NA_IOP_INTTOPIC_MASK        0x7F00
#define IOP_DMA_INDEX_MASK          (IOP_MAX_DMA_DESCRIPTORS - 1)

// #define IOP_DONT_WANT_SEMAPHORE_OVERHEAD

#ifndef IOP_DONT_WANT_SEMAPHORE_OVERHEAD
  #define IOP_GET_SEM(a)  naIopGetSemaphore(a)
  #define IOP_PUT_SEM(a)  naIopPutSemaphore(a)
#else
  #define IOP_GET_SEM(a)  
  #define IOP_PUT_SEM(a)  
#endif

#define IOP_IS_PROCESSOR_TYPE_VALID(t) ((t == NA_IOP_NS9215) /* || (t == ADD_NEW_ONE_HERE) */) 
#define IOP_IS_FORMAT_VALID(f)         ((f == NA_IOP_FORMAT_0) /* || (f == ADD_NEW_ONE_HERE) */) 

#define IOP_DMA_RX_MASK  (NA_IOHUB_IFS_RXNCIP_MASK | NA_IOHUB_IFS_RXNRIP_MASK | NA_IOHUB_IFS_RXECIP_MASK | NA_IOHUB_IFS_RXCAIP_MASK)
#define IOP_DMA_TX_MASK  (NA_IOHUB_IFS_TXNCIP_MASK | NA_IOHUB_IFS_TXNRIP_MASK | NA_IOHUB_IFS_TXECIP_MASK | NA_IOHUB_IFS_TXCAIP_MASK)

typedef struct iop_sem_cb_t
{
    NaIopSemaphoreFn_t getSem;
    NaIopSemaphoreFn_t putSem;
    void *context;
} iop_sem_cb_t;


typedef struct iop_isr_cb_t
{
    NaIopIsrCallback_t cb_f;
    void *context;
    int enabled;
} iop_isr_cb_t;


typedef struct iop_bdp_t
{
    void *src_addr;
    uint32 length;
    uint32 dst_addr; /* as reserved in camry */

#define DMA_WRAP    (1 << 15)
#define DMA_INT     (1 << 14)
#define DMA_LAST    (1 << 13)
#define DMA_FULL    (1 << 12)

#ifdef _LITTLE_ENDIAN
    uint16 status;
	uint16 flags; /* control */
#else
	uint16 flags; /* control */
	uint16 status;
#endif
} iop_bdp_t;

typedef struct iop_dma_cb_t 
{
    NaIopDmaCallback_t cb_f;
    unsigned           buf_len;   /* original length, before DMA picks up */
    void               *context;    
} iop_dma_cb_t;

typedef struct iop_dma_t
{
    iop_bdp_t       *tx_bd;
    iop_bdp_t       *rx_bd;
    iop_dma_cb_t    tx_cb[IOP_MAX_DMA_DESCRIPTORS];
    iop_dma_cb_t    rx_cb[IOP_MAX_DMA_DESCRIPTORS];
    unsigned        tx_first_idx;  /* to return user tx buffer */
    unsigned        tx_free_idx;   /* to place user tx buffer  */
    unsigned        rx_first_idx;  /* to return user rx buffer */
    unsigned        rx_free_idx;   /* to place user rx buffer  */
} iop_dma_t;

#ifdef __cplusplus
}
#endif

#endif
