/** @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
*/

#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/version.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <apci.h>
#include <apci3600.h>
#include <apci3600-kapi.h>


MODULE_LICENSE ("GPL");
MODULE_AUTHOR ("ADDI-DATA GmbH <info@addi-data.com>");
MODULE_DESCRIPTION ("APCI-3600 IOCTL driver sample00");

/*minor of the board*/
static int board_minor=0;

/*can be override*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)  
	MODULE_PARM (board_minor,"i");
	EXPORT_NO_SYMBOLS;
#else
	module_param(board_minor, int, S_IRUGO);
#endif


static int sample00(struct pci_dev *pdev)
{
	int i_ReturnValue = 0;
	uint32_t dw_OnBoardRAMTotalSize = 0;
	uint8_t b_NbrOfComputerBufferAllocated = 0;
	uint8_t b_Cpt = 0;
	uint32_t pdw_ComputerBufferSize [PCI3600_MAX_NBR_COMPUTER_BUFFER];


	uint8_t pb_EnableCurrentSource[2];
	uint8_t pb_Coupling[2];
	uint8_t pb_SingleDiffMode[2];
	uint8_t pb_Gain[2];

	pb_EnableCurrentSource[0] = 0;
	pb_EnableCurrentSource[1] = 0;

	pb_Coupling[0] = PCI3600_DC_COUPLING;
	pb_Coupling[1] = PCI3600_DC_COUPLING;

	pb_SingleDiffMode[0] = PCI3600_SINGLE_ENDED_MODE;
	pb_SingleDiffMode[1] = PCI3600_SINGLE_ENDED_MODE;

	pb_Gain[0] = 0;
	pb_Gain[1] = 0;


	printk("Get Board Information\n");
	/* Initialise the board */
	i_ReturnValue = i_PCI3600_InitBoard (pdev,
										 PCI3600_MASTER_MODE,
										 PCI3600_DIVISOR_4,
										 PCI3600_DIVISOR_4,
										 PCI3600_EXT_CLOCK_1,
										 PCI3600_EXT_CLOCK_1,
										 0,
										 0,
										 PCI3600_CHRONOMETER_DIVISOR_1);

	if (i_ReturnValue == 0)
	{
		printk ("i_PCI3600_InitBoard OK\n");

		i_ReturnValue = i_PCI3600_GetBoardInformation (pdev,
						&dw_OnBoardRAMTotalSize,
						&b_NbrOfComputerBufferAllocated,
						pdw_ComputerBufferSize);

		/*************************/
		/* Test the return value */
		/*************************/
		if (i_ReturnValue == 0) {
			printk ("i_PCI3600_GetBoardInformation OK\n");

			/*Display the board information*/
			printk("On board RAM Size %dMBytes\n",dw_OnBoardRAMTotalSize);

			printk("Number of computer buffer allocated : %hu\n",b_NbrOfComputerBufferAllocated);

			for (b_Cpt = 0; b_Cpt < b_NbrOfComputerBufferAllocated; b_Cpt++) {
				printk("Computer buffer %hu size : %u Bytes\n",b_Cpt,pdw_ComputerBufferSize[b_Cpt]);

			}
		} else {
			printk ("i_PCI3600_GetBoardInformation Error : %d",i_ReturnValue);

		}

	} else
	{
		printk ("i_PCI3600_InitBoard Error : %d\n",i_ReturnValue);
	}

	return (0);
}




//------------------------------------------------------------------------------
/** Called when module loads. */
static int __init
apci3600_sample00_init (void)
{

	printk("Using board minor %d (override with board_minor parameter)\n",board_minor);
	sample00(apci3600_lookup_board_by_index(board_minor));
	printk("Succesfull end of the sample, you can unload it...\n");

	return 0;

}

//-------------------------------------------------------------------
/** Called when module is unloaded. */
static void __exit
apci3600_sample00_exit (void)
{



}


//------------------------------------------------------------------------------
module_exit (apci3600_sample00_exit);

module_init (apci3600_sample00_init);

