
#ifndef _DE2_DRV11J_REGS_H_
#define _DE2_DRV11J_REGS_H_

#include <io.h>


/*   GPIO register
 *  offset 0: Data (read/write)
 *  offset 1: Direction ( my not exit)
 *  offset 2: interrupt mask
 *  offset 3: edgecapture ( may not exit; Writing any value to edge capture
 *          : clear all bits to zero
 *  offset 4: outset (W) Specifis which bit of the output port to set
 *  offset 5: outclear(W) Specifies which output bit to clear
 */
/*
 * GPIO_DATIN configuration
 *
 */
/*
 * #define GPIO_SIGIN_BASE         0x1b020f0
 * #define GPIO_SIGOUT_BASE        0x1b02100
 * #define GPIO_DATIN_BASE         0x1b02140
 * #define GPIO_DATOUT_BASE        0x1b02150
 */

/* application protocol bits */
#define BIT_INTERRUPT0	   0
#define BIT_INTERRUPT1     1
#define BIT_SINGAL_ACK	   2
#define BIT_WRITE_READY    3
#define BIT_READ_READY     4
#define BIT_LISTEN		   5
#define BIT_HANDSHAKE	   7

#define DRJ_INTERRUPT0     ( 1 << BIT_INTERRUPT0 )
#define DRJ_INTERRUPT1     ( 1 << BIT_INTERRUPT1 )
#define DRJ_SIGNAL_ACK     ( 1 << BIT_SINGAL_ACK)
#define DRJ_WRITE_READY    ( 1 << BIT_WRITE_READY)
#define DRJ_READ_READY     ( 1 << BIT_READ_READY)
#define DRJ_LISTEN         ( 1 << BIT_LISTEN)
#define DRJ_HANDSHAKE      ( 1 << BIT_HANDSHAKE)

#define DRJ_SIGOUT        DRJ_HANDSHAKE
#define DRJ_SIGIN         DRJ_HANDSHAKE


#define GPIO_SIGNAL_IE    0xFF


#define DRJ_DEFAULT_BLOCKTIME    20    /* 20 milliseconds */
#define DEFAULT_TIMEOUT          200
#define CYCLES_PER_MS    	     500


#define IOC_SIGINTER_ENABLE        1
#define IOC_SIGINTER_DISABLE       2
#define IOC_READ_DATA              3
#define IOC_WRITE_DATA             4
#define IOC_TIMEOUT                5
#define IOC_SET_BLOCKTIME          6
#define IOC_GET_BLOCKTIME          7
#define IOC_SEND_SIGNAL            8
#define IOC_DRV_ATTACH             9
#define IOC_DRV_DETACH            10
#define IOC_RESET_BUFFER		  11



/* Drive side buffer size*/
#define GPIO_DRV11J_QUEUE_SIZE            8
#define GPIO_DRV11J_MAX_BUF_SIZE         256
/* upper layer buffer size*/
#define GPIO_CONFIG_TX_Q_LENGTH     GPIO_DRV11J_QUEUE_SIZE
#define GPIO_CONFIG_RX_Q_LENGTH     GPIO_DRV11J_QUEUE_SIZE

#define GPIO_SIGINTER_ENABLE       (('s'<<8)|IOC_SIGINTER_ENABLE)
#define GPIO_SIGINTER_DISABLE      (('s'<<8)|IOC_SIGINTER_DISABLE)
#define GPIO_READ_DATA             (('s'<<8)|IOC_READ_DATA)
#define GPIO_WRITE_DATA            (('s'<<8)|IOC_WRITE_DATA)
#define GPIO_SEND_SIGNAL           (('s'<<8)|IOC_SEND_SIGNAL)
#define GPIO_DRV_ATTACH            (('s'<<8)|IOC_DRV_ATTACH)
#define GPIO_DRV_DETACH            (('s'<<8)|IOC_DRV_DETACH)


/*
 *  Error code
 */
#define GPIO_ERROR_OK                 0
#define GPIO_INVALID_HANDLE           1
#define GPIO_INVALID_VALUE            2
#define GPIO_SYNC_ERROR               3
#define GPIO_TIMOUT                   4
#define GPIO_BAD_COMMAND              5

#define GPIO_ATTACH_ERROR            11
#define GPIO_DETACH_ERROR            12
#define GPIO_READ_FAILED             13
#define GPIO_WRITE_ERROR             14
#define GPIO_OPEN_DEVICE_ERROR       15

#endif //end of header file definition
