 /** @file apcie1564.h
  * 
  * @brief Define the public API for the apcie1564 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 __APCIE1564__H_
#define __APCIE1564__H_

/*
  +-----------------------------------------------------------------------+
  | (C) ADDI-DATA GmbH          Dieselstrasse 3      D-77833 Ottersweier  |
  +-----------------------------------------------------------------------+
  | Tel : +49 (0) 7223/9493-0     | email    : info@addi-data.com         |
  | Fax : +49 (0) 7223/9493-92    | Internet : http://www.addi-data.com   |
  +-----------------------------------------------------------------------+
  | Project   : API APCIE1564      | Compiler : mipsel-linux-gcc           |
  | Modulname : apcie1564.h        | Version  : 2.95.4                     |
  +-------------------------------+---------------------------------------+
  | Author    : LIBS Eric         | Date     : 03.09.2003                 |
  +-----------------------------------------------------------------------+
  |                   Description : APCIE1564 header                       |
  +-----------------------------------------------------------------------+
  |                             UPDATE'S                                  |
  +-----------------------------------------------------------------------+
  |   Date   |   Author  |          Description of updates                |
  +----------+-----------+------------------------------------------------+
  |          |           |                                                |
  +-----------------------------------------------------------------------+
*/
#define APCIE1564_DRIVER_VERSION_MAJOR 2026
#define APCIE1564_DRIVER_VERSION_MINOR 06
#define APCIE1564_DRIVER_VERSION_PATCH 1

#include <apci.h>

//GENERAL DEFINE

#define APCIE1564_BOARD_NAME                      "APCIE1564"
#define APCIE1564_BOARD_VENDOR_ID                 0x15B8
#define APCIE1564_BOARD_DEVICE_ID                 0x101A

#define CPCIS1564_BOARD_VENDOR_ID                 0x15B8
#define CPCIS1564_BOARD_DEVICE_ID                 0x101E


#ifndef CONFIG_APCIE1564_MAX_BOARD_NBR
#define CONFIG_APCIE1564_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCIE1564_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCIE1564_MAX_BOARD_NBR CONFIG_APCIE1564_MAX_BOARD_NBR

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

/**
 * @param (char*) area of size CONFIG_APCIE1564_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCIE1564_CheckAndGetPCISlotNumber   _IOR(APCIE1564_MAGIC, 1,char*)
#define CMD_APCIE1564_SetBoardInformation        _IOW(APCIE1564_MAGIC, 2,USHORT)
/**
 * @deprecated
 */
#define CMD_APCIE1564_GetHardwareInformation     _IOR(APCIE1564_MAGIC, 3,str_BaseInformations*)

/* DIGITAL INPUTS *******************************************************************/

/**
 * @param (uint32_t*) inputs
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 */
#define CMD_APCIE1564_Read32DigitalInput         _IOR(APCIE1564_MAGIC, 4,uint32_t*)

/* DIGITAL OUTPUTS ******************************************************************/

/**
 * @param (uint32_t*) outputs
 *
 * @return 0 on success, -1 on failure (see errno then)
 */
#define CMD_APCIE1564_Read32DigitalOutput        _IOR(APCIE1564_MAGIC, 9,uint32_t*)

/**
 * @param (uint32_t) outputs
 * 
 * @return 0 on success, -1 on failure (see errno then)
 */
#define CMD_APCIE1564_Set32DigitalOutputOn       _IOW(APCIE1564_MAGIC, 10,uint32_t)

/**
 * @param (uint32_t) outputs
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 */
#define CMD_APCIE1564_Set32DigitalOutputOff      _IOW(APCIE1564_MAGIC, 11,uint32_t)

/** Activates the digital output memory.
 * 
 * @param NULL
 * 
 * After calling up this function, the outputs you have previously activated 
 * with the function "i_ADDIDATA_SetXDigitalOutputOn" * are not reset. You can 
 * reset them with the function "i_ADDIDATA_SetXDigitalOutputOff".
 * 
 */
#define CMD_APCIE1564_SetOutputMemoryOn          _IOW(APCIE1564_MAGIC, 12,void*)

