/* @file apci1016-kapi.h
 * 
 * @brief Define the public kernel-land API for the APCI XXXX 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 __APCI1016_KAPI_H__
#define __APCI1016_KAPI_H__

#include <linux/pci.h>
#include <apci1016.h>

#ifndef __KERNEL__
	#error This header is for inclusion in kernel code only !
#endif

#ifdef __KERNEL__

/* DIGITAL INPUT ***********************************************************************/

/** Get the value of the digital input channels.
 * 
 * bit D0 returns the state of the digital input 0, D1 returns the state of the digital input 1, and so on...
 * 
 * @param[in] pdev Pointer to the PCI device to access.
 * @param[out] input_value Pointer to a 32-bits variable that will hold the result.
 * 
 * @return 0 on success, non-zero on failure  
 * 
 * */
extern int APCI1016_Read16DigitalInput(struct pci_dev *pdev, uint16_t* input_value);

/* ADMINISTRATIVE ***********************************************************************/

/** find a apci1016 device of a given index in the system PCI device list.
 * @param index The index (minor number) to lookup
 * @return A pointer to the device or NULL
 *
 * This function is used to map a minor number to an actual device.
 */
static __inline__  struct pci_dev * apci1016_lookup_board_by_index(unsigned int index)
{
	struct pci_dev * dev = NULL;	
	int i = 0;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
	while ( (dev = pci_find_device(APCI1016_BOARD_VENDOR_ID,APCI1016_BOARD_DEVICE_ID,dev)) )
#else
	while ( (dev = pci_get_device(APCI1016_BOARD_VENDOR_ID,APCI1016_BOARD_DEVICE_ID,dev)) )
#endif
	{
		if (i == index) return dev;
		i++;
	}      

	return NULL;
}

//----------------------------------------------------------------------------

#endif // __KERNEL__

#endif // __APCI1016_KAPI_H__
