#ifndef __APCI2016_KAPI_H__
#define __APCI2016_KAPI_H__

#ifndef __KERNEL__
#error This header is intended for use in kernel context only
#endif

#ifdef __KERNEL__

#include <linux/pci.h>

/** find a apci 2016 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 * apci2016_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(APCI2016_BOARD_VENDOR_ID,APCI2016_BOARD_DEVICE_ID,dev)) )
#else
	while ( (dev = pci_get_device(APCI2016_BOARD_VENDOR_ID,APCI2016_BOARD_DEVICE_ID,dev)) )
#endif
	{
		if (i == index) return dev;
		i++;
	}      

	return NULL;

}

#endif // __KERNEL__


#endif // __APCI2016_KAPI_H__
