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

#define APCI2032_DRIVER_VERSION_MAJOR 2026
#define APCI2032_DRIVER_VERSION_MINOR 06
#define APCI2032_DRIVER_VERSION_PATCH 1

#include <apci.h>

//GENERAL DEFINE

#define APCI2032_BOARD_NAME                      "APCI2032"
#define APCI2032_BOARD_VENDOR_ID                 0x15B8
#define APCI2032_BOARD_DEVICE_ID                 0x1004

/* value used for CMD_APCI2032_CheckAndGetPCISlotNumber ! DEPRECATED ! */
#ifndef CONFIG_APCI2032_MAX_BOARD_NBR
#define CONFIG_APCI2032_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCI2032_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCI2032_MAX_BOARD_NBR CONFIG_APCI2032_MAX_BOARD_NBR

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

/**
 * @param (char*) area of size CONFIG_APCI2032_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCI2032_CheckAndGetPCISlotNumber   _IOR(APCI2032_MAGIC, 1,char*)
#define CMD_APCI2032_SetBoardInformation        _IOW(APCI2032_MAGIC, 2,USHORT)
/* deprecated */
#define CMD_APCI2032_GetHardwareInformation     _IOR(APCI2032_MAGIC, 3,str_BaseInformations*)
/** Activates the digital output memory.
 * 
 * @param arg (Use 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_APCI2032_SetDigitalOutputMemoryOn	_IOW(APCI2032_MAGIC, 4,void*)
/** Deactivates the digital output memory.
 * 
 * @param arg (Use NULL)
 */
#define CMD_APCI2032_SetDigitalOutputMemoryOff	_IOW(APCI2032_MAGIC, 5,void*)
/** Sets the given output.
 * 
 * @param arg (uint32_t) Number of the channel to set (from 1 to 32 included)
 * 
 * @return 0 or -EINVAL
 * 
 * Setting one output means setting the output to "High".
 * If you have switched on the digital ouput memory (ON), the selected outputs 
 * channels are set to "1". The other channels hold their state.
 * If you have switched off the digital output memory (OFF), the selected 
 * outputs are set to "1". The other channels are reset.
 * 
 */
#define CMD_APCI2032_Set1DigitalOutputOn		_IOW(APCI2032_MAGIC, 6,uint32_t)

/** Resets the given output.
 * 
 * @param arg (uint32_t) Map of the output to set
 * 
 * @return 0 or -EINVAL
 * 
 * Resetting an output means setting this output to "Low". The other channels 
 * hold their state.
 * 
 * @warning You can use this function only if the digital output memory is ON. See 
 * function b_ADDIDATA_SetDigitalOutputMemoryOn (..).
 * 
 * 
 */
#define CMD_APCI2032_Set1DigitalOutputOff		_IOW(APCI2032_MAGIC, 7,uint32_t)

/** Sets the given outputs.
 * 
 * @param arg (uint32_t) Map of the output to set
 * 
 * @return 0 or -EINVAL
 * 
 * Setting one output means setting the output to "High".
 * If you have switched on the digital ouput memory (ON), the selected outputs 
 * channels are set to "1". The other channels hold their state.
 * If you have switched off the digital output memory (OFF), the selected 
 * outputs are set to "1". The other channels are reset.
 * 
 */
#define CMD_APCI2032_Set32DigitalOutputsOn		_IOW(APCI2032_MAGIC, 8,uint32_t)

/** Resets one or several outputs of a port.
 * 
 * 
 * @param arg (uint32_t) Map of the output to reset
 * 
 * @return 0 or -EINVAL
 * 
 * Resetting an output means setting this output to "Low". The other channels 
 * hold their state.
 * 
 * @warning You can use this function only if the digital output memory is ON. See 
 * function b_ADDIDATA_SetDigitalOutputMemoryOn (..).
 * 
 * 
 */
#define CMD_APCI2032_Set32DigitalOutputsOff		_IOW(APCI2032_MAGIC, 9,uint32_t)

/** Returns the status of a 32-bit port.
 * @param (uint32_t*) address of the 32 bits field to store the status
 * 
 * @return 0 if success, -EFAULT if address is invalid 
 * 
*/
#define CMD_APCI2032_Get32DigitalOutputStatus	_IOR(APCI2032_MAGIC, 10,uint32_t*)