/** Deactivates the digital output memory.
 * 
 * @param arg None (Use NULL)
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_SetOutputMemoryOff         _IOW(APCIE1564_MAGIC, 13,void*)

/* DIGITAL INPUTS INTERRUPT ***********************************************************/

/** 
 * @param[in] arg struct {
 * 	int InterruptLogic;
 	uint32_t InterruptMaskMode1; TODO : 0x000FFFF0
	uint32_t InterruptMaskMode2; TODO : 0x000FFFF0
 * }
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_InitAndStartDigitalInputInterrupt   _IOW(APCIE1564_MAGIC, 14,void*)

/** 
 * 
 * @param arg None ( use NULL )
 * 
 * @return 0 on success, -1 on failure (see errno then)
 *  
 */
#define CMD_APCIE1564_ClearAndStopDigitalInputInterrupt   _IOW(APCIE1564_MAGIC, 15,void*)

/**
 * @param[in] arg struct {
 * 	int Enabled; 
 * 	int InterruptLogic;
 	uint32_t InterruptMaskMode1; TODO
	uint32_t InterruptMaskMode2; TODO
 * }
 * 
 * @return 0 on success, -1 on failure (see errno then)
 *  
 */
#define CMD_APCIE1564_GetDigitalInputInterruptConfig   _IOW(APCIE1564_MAGIC, 16,void*)

/* EVENTS ****************************************************************************/

/** Empty event FIFO of all pending events.
 * 
 * @param arg None (Use NULL)
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_EventEmpty         			_IOW(APCIE1564_MAGIC, 30,void*)

/** Wait for an event.
 * 
 * @param[in] arg apcie1564_event_t*
 * }
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_EventWait         			_IOW(APCIE1564_MAGIC, 31,apcie1564_event_t*)

/* COUNTERS ****************************************************************************/

/** Configures and starts given counter. 
 * 
 * @param arg Pointer to a structure containing the initialisation parameters \n  
 * struct \n
	{\n
		unsigned long CounterIndex;\n 
		uint32_t ReloadValue;\n
		unsigned long DirectionSelection;\n
		unsigned long LevelSelection;\n
	};\n
 * with:
 *   CounterIndex : (0,2) Index of the counter
 *   ReloadValue : (1,0xFFFFFFFF) 32-bit reload value
 *   DirectionSelection : (0,1)  
 * 		1 : Select the counter for up count
 *      0 : Select   the counter for down count
 *                                                                         
 *  LevelSelection : (1,2,3)
 * 		1 : Counter count each low level \n
 *      2 : Counter count each high level \n
 *      3 : Counter count each high and low level \n
 * 
 * When the counter overruns, interrupts are automatically generated and an event is recorded. 
 * Events may be retrieved using the event API. 
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 * */

#define CMD_APCIE1564_CounterInitAndStart		_IOW(APCIE1564_MAGIC, 40,void*)

/** Returns the current counter value
 * 
 * @param[in] arg Pointer to a uint32_t containing the index of the counter to require.
 * @param[out] arg Pointer to a uint32_t containing the current value of the counter.
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_ReadCounterValue			_IOW(APCIE1564_MAGIC, 41,void*)

/** Returns the current counter value
 * 
 * Event (interrupt) from this counter is deactivated.
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1564_CounterStop				_IOW(APCIE1564_MAGIC, 42,void*)

/*
	struct
	{
		uint32_t CounterIndex; 
		uint32_t SoftwareTriggerStatus;
		uint32_t SoftwareClearStatus;
		uint32_t OverflowStatus;
	}
	
	@return 0 on success, -1 on failure (see errno then)
*/
#define CMD_APCIE1564_CounterGetStatus			_IOW(APCIE1564_MAGIC, 43,void*)

#define CMD_APCIE1564_CounterGetConfigRegister	_IOW(APCIE1564_MAGIC, 44,void*)

#define CMD_APCIE1564_CounterReset				_IOW(APCIE1564_MAGIC, 45,void*)

/** Trigger the given counter.
 *  
 * if counter direction is 0 (down) the counter is reset to reload value
 * if counter direction is 1 (up) the counter is reset to 0
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */

#define CMD_APCIE1564_CounterTrigger				_IOW(APCIE1564_MAGIC, 46,void*)


#endif //__APCIE1564__H_

