Add the fl2440 Driver (5) ADC Driver learning notes

Source: Internet
Author: User

The figure shows that the analog ADC has two functions: Touch Screen and general ADC. Int_tc and int_adc can be generated respectively. The ADC module has a total of eight channels for analog signal input, ain0, ain1, ain2, ain3, ym, YP, XM, and XP are selected through an 8-way analog switch MUX. Set the value of the pre-divider in the control register (adccon) to determine the AD Converter Frequency. Then, the ADC converts the analog signal to a digital signal and saves it to the adcdat0 data register, data in adcdat0 (generally the tenth digit is valid) can be obtained through interruption or query.

 

Steps for using the ADC:
(1) set the adccon register, select the input signal channel, and set the clock of the/D converter.
(2) set the adctsc register, that is, the ADC touch screen control register, which works in two modes and is mostly used for touch screen. When set to normal conversion mode, use the default value.
(3) set the adcdly register and start A/D conversion. If read_start is set to 1 in adccon, the next conversion is automatically started when the converted data (read the adcdat0 register) is read. Otherwise, set the enable_start bit to start A/D.
(4) When the conversion ends, read the adcdat0 register to obtain the value. If you use the query method, you can choose not to read the ecflg bit of the adccon register to determine whether the conversion is complete. Otherwise, you can use int_adc to interrupt the conversion. If int_adc is interrupted, the conversion is complete.

 

ADC Driver code: http://www.cnblogs.com/hoys/archive/2011/01/24/1943533.html

Record learning points:

1. Use semaphores semaphore and queues to implement blocking access to the critical zone and achieve mutually exclusive access to resources,

Semaphore usage:

Definition and initialization (macro): define_mutex (adc_lock)

Two methods are provided to obtain and release semaphores. The function is included in the header file declaration of Linux/semaphore. h and should be used accordingly:

Obtain semaphores: mutex_lock (& adc_lock) Release semaphores: mutex_unlock (& adc_lock)

Obtain semaphores: down_trylock (& adc_lock) Release semaphores: Up (& adc_lock)

 

Queue usage:

A waiting queue is managed by a "waiting queue Header". The wait_queue_head_t type structure is defined in <Linux/Wait. h> medium. A waiting queue header can be defined and initialized using:

Definition and initialization:

Declare_wait_queue_head (adc_waitq) or

Wait_queue_head_t adc_waitq;

Init_waitqueue_head (& adc_waitq );

Queue sleep:

Wait_event (adc_waitq, condition)

Wait_event_interruptible (adc_waitq, condition)

Wait_event_timeout (adc_waitq, condition, timeout)

Wait_event_interruptible_timeout (adc_waitq, condition, timeout)

Adc_waitq is the waiting queue header to be used.

Queue wake-up:

Void wake_up (wait_queue_head_t * adc_waitq );

Void wake_up_interruptible (wait_queue_head_t * adc_waitq );

Generally, there is no need to differentiate. In fact, the practice is to use wake_up.

 

2. encapsulation of character devices by Linux MISC Devices

Http://blog.csdn.net/yaozhenguo2006/article/details/6760575

 

3. Use of shared interruptions

Apply for an ADC interruption service. Because the touch screen driver and the general conversion ADC use the same interruption, the sharing interruption parameter irqf_shared.

 

Int request_irq (unsigned int IRQ, irqreturn_t (* Handler) (INT, void *, struct pt_regs *), unsigned long flags, const char * dev_name, void * dev_id );

 

Parameter Parsing:

Unsigned int IRQ // request interrupt number

Irqreturn_t (* Handler) // handle function pointer installed.

Unsigned long flags // bit mask of an option related to interrupt management. The shared interrupt is set to irqf_shared.

Const char * dev_name // The string passed to request_irq is used in/proc/interrupts to display the owner of the interrupt

Void * dev_id // used as the pointer to the shared disconnection. it is a unique identifier used to identify a device that is interrupted when it is released and possibly directed to its own private data zone ). if the interrupt is not shared, set dev_id to null,

 

 

 

Link: http://blog.chinaunix.net/uid-24219701-id-3292997.html

 

4. Test code

/********************************************************************************* *      Copyright:  (C) 2014  zhouguangfeng <[email protected]>   *                  All rights reserved. * *       Filename:  s3c_adc.c *    Description:  This file  *                  *        Version:  1.0.0 *         Author:  zhouguangfeng <[email protected]> *      ChangeLog:  1, Release initial version on "04/01/2012 02:51:19 PM" *                  ********************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/select.h>#include <sys/time.h>#include <errno.h>int main(void){    int adc_fd;           int adc_value, adc_size;    int k=8;    adc_fd = open("/dev/adc", O_RDONLY);    if (adc_fd < 0)    {        perror("open device adc");        exit(1);    }    while(k--)    {        adc_size = read(adc_fd, &adc_value, sizeof(adc_value));        printf("adc  channel %d value : %d\n", k, adc_value);        sleep(1);    }    close(adc_fd);    return 0;}

  

 

Add the fl2440 Driver (5) ADC Driver learning notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.