#ifndef __APCI1032_PRIVATE__
#define __APCI1032_PRIVATE__

/** @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 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 should have received a copy of the GNU General Public License along with 
this program; if not, write to the Free Software Foundation, 
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

You shoud also find the complete GPL in the COPYING file 
accompanying this source code.

* @endverbatim
*/

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
	#include <linux/config.h>
#else
	#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
		#include <linux/autoconf.h>
	#else
		#include <generated/autoconf.h>
	#endif
#endif


#include <linux/module.h>
#include <linux/pci.h> // struct pci_dev
#include <linux/list.h>
#include <linux/fs.h>
#include <linux/init.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0)
    #include <asm/uaccess.h>
#else
    #include <linux/uaccess.h>
#endif
#include <asm/io.h>
#include "apci1032.h"

/** @file apci1032-private.h
*
* stores definitions private to the driver
*/

/** private data of a board */

static __inline__ unsigned long GET_BAR0(struct pci_dev * dev)
{
	return dev->resource[0].start;
}

static __inline__ unsigned long GET_BAR1(struct pci_dev * dev)
{
	return dev->resource[1].start;
}


/** Utility fonction that returns 0 if the given index corresponds to a card already configured.
 * 
 * @param count Number of board 
 * @param index Minor number to check
 * 
 * @return 0 if minor number valid, not 0 otherwise
 * 
 * count ranges from 1 to ...
 * index ranges from 0 to ...
 * 
 * */

static __inline__ int apci1032_INDEX_NOT_VALID(atomic_t * count , unsigned int index )
{
	volatile unsigned int __count =  atomic_read(count);
	if (index >= __count) return 1;
	return 0;
	
}

/* number of board detected by the kernel */
extern atomic_t apci1032_count;
extern unsigned int apci1032_majornumber;

#define __DRIVER_NAME "apci1032"

/* /DEV function */
int apci1032_open_lookup (struct inode *inode, struct file *filp);
int apci1032_release_lookup (struct inode *inode,struct file *filp);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
int apci1032_ioctl_lookup(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
#else
long apci1032_ioctl_lookup(struct file *filp, unsigned int cmd, unsigned long arg);
#endif

/* actual FS functions  */
int apci1032_do_ioctl(struct pci_dev * dev, unsigned int cmd, unsigned long arg);

/* actual FS functions  */
void apci1032_proc_init(void);
void apci1032_proc_release(void);
void apci1032_proc_create_device(struct pci_dev * dev, unsigned int minor_number);
void apci1032_proc_release_device(struct pci_dev * dev);



int i_APCI1032_CheckAndGetPCISlotNumber  (unsigned char * pb_SlotNumberArray );
int i_APCI1032_SetBoardInformation       (unsigned char b_SlotNumber, int * pi_BoardHandle);
int i_APCI1032_GetHardwareInformation    (int i_BoardHandle,unsigned int * pui_BaseAddress,unsigned char * pb_InterruptNbr, unsigned char * pb_SlotNumber ); 
int i_APCI1032_CloseBoardHandle          (int i_BoardHandle);

int i_APCI1032_Read1DigitalInput         (int i_BoardHandle, unsigned char b_Channel, unsigned char * pb_ChannelValue);
int i_APCI1032_Read8DigitalInput         (int i_BoardHandle, unsigned char b_Port, unsigned char * pb_PortValue);
int i_APCI1032_Read16DigitalInput        (int i_BoardHandle, unsigned char b_Port, unsigned long * pul_InputValue);
int i_APCI1032_Read32DigitalInput        (int i_BoardHandle, unsigned long * pul_InputValue);

#include "api.h"
#include "privdata.h"

#endif //__APCI1032_PRIVATE__
