 /* @file apci3001.h
  * 
  * @brief Define the public API for the apci3001 ADDI-DATA board. 
  * 
  *
  */

/** @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 __APCI3001_H__
#define __APCI3001_H__


#define APCI3001_DRIVER_VERSION_MAJOR 2026
#define APCI3001_DRIVER_VERSION_MINOR 06
#define APCI3001_DRIVER_VERSION_PATCH 1

#include <apci.h>

//GENERAL DEFINE

#define APCI3001_BOARD_NAME                      "apci3001"
#define APCI3001_BOARD_VENDOR_ID                 0x10E8
#define APCI3001_BOARD_DEVICE_ID                 0x828D


#define APCI3001_1_GAIN                           0x00
#define APCI3001_2_GAIN                           0x10
#define APCI3001_5_GAIN                           0x20
#define APCI3001_10_GAIN                          0x30

#define APCI3001_BIPOLAR                          0x00
#define APCI3001_UNIPOLAR                         0x80

#define APCI3001_DISABLE                         0
#define APCI3001_ENABLE                          1

#define  APCI3001_CHANNEL_0	0
#define  APCI3001_CHANNEL_1	1
#define  APCI3001_CHANNEL_2	2
#define  APCI3001_CHANNEL_3	3
#define  APCI3001_CHANNEL_4	4
#define  APCI3001_CHANNEL_5	5
#define  APCI3001_CHANNEL_6	6
#define  APCI3001_CHANNEL_7	7
#define  APCI3001_CHANNEL_8	8
#define  APCI3001_CHANNEL_9	9
#define  APCI3001_CHANNEL_10	10
#define  APCI3001_CHANNEL_11	11
#define  APCI3001_CHANNEL_12	12
#define  APCI3001_CHANNEL_13	13
#define  APCI3001_CHANNEL_14	14
#define  APCI3001_CHANNEL_15	15


/* value used for CMD_APCI3001_CheckAndGetPCISlotNumber ! DEPRECATED ! */
#ifndef CONFIG_APCI3001_MAX_BOARD_NBR
#define CONFIG_APCI3001_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCI3001_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCI3001_MAX_BOARD_NBR CONFIG_APCI3001_MAX_BOARD_NBR

// IOCTL define part
#define APCI3001_MAGIC (char) 'A'

/**
 * @param (char*) area of size CONFIG_APCI3001_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCI3001_CheckAndGetPCISlotNumber   _IOR(APCI3001_MAGIC, 1,char*)

#define CMD_APCI3001_SetBoardInformation        _IOW(APCI3001_MAGIC, 2,USHORT)

/**
 * @deprecated
 */
#define CMD_APCI3001_GetHardwareInformation     _IOR(APCI3001_MAGIC, 3,str_BaseInformations*)

/** Read 1 analog input channel.
 * 
 * This function call all kapi functions to read 1 analog input channel.
 * It can be possible to use separate functions to do that once they are
 * implemented.                                                  
 * 
 * @param [in] pdev								: The device to initialize.
 * @param [in] arg[0] (b_Channel)				: Number of the analog input to be read. 
 * @param [in] arg[1] (b_Gain)					: Gain selection.
 * @param [in] arg[2] (b_Polarity)				: Selection of the input voltage range of the analog input to convert.
 * @param [in] arg[3] (ui_ConvertinTiming)		: Selection of the conversion time from 10�s to 32767�s.
 * @param [in] arg[4] (b_InterruptFlag)			: This parameter has to be 0 or PCI3001_DISABLE.<br> 
 * 																The interrupt is not implemeted!
 * @param [out] arg[0] (ui_AnalogInputValue)	: The analog value.
 * 
 * @retval 0: No error.                                        
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: Number of the analog input is wrong.
 * @retval 3: The selected gain is wrong.
 * @retval 4: The selected input voltage range is wrong.
 * @retval 5: The selected conversion time is wrong.
 * @retval 6: A wrong parameter has been passed for <br>
 *				b_InterruptFlag or the user interrupt routine has <br>
 *				not been installed.
 * @retval 7: Time out.    
 * @retval -EFAULT : Fail to retrieve user data.           
 */				
