 /* @file apcie1532.h
  * 
  * @brief Define the public API for the apcie1532 ADDI-DATA board. 
  * 
  * @author Sylvain Nahas, Julien Krauth
  */

/** @par LICENCE
 * 
 *  @verbatim
   Copyright (C) 2009  ADDI-DATA GmbH for the source code of this module.
        
   ADDI-DATA GmbH
   Airpark Business Center
   Airport Boulevard B210
   77836 Rheinm�nster
   Germany
   Tel: +49(0)7229/1847-0
   Fax: +49(0)7229/1847-200
   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 __APCIE1532_H__
#define __APCIE1532_H__


#define APCIE1532_DRIVER_VERSION_MAJOR 2026
#define APCIE1532_DRIVER_VERSION_MINOR 06
#define APCIE1532_DRIVER_VERSION_PATCH 1

#include <apci.h>

//GENERAL DEFINE

#define APCIE1532_BOARD_NAME                      "APCIE1532"

#define APCIE1532_BOARD_VENDOR_ID                 0x15B8
#define APCIE1532_BOARD_DEVICE_ID                 0x1011

#define CPCIS1532_BOARD_VENDOR_ID                 0x15B8
#define CPCIS1532_BOARD_DEVICE_ID                 0x101F

/**@def APCIE1532_READREG 
 * Read register offset (channel 0 - 7).
 */
#define APCIE1532_READREG			0x00

/**@def APCIE1532_WRITE 
 * Write register offset (channel 0 - 7).
 */
#define APCIE1532_WRITEREG			0x04

/* value used for CMD_APCIE1532_CheckAndGetPCISlotNumber ! DEPRECATED ! */
#ifndef CONFIG_APCIE1532_MAX_BOARD_NBR
#define CONFIG_APCIE1532_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCIE1532_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCIE1532_MAX_BOARD_NBR CONFIG_APCIE1532_MAX_BOARD_NBR

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

/**
 * @param (char*) area of size CONFIG_APCIE1532_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCIE1532_CheckAndGetPCISlotNumber   _IOR(APCIE1532_MAGIC, 1,char*)

#define CMD_APCIE1532_SetBoardInformation        _IOW(APCIE1532_MAGIC, 2,USHORT)

/**
 * @deprecated
 */
#define CMD_APCIE1532_GetHardwareInformation     _IOR(APCIE1532_MAGIC, 3,str_BaseInformations*)

/** Read all digital inputs of the APCIE-1532.
 *
 * @param [out]		arg		Port state (0 to 65535).
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Can't return parameters.
 */
#define CMD_APCIE1532_Read16DigitalInputs			_IOR(APCIE1532_MAGIC, 4, uint32_t *)

/** Set all digital outputs of the APCIE-1532 on.
 *
 * @param [in]		arg		Port state to set (0 to 65535).
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Can't return parameters.
 */
#define CMD_APCIE1532_Set16DigitalOutputsOn		_IOW(APCIE1532_MAGIC, 5, uint32_t)

/** Set all digital outputs of the APCIE-1532 off.
 *
 * @param [in]		arg		Port state to reset (0 to 65535).
 *
 * @retval 0		No error. 
 * @retval -EPERM	Output memory is not activated.
 * @retval -EFAULT	Can't return parameters.
 */
#define CMD_APCIE1532_Set16DigitalOutputsOff		_IOW(APCIE1532_MAGIC, 6, uint32_t)

/** Set the digital output memory on.
 *
 * @param 			arg		No arg, it can be NULL.
 *
 * @retval 0		No error.
 */
#define CMD_APCIE1532_SetDigitalOutputMemoryOn	_IO(APCIE1532_MAGIC, 7)

/** Set the digital output memory off.
 *
 * @param 			arg		No arg, it can be NULL.
 *
 * @retval 0		No error.
 */
#define CMD_APCIE1532_SetDigitalOutputMemoryOff	_IO(APCIE1532_MAGIC, 8)

/** Get all digital outputs state of the APCIE-1532.
 *
 * @param [out]		arg		Port state (0 to 65535).
 *
 * @retval 0		No error. 
 * @retval -EFAULT	Can't return parameters.
 */
#define CMD_APCIE1532_Get16DigitalOutputStatus	_IOR(APCIE1532_MAGIC, 9, uint32_t *) 

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

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

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

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

/** Wait for an event.
 * 
 * @param[in] arg apcie1532_event_t*
 * 
 * @return 0 on success, -1 on failure (see errno then) 
 * 
 */
#define CMD_APCIE1532_EventWait         			_IOW(APCIE1532_MAGIC, 14,apcie1532_event_t*)

/** Configures and starts given counter. 
 * 
 * @param arg Pointer to a structure containing the initialisation parameters \n  
 * struct \n
	{\n
		uint32_t ReloadValue;\n
		unsigned long DirectionSelection;\n
		unsigned long LevelSelection;\n
	};\n
 * with:
 *   ReloadValue : (1,0xFFFF) 16-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_APCIE1532_CounterInitAndStart		_IOW(APCIE1532_MAGIC, 15,void*)

/** Returns the current counter value
 * 
 * @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_APCIE1532_ReadCounterValue			_IOW(APCIE1532_MAGIC, 16,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_APCIE1532_CounterStop				_IOW(APCIE1532_MAGIC, 17,void*)

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

#define CMD_APCIE1532_CounterGetConfigRegister	_IOW(APCIE1532_MAGIC, 19,void*)

#define CMD_APCIE1532_CounterReset				_IOW(APCIE1532_MAGIC, 20,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_APCIE1532_CounterTrigger				_IOW(APCIE1532_MAGIC, 21,void*)

/*
struct
{
	uint8_t timerIndex;
	uint8_t timeBase;
	uint32_t reloadValue;
	uint8_t interruptFlag;
}timer_params;
* @see kapi funtion: APCIE1532_TimerWatchdogInitAndStart
*/
#define CMD_APCIE1532_TimerWatchdogInitAndStart _IOW(APCIE1532_MAGIC, 22, void*)
/*
struct {
  uint8_t timerIndex;
  uint32_t value;
} read_params;
* @see kapi funtion: APCIE1532_ReadTimerWatchdogValue
*/
#define CMD_APCIE1532_ReadTimerWatchdogValue _IOR(APCIE1532_MAGIC, 23, void*)

#define CMD_APCIE1532_TimerWatchdogStop _IOW(APCIE1532_MAGIC, 24, void*)

#define CMD_APCIE1532_TimerWatchdogTrigger _IOW(APCIE1532_MAGIC, 25, void*)

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

#endif // __APCIE1532_H__
