/** @file utility-kapi.c
 
   Contains utility functions for kernel level.
 
   @par CREATION  
   @author Krauth Julien
   @date   11.08.06
   
   @par VERSION
   @verbatim
   $LastChangedRevision$
   $LastChangedDate$
   @endverbatim   
   
   @par COMPILER
   @verbatim
   Compiler	: gcc
   Version	: 
   kernel	: 
   @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"

EXPORT_SYMBOL(i_APCI3200_GetNumberOfAnalogInputChannels);
EXPORT_SYMBOL(i_APCI3200_GetChannelCalibrationValue);

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

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

/** Get the number of analog input channels.
 * 
 * Return the number of analog input channels.
 * E.g.: For a board that has 4 modules, the number of channels 
 * returned by this function will be 16.
 * 
 * @param [in] pdev				: The device to use.
 * @param [in] b_SingleDiff		: The mode of the input channels APCI3200_CONNECTION_TYPE_DIFFERENTIAL or APCI3200_CONNECTION_TYPE_SINGLE.
 * 
 * @param [out] b_NbrChannels	: The number of analog input channels. 			  
 * 
 * @retval 0: No error.
 * @retval 1: The handle parameter of the board is wrong.
 * @retval 2: Can't get the number of input channels.
 */
INT i_APCI3200_GetNumberOfAnalogInputChannels (struct pci_dev *pdev, BYTE b_SingleDiff, BYTE *b_NbrChannels)
{
	
		*b_NbrChannels = 0;
		
		if (!pdev) return 1;
		
		/* Check the number of modules */
		if ((APCI3200_PRIVDATA(pdev)->w_NbHardwareComponent <= 0) ||  
			(APCI3200_PRIVDATA(pdev)->w_NbHardwareComponent > 4))
			return 2;
			
		/* 
		 * Number of modules x Number of channels.
		 * On the APCI-3200 each module contains always 4 channles.
		 */
		*b_NbrChannels = (APCI3200_PRIVDATA(pdev)->w_NbHardwareComponent * 4);
		
		 if (b_SingleDiff == APCI3200_CONNECTION_TYPE_DIFFERENTIAL)
		 	*b_NbrChannels = (*b_NbrChannels / 2); 
		
		return 0;
}

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

/** Get the APCI-3200 calibration values from the device structure.
 * 
 * @param [in,out]	pdev					Pointer on the device structure.
 * @param [int]		channel_num				The channel on which value have to be read.
 * @param [int]		ConnectionType			The connection type:<br>
 *											- APCI3200_CONNECTION_TYPE_SINGLE<br>
 *											- APCI3200_CONNECTION_TYPE_DIFFERENTIAL
 * @param [int]		Gain					The agin to use:<br>
 *											- APCI3200_GAIN_1<br>
 *											- APCI3200_GAIN_2<br>
 *											- APCI3200_GAIN_4<br>
 *											- APCI3200_GAIN_8<br>
 *											- APCI3200_GAIN_16<br>
 *											- APCI3200_GAIN_32<br>
 *											- APCI3200_GAIN_128
 * @param [out]		CJCCurrentSource		The CJC current source value.	
 * @param [out]		ChannelCurrentSource	The channel current source value.
 * @param [out]		ChannelGainFactor		The channel gain factor value.
 * 
 * @retvale			0						No error.
 */	 
INT i_APCI3200_GetChannelCalibrationValue (struct pci_dev *pdev, 
											unsigned int channel_num,
											unsigned int ConnectionType,
											unsigned int Gain,
											unsigned long *CJCCurrentSource, 
											unsigned long *ChannelCurrentSource, 
											unsigned long *ChannelGainFactor)
{											
	return (apci3200_get_channel_calibration_value (pdev, 
											channel_num,
											ConnectionType,
											Gain,
											CJCCurrentSource, 
											ChannelCurrentSource, 
											ChannelGainFactor));
}

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

