/** @file api.h
*
* @author Rodolphe Hilpert
*
* @date 05.01.06
* 
* @version  $LastChangedRevision$
* @version $LastChangedDate$
* 
* Kernel functions prototype for all functionality of the board.
*
*/

/** @par LICENCE
* @verbatim
 Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code and the documentation.
        
        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 program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details. 
        
    You shoud find the complete GPL in the COPYING file accompanying 
    this source code. 
* @endverbatim
*/

#ifndef __xpci3009_API_H_
#define __xpci3009_API_H_

int do_CMD_xpci3009_GetHardwareInformation(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_TestInterrupt(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_SetTTLPortConfiguration(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitAnalogInput (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAnalogInput (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadAnalogInputBit (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadAnalogInputValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitAnalogInputAutoRefresh (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAnalogInputAutoRefresh (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopAnalogInputAutoRefresh (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadAnalogInputAutoRefreshValueAndCounter (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReleaseAnalogInputAutoRefresh (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitAnalogInputSequence (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAnalogInputSequence (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopAnalogInputSequence (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReleaseAnalogInputSequence (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_EnableDisableAnalogInputHardwareTrigger (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetAnalogInputHardwareTriggerStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableAnalogInputSoftwareTrigger (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_AnalogInputSoftwareTrigger (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetAnalogInputSoftwareTriggerStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableAnalogInputHardwareGate (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetAnalogInputHardwareGateStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitAnalogOutput (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadAnalogOutputBit (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_WriteAnalogOutputValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_Read32DigitalInputs(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_InitDigitalInputModuleFilter(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_Set32DigitalOutputsOn(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_Set32DigitalOutputsOff(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_SetDigitalOutputMemoryOn(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_SetDigitalOutputMemoryOff(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_Get32DigitalOutputStatus(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitTimer                      (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReleaseTimer                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartTimer                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAllTimers                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerTimer                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerAllTimers                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopTimer                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopAllTimers                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadTimerValue  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadTimerStatus  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableTimerInterrupt          (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableTimerHardwareOutput (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetTimerHardwareOutputStatus (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitCounter                      (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReleaseCounter                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartCounter                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAllCounters                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerCounter                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerAllCounters                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopCounter                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopAllCounters                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ClearCounter                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadCounterValue  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadCounterStatus  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableCounterInterrupt          (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableCounterHardwareOutput (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetCounterHardwareOutputStatus (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

int do_CMD_xpci3009_InitWatchdog                      (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReleaseWatchdog                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartWatchdog                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StartAllWatchdogs                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerWatchdog                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_TriggerAllWatchdogs                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopWatchdog                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_StopAllWatchdogs                    (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadWatchdogValue  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_ReadWatchdogStatus  (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableWatchdogInterrupt          (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_EnableDisableWatchdogHardwareOutput (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
int do_CMD_xpci3009_GetWatchdogHardwareOutputStatus (struct pci_dev * pdev, unsigned int cmd, unsigned long arg);

// COUNTER
int do_CMD_XPCI3009_InitCounter (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_ClearCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_ClearAllCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_EnableLatchInterrupt (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_DisableLatchInterrupt (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_InitCompareLogic (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_EnableCompareLogic (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_DisableCompareLogic (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_Read16BitCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_Read32BitCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalChlOn (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalChlOff (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_Write16BitCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_Write32BitCounterValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_GetInterruptUDLatchedStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_InitIndex (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_EnableIndex (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_DisableIndex (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_GetIndexStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetIndexAndReferenceSource (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_InitReference (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_GetReferenceStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_GetCounterInitialisationStatus (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

// DIG IO
int do_CMD_XPCI3009_InitDigitalIO (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_ReadDigitalIOChlValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_ReadDigitalIOPortValue (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOMemoryOn (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOMemoryOff (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOChlOn (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOChlOff (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOPortOn (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);
int do_CMD_XPCI3009_SetDigitalIOPortOff (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);



// UTILS
/* Return the module functionalities.
 *
 * @param [in] pdev          : The device to initialize.
 * @param [in] b_ModulNbr    : Module number to configure (0 to 3).
 *
 * @param [out] pui_Functionality : Module configuration.
 *
 * @retval 0: No error.
 * @retval -EFAULT : Failed to copy data in user space (incorrect pointer).
 */
int do_CMD_XPCI3009_GetModulesId (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Get the board type
 *
 * @param [out] arg : Board type:	APCI1710_BOARD_TYPE
 *								   	PCI3009_BOARD_TYPE
 *									APCIE1711_BOARD_TYPE
 * @retval 0: No error.
 * @retval -EFAULT : Failed to copy data in user space (incorrect pointer).
 */
int do_CMD_XPCI3009_GetBoardType (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Read data directly from the board
 * 	In the user space, the user can specify an address to read
 *
 * This function can be changed, it is recommended NOT TO USE IT!
 *
 * @param [in] arg :	arg[0] : Bar to access
 * 						arg[1] : How many bytes (1, 2, 4, 8)
 * 						arg[2] : Offset
 *
 * @param [out] arg :
 * 						arg[0] : Value
 *
 * @retval 0: No error.
 * @retval -EFAULT : Failed to copy data in user space (incorrect pointer).
 * @retval -EADDRNOTAVAIL : Type of access not available.
 */
int do_CMD_XPCI3009_READ (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Write data directly the board
 * 	In the user space, the user can specify an address to read
 *
 * This function can be changed, it is recommended NOT TO USE IT!
 *
 * @param [in] arg :	arg[0] : Bar to access
 * 						arg[1] : How many bytes (1, 2, 4, 8)
 * 						arg[2] : Offset
 * 						arg[3] : Value
 *
 *
 * @retval 0: No error.
 * @retval -EFAULT : Failed to copy data in user space (incorrect pointer).
 * @retval -EADDRNOTAVAIL : Type of access not available.
 */
int do_CMD_XPCI3009_WRITE (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Enable and set the interrupt routine.
 *
 * @param [in] pdev              : The device to initialize.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: The interrupt callback is NULL.
 */
int do_CMD_XPCI3009_SetBoardIntRoutine (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Disable and reset the interrupt routine.
 *
 * @param [in] pdev              : The device to initialize.
 *
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 */
int do_CMD_XPCI3009_ResetBoardIntRoutine (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);

/** Return interrupt information.
 *
 * @param [in] pdev                            : The device to initialize.
 *
 * @param [out] arg[0] (pb_ModuleMask)         : Mask of the events <br>
 *                                               which have generated the interrupt.
 * @param [out] arg[1] (pul_InterruptMask)     :
 * @param [out] arg[2] (pul_CounterLatchValue) : The latched values of <br>
 *                                               the counter are returned.
 *
 * @retval 1  : No interrupt.
 * @retval >0 : IRQ number
 * @retval -EFAULT : Fail to retrieve user data.
 */
int do_CMD_XPCI3009_TestModuleInterrupt (struct pci_dev *pdev, unsigned int cmd, unsigned long arg);


/** Execute a command.
*
* @param pdev Pointer to a device.
* @param cmd Command to execute
* @param arg Argument of the command.
*/
int xpci3009_do_ioctl(struct pci_dev * pdev, unsigned int cmd, unsigned long arg);
#endif
