⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.c

📁 s3c44b0片上ADC的uclinux驱动
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                     graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:           adc.c
** Last modified Date:  2005-04-21
** Last Version:        1.0
** Descriptions:        This is a Kernel module for uClinux 2.4.x .**                      This module let uClinux 2.4.x can use adc. 
**------------------------------------------------------------------------------------------------------
** Created by:          Chenmingji
** Created date:        2005-04-21
** Version:             1.0
** Descriptions:        The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**

********************************************************************************************************/
#define IN_adc#include "config.h"/********************************************************************************************************
              function announce********************************************************************************************************/
#if 0static loff_t adc_llseek(struct file *filp, loff_t off, int whence);static ssize_t adc_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos);#endifstatic ssize_t adc_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);
static int adc_open(struct inode *inode, struct file *filp);static int adc_release(struct inode *inode, struct file *filp); static int adc_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,                     unsigned long param);int  adc_init(void);void adc_cleanup(void);
/********************************************************************************************************
              function announce********************************************************************************************************/
#define MAJOR_NR majormodule_init(adc_init);module_exit(adc_cleanup);MODULE_PARM(major, "i");MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION("Guangzou ZLG-MCU Development Co.,LTD.\ngraduate school\nhttp://www.zlgmcu.com");MODULE_SUPPORTED_DEVICE("uClinux2.4.x LPC2200 adc");MODULE_AUTHOR("chenmingji");/*********************************************************************************************************
**                  "全局和静态变量在这里定义"         
**        global variables and static variables define here
********************************************************************************************************/
static int major = ADC_MAJOR_NR;
static unsigned int adc_usage[MAX_ADC];     /* device using count */
/********************************************************************************************************/
static struct file_operations adc_fops =        /* driver info  */{    owner:      THIS_MODULE,#if 0    llseek:     adc_llseek,    write:      adc_write,#endif    read:       adc_read,    ioctl:      adc_ioctl,    open:       adc_open,    release:    adc_release,};#if 0/*********************************************************************************************************
** Function name: adc_llseek
** Descriptions:  move read and write point
** Input: filp:   pointer of file
**        off:    ofset
**        whence: move mode
**                0: seek set
**                1: seek file' current point
**                2: seek file' end
** Output :      new point
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static loff_t adc_llseek(struct file *filp, loff_t off, int whence){    return 0;}#endif
/*********************************************************************************************************
** Function name: adc_read
** Descriptions:  read device
** Input: filp:   pointer of file
**        buf:    buf for save data
**        count:  size for read
**        f_pos:  *f_pos = read point
** Output : read size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t adc_read(struct file *filp, char *buf, size_t count,                           loff_t *f_pos){
    unsigned long flag;    u32 temp;
    u16 temp1;
    if (count > 2)
    {        return -EFBIG;
    }

    if (!access_ok(VERIFY_WRITE, (void *)buf, count))
    {        return -EFAULT;    }    temp = (int)filp->private_data;    local_irq_save(flag);    outl(inl(S3C44B0X_ADCCON)|0x01 , S3C44B0X_ADCCON);    while(inl(S3C44B0X_ADCCON)&0x01);    while (!(inl(S3C44B0X_ADCCON)&0x40));    temp = inl(S3C44B0X_ADCDAT);    local_irq_restore(flag);    temp1 = temp & 0xffff;    put_user(temp1, (u16 *)buf);    return count;}
#if 0/*********************************************************************************************************
** Function name: adc_write
** Descriptions:  write device
** Input: filp:   pointer of file
**        buf:    buf to write data
**        count:  size for write
**        f_pos:  *f_pos = write point
** Output : write size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t adc_write(struct file *filp, const char *buf, size_t count,                            loff_t *f_pos){    return 0;}#endif                /*********************************************************************************************************
** Function name: adc_open
** Descriptions:  open device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int adc_open(struct inode *inode, struct file *filp){    int num;    num = MINOR(inode->i_rdev);    if (num >= MAX_ADC)    {        return -ENODEV;    }        if (adc_usage[num] == 0)    {      filp->private_data = (void *)(num);    }    adc_usage[num]++;    MOD_INC_USE_COUNT;    printk(KERN_INFO DEVICE_NAME ": open  OK\n");    return 0;          /* success */} /*********************************************************************************************************
** Function name: adc_release
** Descriptions:  release device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int adc_release(struct inode *inode, struct file *filp) {    int num;
    num = MINOR(inode->i_rdev);    if (num >= MAX_ADC)    {        return -ENODEV;    }
    MOD_DEC_USE_COUNT;    adc_usage[num]--;
    return(0); } /*********************************************************************************************************
** Function name: adc_ioctl
** Descriptions:  IO control function
** Input:inode:   information of device
**       filp:    pointer of file
**       cmd:     command
**       arg:     additive parameter
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int adc_ioctl(struct inode *inode, struct file *filp,                        unsigned int cmd, unsigned long arg){
    if (_IOC_TYPE(cmd) != ADC_IOC_MAGIC)    {        return -ENOTTY;    }    if (_IOC_NR(cmd) >= ADC_MAXNR)    {        return -ENOTTY;    }
    switch(cmd)    {        case ADC_SET_CLKDIV:            if(arg>255)              {               arg = 255;              }            outl(arg,S3C44B0X_ADCPSR);            printk(KERN_INFO DEVICE_NAME ": ADC_SET_CLKDIV  OK\n");               /* success */            break;        case ADC_SET_BITS:            outl(arg&0x1C,S3C44B0X_ADCCON);            break;        default:            return -ENOTTY;            break;    }    return 0;}
/*********************************************************************************************************
** Function name: adc_init
** Descriptions:  init driver
** Input:none
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        int adc_init(void){    int  result;    
    result = register_chrdev(MAJOR_NR,  DEVICE_NAME,  &adc_fops);     if (result < 0)    {        printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR );        return(result);     } 
    if (MAJOR_NR == 0)    {        MAJOR_NR = result; /* dynamic */    }    outl(0, S3C44B0X_ADCCON);    printk(KERN_INFO DEVICE_NAME ": init OK\n");    return(0); }/*********************************************************************************************************
** Function name: adc_cleanup
** Descriptions:  exit driver
** Input:none
** Output none
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void adc_cleanup(void){
    outl(0, S3C44B0X_ADCCON);
    unregister_chrdev(MAJOR_NR, DEVICE_NAME);}/***********************************************************************************************************                            End Of File********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -