/** @file scan.c
 
   Contains analog inputs scan functions, to initialize and read analog values on the APCI-3200.
 
   @par CREATION  
   @author Krauth Julien
   @date   16.11.05
   
   @par VERSION
   @verbatim
   $LastChangedRevision$
   $LastChangedDate$
   @endverbatim   
   
   @par COMPILER
   @verbatim
   Compiler	: gcc
   Version	: gcc (GCC) 3.3.6 (Debian 1:3.3.6-5)   
   kernel	: 2.4.26
   @endverbatim  
   
   @par UPDATES
   @verbatim
   Date			: 
   Author		: 
   Description	: 
   @endverbatim    
    
   @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 "apci3200-private.h"

/**@def EXPORT_NO_SYMBOLS
 * Function in this file are not exported.
 */
EXPORT_NO_SYMBOLS;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27)
#define __user 
#endif

int do_CMD_APCI3200_InitScanModuleAcquisitionSensor (struct pci_dev *pdev, unsigned int cmd, unsigned long arg)  
{
	INT i_ErrorCode = 0;
	struct InitTemperatureModule_t InitTemperatureModule;
		 
	if ( copy_from_user( &InitTemperatureModule, (WORD __user*)arg, sizeof(struct InitTemperatureModule_t) ) )
		return -EFAULT;		
	
	{
		unsigned long irqstate;
		APCI3200_LOCK(pdev,&irqstate);		
		{	    			        
			i_ErrorCode = i_APCI3200_InitScanModuleAcquisitionSensor (pdev, (&InitTemperatureModule)->l_Module, (&InitTemperatureModule)->l_SensorType, (&InitTemperatureModule)->pl_SensorValue, (&InitTemperatureModule)->l_DiffSingSelected);
		}
		APCI3200_UNLOCK(pdev,irqstate);
	}
	return (i_ErrorCode);		
}
   
int do_CMD_APCI3200_InitScanModuleAcquisition (struct pci_dev *pdev, unsigned int cmd, unsigned long arg)  
{
	INT i_ErrorCode = 0;											
	DWORD dw_ArgArray[7];
    			        
	if ( copy_from_user( dw_ArgArray, (DWORD __user *)arg, sizeof(dw_ArgArray) ) )
		return -EFAULT;		
    	
	{
		unsigned long irqstate;
		APCI3200_LOCK(pdev,&irqstate);		
		{
			i_ErrorCode = i_APCI3200_InitScanModuleAcquisition (pdev, 
															(WORD)dw_ArgArray[0], 
															dw_ArgArray[1],
															(BYTE)dw_ArgArray[2],
															dw_ArgArray[3],
															(BYTE)dw_ArgArray[4],
															(BYTE)dw_ArgArray[5],
															(BYTE)dw_ArgArray[6]);
		}
		APCI3200_UNLOCK(pdev,irqstate);
	}
	return (i_ErrorCode);		
}

int do_CMD_APCI3200_StartScanModuleAcquisition (struct pci_dev *pdev, unsigned int cmd, unsigned long arg)  
{
	INT i_ErrorCode = 0;											
	WORD w_Arg = 0;
    			        
	if ( copy_from_user( &w_Arg, (WORD __user *)arg, sizeof(w_Arg) ) )
		return -EFAULT;

	{
		unsigned long irqstate;
		APCI3200_LOCK(pdev,&irqstate);		
		{
			i_ErrorCode = i_APCI3200_StartScanModuleAcquisition (pdev, w_Arg);
		}
		APCI3200_UNLOCK(pdev,irqstate);
	}
	return (i_ErrorCode);		
}

int do_CMD_APCI3200_StopScanModuleAcquisition (struct pci_dev *pdev, unsigned int cmd, unsigned long arg)  
{
	INT i_ErrorCode = 0;											
	WORD w_Arg = 0;
    			        
	if ( copy_from_user( &w_Arg, (WORD __user *)arg, sizeof(w_Arg) ) )
		return -EFAULT;		
	{
		unsigned long irqstate;
		APCI3200_LOCK(pdev,&irqstate);		
		{
			i_ErrorCode = i_APCI3200_StopScanModuleAcquisition (pdev, w_Arg);
		}
		APCI3200_UNLOCK(pdev,irqstate);
	}
	return (i_ErrorCode);		
}
