/** @file apci1696.h
 
   Contains defines and IOCTL commands of the APCI-1696.
 
   @par CREATION  
   @author Krauth Julien
   @date   06.06.05
   
   @par VERSION
   @verbatim
   $LastChangedRevision:$
   $LastChangedDate:$
   @endverbatim   
   
   @par COMPILER
   @verbatim
   Compiler	: gcc
   Version	: gcc (GCC) 3.3.6 (Debian 1:3.3.6-5)   
   kernel	: 2.4.26
   @endverbatim  
   
   @par UPDATES
   @verbatim
   Date			:
   Author		: 
   Description	: 
   @endverbatim    
    
   @par LICENCE
   @verbatim
   Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
  
         ADDI-DATA GmbH
         Dieselstrasse 3
         D-77833 Ottersweier
         Tel: +19(0)7223/9493-0
         Fax: +49(0)7223/9493-92
         http://www.addi-data-com
         info@addi-data.com
 
   This library is free software; you can redistribute it and/or modify it under 
   the terms of the GNU Lesser General Public License as published by the 
   Free Software Foundation; either version 2.1 of the License, 
   or (at your option) any later version.
 
   This library is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
   or FITNESS FOR A PARTICULAR PURPOSE. 
   See the GNU Lesser General Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public License 
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
   You also shoud find the complete LGPL in the LGPL.txt file accompanying 
   this source code.
   @endverbatim   
 */ 

#ifndef __APCI1696_H__
#define __APCI1696_H__


#define APCI1696_DRIVER_VERSION_MAJOR 2026
#define APCI1696_DRIVER_VERSION_MINOR 06
#define APCI1696_DRIVER_VERSION_PATCH 1

#include <apci.h>


//GENERAL DEFINE

#define APCI1696_BOARD_NAME                      "APCI1696"
#define APCI1696_BOARD_VENDOR_ID                 0x15B8
#define APCI1696_BOARD_DEVICE_ID                 0x100A

/**@enum PortName 
 * Can be used to indentify a port.
 */
enum PortName
{
	APCI1696_PORT0,
	APCI1696_PORT1,
	APCI1696_PORT2,
	APCI1696_PORT3,
	APCI1696_PORT4,
	APCI1696_PORT5,					
	APCI1696_PORT6,
	APCI1696_PORT7,
	APCI1696_PORT8,
	APCI1696_PORT9,
	APCI1696_PORT10,
	APCI1696_PORT11
};

/** number of ports of the board */ 
#define APCI1696_PORT_NUMBER (12)

/**@def APCI1696_PORT_INPUT_DIRCETION
 * Define the port direction as input port.
 */
#define APCI1696_PORT_INPUT_DIRECTION	(0)

/**@def APCI1696_PORT_OUTPUT_DIRCETION
 * Define the port direction as output port.
 */
#define APCI1696_PORT_OUTPUT_DIRECTION	(1)

/**@def APCI1696_READREG_1 
 * Read register offset (channel 0 - 31).
 */
#define APCI1696_READREG_1			0x08

/**@def APCI1696_READREG_2
 * Read register offset (channel 32 - 63).
 */
#define APCI1696_READREG_2			0x0C


/**@def APCI1696_READREG_3 
 * Read register offset (channel 64 - 95).
 */
#define APCI1696_READREG_3			0x10

/**@def APCI1696_WRITEREG_1 
 * Write register offset (channel 0 - 31).
 */
#define APCI1696_WRITEREG_1			0x14

/**@def APCI1696_WRITEREG_2 
 * Write register offset (channel 32 - 63).
 */
#define APCI1696_WRITEREG_2			0x18

/**@def APCI1696_WRITEREG_3
 * Write register offset (channel 64 - 95).
 */
#define APCI1696_WRITEREG_3			0x1C

/**@def APCI1696_CMDREG_1 
 * Command register offset (channel 0 - 31).
 */
#define APCI1696_CMDREG_1			0x20

/**@def APCI1696_CMDREG_2 
 * Command register offset (channel 32 - 63).
 */
#define APCI1696_CMDREG_2			0x24			

/**@def APCI1696_CMDREG_3 
 * Command register offset (channel 64 - 95).
 */
#define APCI1696_CMDREG_3			0x28


/**@struct DigitalPortsArg_t
 */
struct DigitalPortsArg_t
{
	unsigned char Port ; 
	unsigned char Value ;
} __attribute__ ((packed));


/* value used for CMD_APCI1696_CheckAndGetPCISlotNumber ! DEPRECATED ! */
#ifndef CONFIG_APCI1696_MAX_BOARD_NBR
#define CONFIG_APCI1696_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCI1696_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCI1696_MAX_BOARD_NBR CONFIG_APCI1696_MAX_BOARD_NBR

