Exemplo n.º 1
0
static ssize_t s3c2410_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
	char str[20];
	int value;
	size_t len;

	if (mini6410_adc_acquire_io() == 0) {
		__ADC_locked = 1;

		START_ADC_AIN(adcdev.channel, adcdev.prescale);

		wait_event_interruptible(adcdev.wait, ev_adc);
		ev_adc = 0;

		DPRINTK("AIN[%d] = 0x%04x, %d\n", adcdev.channel, adc_data, ADCCON & 0x80 ? 1:0);

		value = adc_data;

		__ADC_locked = 0;
		mini6410_adc_release_io();
	} else {
		value = -1;
	}

	len = sprintf(str, "%d\n", value);
	if (count >= len) {
		int r = copy_to_user(buffer, str, len);
		return r ? r : len;
	} else {
		return -EINVAL;
	}
}
Exemplo n.º 2
0
int s3c2410_adc_read(int ain, wait_queue_head_t *wait)
{
	int ret = 0;

	if (down_interruptible(&adc_lock))
		return -ERESTARTSYS;

	adc_wait = wait;

	START_ADC_AIN(ain);
	sleep_on_timeout(adc_wait, HZ/100); /* 10ms */

#if 0
	if (signal_pending(current)) {
		up(&adc_lock);
		return -ERESTARTSYS;
	}
#endif

	ret = ADCDAT0 ;

	up(&adc_lock);

	adc_wait = NULL;

	DPRINTK("AIN[%d] = 0x%04x, %d\n", ain, ret, ADCCON & 0x80 ? 1:0);

	return (ret & 0x3ff);
}
Exemplo n.º 3
0
//ADC 读函数,一般对应于用户层/应用层的设备读函数(read)
static ssize_t s3c2410_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
	char str[20];
	int value;
	size_t len;
	//判断“A/D 转换器”资源是否可用
	if (down_trylock(&ADC_LOCK) == 0) 
	{
		OwnADC = 1; //标记“A/D 转换器”资源状态为可用
		START_ADC_AIN(adcdev.channel, adcdev.prescale); //开始转换
		wait_event_interruptible(adcdev.wait, ev_adc); //通过终端的方式等待转换结果
		ev_adc = 0;
		DPRINTK("AIN[%d] = 0x%04x, %d\n", adcdev.channel, adc_data, ADCCON & 0x80 ? 1:0);
		//把转换结果赋予 value,以便传递到用户层/应用层
		value = adc_data;
		//释放“A/D 转换器”资源
		OwnADC = 0;
		up(&ADC_LOCK);
	}
	else 
	{		//没有“A/D 转换器”资源,赋值为“-1”
		value = -1;
	}
	len = sprintf(str, "%d\n", value);
	if (count >= len) 
	{	//把转换结果传递到用户层/应用层
		int r = copy_to_user(buffer, str, len);
		return r ? r : len;
	}
	else 
	{
		return -EINVAL;
	}
}
Exemplo n.º 4
0
static ssize_t s3c2410_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
	int ret = 0;

	if (down_interruptible(&adcdev.lock))
		return -ERESTARTSYS;

	START_ADC_AIN(adcdev.channel, adcdev.prescale);
	interruptible_sleep_on(&adcdev.wait);

	ret = ADCDAT0;
	ret &= 0x3ff;
	DPRINTK("AIN[%d] = 0x%04x, %d\n", adcdev.channel, ret, ADCCON & 0x80 ? 1:0);

	copy_to_user(buffer, (char *)&ret, sizeof(ret));

	up(&adcdev.lock);

	return sizeof(ret);
}
Exemplo n.º 5
0
static ssize_t tq2440_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
	char str[20];
	int value;
	size_t len;
	if (down_trylock(&ADC_LOCK) == 0)
	{
		ADC_enable = 1;
		START_ADC_AIN(adcdev.channel, adcdev.prescale);
		wait_event_interruptible(adcdev.wait, ev_adc);

		ev_adc = 0;

		DPRINTK("AIN[%d] = 0x%04x, %d\n", adcdev.channel, adc_data, ((ADCCON & 0x80) ? 1:0));

		value = adc_data;
		sprintf(str,"%5d", adc_data);
		copy_to_user(buffer, (char *)&adc_data, sizeof(adc_data));

		ADC_enable = 0;
		up(&ADC_LOCK);
	}
	else
	{
		value = -1;
	}

	len = sprintf(str, "%d\n", value);
	if (count >= len)
	{
		int r = copy_to_user(buffer, str, len);
		return r ? r : len;
	}
	else
	{
		return -EINVAL;
	}
}