/* @todo
#define CMD_APCI2032_Set2DigitalOutputsOn
#define CMD_APCI2032_Set2DigitalOutputsOff
#define CMD_APCI2032_Set4DigitalOutputsOn
#define CMD_APCI2032_Set4DigitalOutputsOff
#define CMD_APCI2032_Set8DigitalOutputsOn
#define CMD_APCI2032_Set8DigitalOutputsOff
#define CMD_APCI2032_Set16DigitalOutputsOn
#define CMD_APCI2032_Set16DigitalOutputsOff
#define CMD_APCI2032_Set32DigitalOutputsOn
#define CMD_APCI2032_Get1DigitalOutputStatus
#define CMD_APCI2032_Get2DigitalOutputStatus
#define CMD_APCI2032_Get4DigitalOutputStatus
#define CMD_APCI2032_Get8DigitalOutputStatus
#define CMD_APCI2032_Get16DigitalOutputStatus
*/

/** VCC interrupt flag (voltage drop) */
#define APCI2032_INTERRUPT_VCC						0x01

/** CC interrupt flag (electrical short-circuit) */
#define APCI2032_INTERRUPT_CC						0x02

/** Initialises the digital output interrupt. 
 * 
 * @param (you may use NULL) 
 * @return always zero
 * 
 * @note In the Linux driver this function actually does nothing and may not 
 * be used. It is provided for compatibility with the MS Windows ADDI-PACK API.
 * 
 * IMPORTANT! The interrupt function is active only once.
 * After an interrupt has occurred, the interrupt function must be enabled again with the
 * function "b_ADDIDATA_EnableDisableDigitalOutputInterrupt".
 * 
 * 
 */
#define CMD_APCI2032_InitDigitalOutputInterrupt		_IOW(APCI2032_MAGIC, 11,unsigned long)

/** Enables or disables the digital output interrupt.
 * 
 * @param (unsigned long) the combinaison of the flags APCI2032_INTERRUPT_VCC and APCI2032_INTERRUPT_CC
 * @return 0 or -EINVAL
 * 
 * IMPORTANT! The interrupt function is active only once.
 * After an interrupt has occurred, the interrupt function must be enabled again with the
 * function "b_ADDIDATA_EnableDisableDigitalOutputInterrupt".
 * 
 * example:
 * - ioctl(fd, CMD_APCI2032_EnableDisableDigitalOutputInterrupt, 0) disable both interrupt
 * - ioctl(fd, CMD_APCI2032_EnableDisableDigitalOutputInterrupt, APCI2032_INTERRUPT_VCC | APCI2032_INTERRUPT_CC) enable both interrupt
 * - ioctl(fd, CMD_APCI2032_EnableDisableDigitalOutputInterrupt, APCI2032_INTERRUPT_VCC ) enables VCC, disables CC
 * - ioctl(fd, CMD_APCI2032_EnableDisableDigitalOutputInterrupt, APCI2032_INTERRUPT_CC ) enables CC, disables VCC
 * 
 */
#define CMD_APCI2032_EnableDisableDigitalOutputInterrupt	_IOW(APCI2032_MAGIC, 12,unsigned long)

/** Releases the digital output interrupt. 
 * 
 * @param (use NULL) 
 * @return 0
 * 
 * After this call, the board generate no more interrupt of the given type.
 *
 *  
 */
#define CMD_APCI2032_ReleaseDigitalOutputInterrupt	_IOW(APCI2032_MAGIC, 14,unsigned long)

/** Get the last interrupt flags . 
 * 
 * @param (unsigned int*) address of the field to store the status
 * @return 0 or -EFAULT if address is incorrect
 * 
 * This status can be 0, APCI2032_INTERRUPT_VCC , APCI2032_INTERRUPT_CC
 * or (APCI2032_INTERRUPT_VCC | APCI2032_INTERRUPT_CC)
 * 
 * If one of this bit is set, it means that :
 * 1) the corresponding interrupt happened,
 * 2) this interrupt has been acknowledged by the driver
 * 3) the corresponding interruption source has been deactivated by the handler 
 * and can no more generate this interrupt. 
 * 
 * The client software should re-activate this interruption source after 
 * treatment with CMD_APCI2032_EnableDisableDigitalOutputInterrupt()
 * 
 * @note This command has not correspondant in the MS Windows ADDI-PACK API.
 * 
 */

#define CMD_APCI2032_GetDigitalOutputInterruptStatus	_IOW(APCI2032_MAGIC, 15,unsigned int*)

#define CMD_APCI2032_GetWatchdogInformation
#define CMD_APCI2032_GetWatchdogInformationEx
#define CMD_APCI2032_InitWatchdog
#define CMD_APCI2032_StartWatchdog
#define CMD_APCI2032_TriggerWatchdog
#define CMD_APCI2032_StopWatchdog
#define CMD_APCI2032_ReadWatchdogStatus
#define CMD_APCI2032_ReleaseWatchdog

#endif // __APCI2032_H__