#define CMD_APCI3001_Read1AnalogInput			_IOWR(APCI3001_MAGIC, 4, UINT*)

/** Read more analog input channel.
 * 
 * This function call all kapi functions to read more analog input channel.
 * 
 * @param [in] pdev					: The device to initialize.
 * @param [in]	arg[0] (b_SequenzArraySize)		: Size of the sequence array (1 to 16 elements).
 * @param [in]	arg[1] (pb_ChannelArray)		: Channels to read (array size = b_SequenzArraySize).
 * @param [in]	arg[...] (pb_GainArray)			: Gain selection array.
 * @param [in]	arg[...] (pb_PolarityArray)		: Selection of the input.
 * @param [in]	arg[...] (ui_ConvertTiming)		: Selection of the conversion time from 10 to 32767 us.
 * @param [in]	arg[...] (b_InterruptFlag)		: This parameter has to be 0 or PCI3001_DISABLE.<br> 
 * 																The interrupt is not implemeted!
 *
 * @param [out]	arg[0...] (pui_AnalogInputValueArray)	: Read values.
 * 
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: The size of the sequence table is wrong.
 * @retval 3: Wrong parameter found in table "pb_ChannelArray".
 * @retval 4: Wrong parameter found in table "pb_GainArray".
 * @retval 5: Wrong parameter found in table "pb_PolarityArray".
 * @retval 6: The selected conversion time is wrong.
 * @retval 7: A wrong parameter has been passed for b_InterruptFlag.
 * @retval 8: Time out.
 * @retval -EFAULT : Fail to retrieve user data.
 */				
#define CMD_APCI3001_ReadMoreAnalogInputs			_IOWR(APCI3001_MAGIC, 5, UINT*)

#define CMD_APCI3001_InitReadMoreAnalogInput		_IOW(APCI3001_MAGIC, 6, UINT*)
#define CMD_APCI3001_StartReadMoreAnalogInput		_IOW(APCI3001_MAGIC, 7, UINT*)
#define CMD_APCI3001_TestEndOfReadMoreConversion	_IO(APCI3001_MAGIC, 8)
#define CMD_APCI3001_TestReadMoreAnalogInput		_IOW(APCI3001_MAGIC, 9, UINT*)
#define CMD_APCI3001_ReadMoreValues					_IOWR(APCI3001_MAGIC, 10, UINT*)

/** Read 4 digital input.
 * 
 * @param [in] pdev                       : The device to manage.
 * @param [out] arg (b_DigitalInputValue) : Digital input value.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval -EFAULT : Fail to retrieve user data.
 */
#define CMD_APCI3001_Read4DigitalInput				_IOW(APCI3001_MAGIC, 11, uint8_t*)

/** Set digital output memory on.
 *
 * When output memory is setting on. Output state is holding, and <br>
 * the new output(s) is(are) set or reset.
 *
 * @param [in] pdev                 : The device to manage.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 */
#define CMD_APCI3001_SetOutputMemoryOn				_IO(APCI3001_MAGIC, 12)

/** Set digital output memory off.
 *
 * @param [in] pdev                 : The device to manage.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 */
#define CMD_APCI3001_SetOutputMemoryOff				_IO(APCI3001_MAGIC, 13)

/** Set 4 digital output on.
 *
 * @param [in] pdev                       : The device to manage.
 * @param [in] arg (b_DigitalOutputValue) : Digital output value.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: The digital output value is wrong.
 */
#define CMD_APCI3001_Set4DigitalOutputOn				_IOW(APCI3001_MAGIC, 14, uint8_t)

/** Set 4 digital output off.
 *
 * Can only be used when i_APCI3001_SetOutputMemoryOn has been called.
 *
 * @param [in] pdev                 : The device to manage.
 * @param [in] arg (b_DigitalOutputValue) : Digital output value.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: The digital output value is wrong.
 * @retval 3: Output memory is not activated (please use i_APCI3001_SetOutputMemoryOn).
 */
#define CMD_APCI3001_Set4DigitalOutputOff				_IOW(APCI3001_MAGIC, 15, uint8_t)

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

#endif // __APCI3001_H__
