/** @file analog_in-api.c

Contains function that enable to read the analog input

@par CREATION
@author Rose Jordan
@date   20.08.2010

@par VERSION
@verbatim
$LastChangedRevision:$
$LastChangedDate:$
@endverbatim

@par LICENCE
@verbatim
Copyright (C) 2009  ADDI-DATA GmbH for the source code of this module.

ADDI-DATA GmbH
Airpark Business Center
Airport Boulevard B210
77836 Rheinmuenster
Germany
Tel: +49(0)7229/1847-0
Fax: +49(0)7229/1847-200
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 "apci3701-private.h"

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

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  #define __iomem
#endif

/*
 * IOCTL command called to read one channel value
 * @param in: 	arg[0] => the index of the channel that we want to read
 * @param out: 	arg[0] => the value of the channel
 */
int do_CMD_apci3701_read_one_analog_input(struct pci_dev * pdev, unsigned int cmd, unsigned long arg)
{
	/*
	 * Get the data given by the user
	 */
	int ret = 0;
	uint32_t arg_array[1];
	uint32_t value = 0;

	if ( copy_from_user( arg_array, (uint32_t __user *)arg, sizeof(arg_array) ) )
	{
		return -EFAULT;
	}

	/*
	 * Read the value
	 */
	ret = i_APCI3701_read_1_analog_channel( pdev, (BYTE) arg_array[0], &value );

	/* Return the value */
	if ( copy_to_user( (uint32_t __user *)arg , &value, sizeof(value) ) )
	{
		return -EFAULT;
	}

	return ret;
}