// IOCTL define part
#define APCI1696_MAGIC (char) 'Ü'

/**
 * @param (char*) area of size CONFIG_APCI1696_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCI1696_CheckAndGetPCISlotNumber   _IOR(APCI1696_MAGIC, 1,char*)

#define CMD_APCI1696_SetBoardInformation        _IOW(APCI1696_MAGIC, 2,USHORT)

/**
 * @deprecated
 */
#define CMD_APCI1696_GetHardwareInformation     _IOR(APCI1696_MAGIC, 3,str_BaseInformations*)




/** Initialize all digital ports of the APCI-1696.
 *
 * @param 			arg		Function argument. An array of 12 unsigned char that has to be initialized as following.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsSetting [0]: Port 0 (0: Input direction / 1: Output direction)
 *                          PortsSetting [11]: Port 11 (0: Input direction / 1: Output direction)
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -EINVAL	Port settings are incorrect.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_InitAllDigitalPorts			_IOW(APCI1696_MAGIC, 4, unsigned char *)

/** Get all digital ports settings of the APCI-1696.
 *
 * @param 			arg		Function argument. An array of 6 unsigned char that will contain ports settings.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsSetting [0]: Port 0 (0: Input direction / 1: Output direction)
 *                          PortsSetting [11]: Port 11 (0: Input direction / 1: Output direction)
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_GetAllDigitalPortsSetting		_IOR(APCI1696_MAGIC, 5, unsigned char *)

/** Initialize one port of the APCI-1696.
 *
 * 							CMD_APCI1696_Read1DigitalInput when using the IOCTL funktion.
 * @param 			arg		DigitalPortsArg_t
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -EINVAL	The port number or the initialization value is incorrect.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_InitDigitalPort				_IOW(APCI1696_MAGIC, 6, struct DigitalPortsArg_t *)

/** Get one port initialization of the APCI-1696.
 *
 * @param 			arg		DigitalPortsArg_t
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -EINVAL	The port number is incorrect.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_GetDigitalPortSetting			_IOWR(APCI1696_MAGIC, 7, struct DigitalPortsArg_t *)

/** Read all digital inputs of the APCI-1696.
 *
 * @param 			arg		Function argument. An array of 12 unsigned char that will contain ports states.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsSetting [0]: Port 0, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *                          PortsSetting [11]: Port 5, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board.
 */
#define CMD_APCI1696_ReadAllDigitalInputs			_IOR(APCI1696_MAGIC, 8, unsigned char *)


/** Set all digital outputs of the APCI-1696 on.
 *
 * @param 			arg		Function argument. An array of 12 unsigned char that has contain ports states.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsState [0]: Port 0, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *                          PortsState [11]: Port 5, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_SetAllDigitalOutputsOn			_IOW(APCI1696_MAGIC, 9, unsigned char *)

/** Set all digital outputs of the APCI-1696 off.
 *
 * @param 			arg		Function argument. An array of 12 unsigned char that contains ports states.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsState [0]: Port 0, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *                          PortsState [5]: Port 5, is composed of 8 channels. One channel can be 1 (high) or 0 (low).
 *
 * @retval 0		No error. 
 * @retval -EPERM	Output memory is not activated.
 * @retval -EFAULT	Bad address.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_SetAllDigitalOutputsOff		_IOW(APCI1696_MAGIC, 10, unsigned char *)

/** Set the digital output memory on.
 *
 * @param 			arg		Should be NULL.
 *
 * @retval 0		No error.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_SetDigitalOutputMemoryOn		_IO(APCI1696_MAGIC, 11)

/** Set the digital output memory off.
 *
 * @param 			arg		Should be NULL.
 *
 * @retval 0		No error.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_SetDigitalOutputMemoryOff		_IO(APCI1696_MAGIC, 12)

/** Get all digital outputs states of the APCI-1696.
 *
 * @param 			arg		Function argument. An array of 12 unsigned char that contain ports states.<br>
 *                          Each index of the array is a port e.g.:<br>
 *                          PortsState [0]: Port 0, is composed of 8 channels. One channel can be 1 (high) or 0 (low).  
 *                          PortsState [11]: Port 11, is composed of 8 channels. One channel can be 1 (high) or 0 (low). 
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Bad address.
 * @retval -ERESTARTSYS	Call has been interrupted while trying to get exclusive access to the board. 
 */
#define CMD_APCI1696_GetAllDigitalOutputsStates		_IOR(APCI1696_MAGIC, 13, unsigned char *) 




/** Used internally. This is the ioctl CMD with the highest number.
 * @internal
 */
#define __APCI1696_UPPER_IOCTL_CMD 13

#endif // __APCI1696_H__
