亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 44b0-iic-drive.txt

?? 實現基于44bo嵌入式系統環境下的IIC驅動程序
?? TXT
字號:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>

#include <linux/poll.h>
#include <asm/irq.h>
#include <asm/arch/irq.h>
#include <asm/arch/irqs.h>
#include <asm/arch/s3c44b0x.h>

#include "config.h"
#include "44b.h"

#define IIC_MAJOR 232
#define IIC_NAME "xiuiic"
#define S3C44B0X_INTERRUPT_IIC 5
#define XIUIIC_DEBUG

static DECLARE_WAIT_QUEUE_HEAD(wait);

volatile uint8 I2C_sla = 0xa0;                   //從機地址
volatile uint8 I2C_suba = 0x00;                   //子地址
volatile uint8 iic_usage = 0;
volatile uint8 ack_tag;
volatile uint8 I2cReadWrite;


#undef PDEBUG                 /* undef it, just in case */
#ifdef XIUIIC_DEBUG
#      ifdef __KERNEL__
/* This one if debugging is on, and kernel space */
#        define PDEBUG(fmt, args...) printk( KERN_INFO "xiuiic: " fmt, ## args)
#      else
/* This one for user space */
#        define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
#      endif
#else
#      define PDEBUG(fmt, args...) /* not debugging: nothing */
#endif


static void board_init()
{
        rPDATF = 0X0;
        rPCONF = (rPCONF&0xfffffff0)|0x0a;      //SDA,SCL
        rPUPF = rPUPF|0x3; //disable SDA and SCL pull up
        rSYSCFG=SYSCFG_8KB;
}

void vdelay(unsigned short i)
{
        ushort cm = 0;
        while(cm < i)
        {
            cm++;
        }
}

static int iic_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
{
   
        return(0);
}

static loff_t iic_llseek(struct file *filp,loff_t off,int whence)
{
  
        return(0);
}

static ssize_t iic_read(struct file *filp,char *buf,size_t count,loff_t *f_pos)
{

       // char ker_buf;
char *ker_buf;
        char *ptr;
int i;      //the number of data truly read

        I2cReadWrite=0;   
ack_tag = 0;
PDEBUG( "enter to read function\n");  

if ((ker_buf = kmalloc(count,GFP_KERNEL)) == NULL) //dynamic allocation
      PDEBUG("kmalloc error\n");
ptr = ker_buf;

PDEBUG( "start to transfer slave addr 0xa0\n");
rIICDS = I2C_sla;      // 0xa0
        rIICSTAT = 0xf0;       // Master Tx,Start
        wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;

        //      PDEBUG("start to transfer sub-addr 0x00\n");
        rIICDS = I2C_suba;
        rIICCON = 0xe2;         // resumes IIC operation.
        wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;

// PDEBUG("start to transfer slave addr 0xa1\n");
rIICDS = I2C_sla|0x01;      // 0xa1:Read
        rIICSTAT=0xb0;        // Master Rx,Start
        rIICCON=0xe2;         // resumes IIC operation.   
        wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;

   
        *ptr = rIICDS;      //ack from slave device

//begin to loop???????????應該把ack清零嗎?

PDEBUG("start to transfer data\n");
for (i = 1; i < count; i++)      //only read count-1 data
{
      rIICCON = 0xe2; //????????????????rIICCON = 0xe2 & (~0x80)
      wait_event_interruptible(wait, (ack_tag != 0));
      ack_tag = 0;
      *ptr = rIICDS;
      PDEBUG("readbuf[%d] = %c\n", i, *ptr);
            ptr++;
}

        //PDEBUG("the first data in buf is %d\n", user_buf[0]);   
      rIICCON = 0xe2 & (~0x80) ;//disable ack,the last data disable ack
wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;

        PDEBUG("the last data in rIICDS is %c\n", rIICDS);
        *ptr = rIICDS; //read the last data
   
rIICSTAT = 0x90;//write this register,so send stop signal
        rIICCON =      0xe2;//resume IIC operation
        vdelay(100);
        copy_to_user(buf, ker_buf, i);      //if i=1 < count means not read a part of data
        rI_ISPC = rI_ISPC | BIT_IIC;//CLEAR PENDING BIT OF IIC TO MEAN IT IS FREE
        kfree(ptr);

return(i);
}

static int iic_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
{
char *ker_buf;
        char *ptr;
int i;      //the data

        //char ker_buf;
        PDEBUG("entering write function\n");
if ((ker_buf = kmalloc(count,GFP_KERNEL)) == NULL) //dynamic allocation
      PDEBUG("kmalloc error\n");
        copy_from_user(ker_buf, buf, count);
ptr = ker_buf;
ack_tag = 0;
I2cReadWrite=1;
//rIICSTAT=0x10;      // enbale TX/RX 
        rIICDS = I2C_sla;      // 0xa0
        rIICSTAT=0xf0;        // Master Tx,Start

PDEBUG("start to transfer the addr of slave device\n");
        wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;

        PDEBUG("start to transfer the sub-addr\n");
        rIICDS = I2C_suba;
        rIICCON = 0xe2;         // resumes IIC operation.
        wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
        ack_tag = 0;
// begin to write
PDEBUG("start to transfer data\n");
for (i = 0; i <count; i++)
{
         rIICDS = *ptr;     
         rIICCON = 0xe2;         // resumes IIC operation.
         wait_event_interruptible(wait, (ack_tag != 0)); //wait the trans complete
         ack_tag = 0;
      PDEBUG("buf[%d] = %c\n", i, rIICDS);
      ptr ++;
}

PDEBUG("begin to end\n");
        rIICSTAT = 0xd0;      // stop Master Tx condition
        rIICCON = 0xe2;       // resumes IIC operation.

        PDEBUG("we have write %d numbers in to epprom\n", i);
        rI_ISPC = rI_ISPC | BIT_IIC;//CLEAR PENDING BIT OF IIC TO MEAN IT IS FREE
        vdelay(100);
        kfree(ptr);
        return(i);
}

static void iic_irq(int irq, void *dev_id,struct pt_regs *regs)
{
ack_tag = 1;
        wake_up_interruptible(&wait);
rI_ISPC = rI_ISPC | BIT_IIC;
}

static int iic_open(struct inode *inode,struct file *filp)
{
int ret;
unsigned long flag = 0;
   
if (iic_usage == 0)
{
            ret = request_irq(S3C44B0X_INTERRUPT_IIC,iic_irq,SA_INTERRUPT,IIC_NAME,NULL);
      if (ret)
      {
       PDEBUG("%s: iic driver irq request failed.\n",IIC_NAME);
       free_irq(S3C44B0X_INTERRUPT_IIC,NULL);
       return(ret);
      }
} 
   
        PDEBUG("%s: request irq success.\n", IIC_NAME);

        local_irq_save(flag);
        board_init();
        rIICADD = 0x10;//slave addr 
        //IIC operation configure
        rIICCON=0xe2;      //Enable ACK,interrupt, IICCLK=MCLK/512, Enable ACK//64Mhz/512/(9+1) = 12.5Khz 
        rIICSTAT = 0x10;      // enbale TX/RX 

        PDEBUG("before INTPND = %d\n", rINTPND);
        rI_ISPC = rI_ISPC | BIT_IIC;//CLEAR PENDING BIT OF IIC TO MEAN IT IS FREE
        PDEBUG("after INTPND = %d\n", rINTPND);
        //init_waitqueue_head(&wait);
    
        PDEBUG("before mask = %d\n", rINTMSK);
rINTMSK = rINTMSK & ~BIT_IIC;// & ~BIT_GLOBAL;//ENABLE IIC AND GLOBAL INTERRUPT
        PDEBUG("after mask = %d\n", rINTMSK);
    
        local_irq_restore(flag);
        iic_usage ++;
PDEBUG("iic_usage is %d\n",iic_usage);
MOD_INC_USE_COUNT;
       return(0);
}

static int iic_release(struct inode *inode,struct file *filp)
{
      unsigned long flag = 0;
        vdelay(100);
        MOD_DEC_USE_COUNT;

        if(iic_usage)iic_usage --;
       if(iic_usage==0)
        {
            local_irq_save(flag);          
            //PDEBUG("INTPND = %d\n", rINTPND);
            //rI_ISPC = rI_ISPC | BIT_IIC;//CLEAR PENDING BIT OF IIC TO MEAN IT IS FREE
            //PDEBUG("INTPND = %d\n", rINTPND);
            //rINTMSK = rINTMSK | BIT_IIC;
            local_irq_restore(flag);
            free_irq(S3C44B0X_INTERRUPT_IIC,NULL);
            PDEBUG("enter release\n");
        }

        return(0);
}

static struct file_operations iic_fops={
        //       owner:THIS_MODULE,
llseek:iic_llseek,
read:      iic_read,
write: iic_write,
open:      iic_open,
release:iic_release,
ioctl:iic_ioctl,
};

static int __init myiic_init(void)
{
        int result;

        result=register_chrdev(IIC_MAJOR,IIC_NAME,&iic_fops);
        if(result==0){
            PDEBUG("%s: iic driver installed.\n", "myiic");
            return 0;
        }
        PDEBUG("%s:IIC driver install fail.\n","myiic");
        return(result);
}

static void __exit myiic_exit(void)
{
        int ret;
        ret = unregister_chrdev(IIC_MAJOR,IIC_NAME);
        if (ret < 0)
        {
            PDEBUG( KERN_ALERT "unregister fail\n");
            return;
        }
        PDEBUG(KERN_ALERT "leddrv:good_bye!\n");
}

module_init(myiic_init);
module_exit(myiic_exit);

/******************************************************************************************

測試程序

********************************************************************************************/

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>


int
main(int argc, char **argv)
{
        int fd;
        int count = 16;
        char wbuf[16] = "mingming shi zhu";
        char rbuf[16];
char *ptr;
        int i;
        // printf("enter main\n");
        // printf("\n");
   
        if ((fd = open("/var/tmp/ming/driver/IIC_test/xiuiic", O_RDWR)) == -1)
        {
            perror("open error\n");
            exit(1);
        }
        printf("open ok\n");
        printf("fd = %d\n",fd);

   
        // printf("%s\n", wbuf);
        // fflush((void *)STDOUT_FILENO);
         if (write(fd, wbuf, count) != count)
         {
            perror("write error\n");
            exit(1);
         }
         printf("we have write %d characters\n", count);

         //test write by reading
         if (read(fd, &rbuf, count) != count)
         {
             perror("read error\n");
             exit(1);
         }
      ptr = rbuf;
for ( i = 0; i < count; i++)
{
      printf("read[%d] = %c\n", i, *ptr);
      ptr ++;
}
        printf("\n");
        close(fd);
        return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人毛片在线观看| 国产日韩综合av| 国产乱子伦一区二区三区国色天香| 国产精品激情偷乱一区二区∴| 91精品国产综合久久久蜜臀图片 | 欧美www视频| 欧美一区二区精品| 欧美一区在线视频| 欧美mv日韩mv国产网站| 日韩欧美不卡一区| 久久久99久久| 国产精品免费视频观看| 综合色中文字幕| 亚洲色图都市小说| 亚洲成人免费电影| 日韩av二区在线播放| 精品一区二区三区在线视频| 韩国一区二区三区| 成人精品一区二区三区四区| 99这里都是精品| 色婷婷亚洲婷婷| 91精品国产综合久久福利软件| 69堂成人精品免费视频| 欧美电影免费观看高清完整版 | 91色porny在线视频| aaa欧美色吧激情视频| 日本电影亚洲天堂一区| 91精品久久久久久久91蜜桃| 精品国产123| 亚洲视频你懂的| 亚洲成国产人片在线观看| 蜜臀精品久久久久久蜜臀| 国产福利不卡视频| 在线亚洲一区二区| 日韩一级二级三级| 中文字幕久久午夜不卡| 亚洲激情av在线| 久久精品国产久精国产| 不卡一卡二卡三乱码免费网站| 91福利资源站| 久久网站最新地址| 亚洲成人动漫一区| 成人免费福利片| 欧美人xxxx| 国产精品不卡在线观看| 日本不卡一区二区三区高清视频| 国产福利电影一区二区三区| 欧美日韩一卡二卡| 国产精品视频看| 美女视频黄免费的久久| 91成人国产精品| 久久久久亚洲蜜桃| 日韩电影在线观看网站| 色婷婷精品大视频在线蜜桃视频| 精品成人私密视频| 日本女人一区二区三区| 一本到高清视频免费精品| 国产视频一区在线播放| 玖玖九九国产精品| 欧美美女一区二区三区| 视频在线观看国产精品| 色噜噜狠狠一区二区三区果冻| 日韩欧美高清dvd碟片| 亚洲综合在线第一页| 国产成人精品免费| 欧美日本在线视频| 亚洲电影视频在线| 99久久精品免费| 久久在线观看免费| 亚洲成国产人片在线观看| 99久久亚洲一区二区三区青草| 日韩三级中文字幕| 亚洲国产综合在线| 国产成人啪免费观看软件| 日韩精品在线网站| 亚洲午夜精品在线| av激情综合网| 91精品国产aⅴ一区二区| 亚洲日本va在线观看| 国产精品18久久久| 欧美美女直播网站| 日韩精品一二三区| 一道本成人在线| 中文字幕在线观看一区二区| 国产精品自拍在线| 欧美成人国产一区二区| 日韩精品成人一区二区在线| 色呦呦国产精品| 自拍偷自拍亚洲精品播放| 一本大道av伊人久久综合| 国产精品乱人伦| 成人一级片在线观看| 精品国产亚洲在线| 久久成人免费电影| 日韩欧美国产系列| 激情国产一区二区| 国产精品妹子av| 91香蕉国产在线观看软件| 国产精品久久久久久久久果冻传媒| 三级一区在线视频先锋| 欧美日韩电影一区| 日日夜夜精品视频免费| 91精品国产综合久久国产大片| 亚洲成人动漫一区| 91精品国产综合久久香蕉麻豆| 麻豆国产精品官网| 久久嫩草精品久久久精品| 国产在线不卡一卡二卡三卡四卡| 精品成人一区二区| 色88888久久久久久影院按摩| 亚洲精品免费在线| 欧美视频在线一区二区三区| 裸体在线国模精品偷拍| 国产亚洲污的网站| 91蝌蚪porny| 日产国产高清一区二区三区| 欧美电影精品一区二区| 成人免费不卡视频| 性做久久久久久免费观看欧美| 日韩一区和二区| 国产精品一区二区在线观看不卡| 国产精品狼人久久影院观看方式| 色一区在线观看| 奇米影视一区二区三区小说| 国产亚洲视频系列| 欧美日韩国产高清一区二区 | 粉嫩aⅴ一区二区三区四区五区 | 在线一区二区三区四区五区| 婷婷开心久久网| 久久综合久久久久88| 91一区二区三区在线播放| 日韩电影一二三区| 亚洲国产经典视频| 欧美日韩成人一区| 九九精品一区二区| 亚洲午夜精品在线| 国产亚洲欧美一区在线观看| 色老汉av一区二区三区| 亚洲女性喷水在线观看一区| 日韩你懂的电影在线观看| 色综合久久精品| 国产一区视频网站| 天天综合天天做天天综合| 国产视频一区在线播放| 欧美日韩专区在线| 精品一二三四区| 美女任你摸久久| 亚洲制服丝袜在线| 国产精品天美传媒| 精品理论电影在线观看 | 国产精品大尺度| 制服.丝袜.亚洲.中文.综合 | 一区二区三区不卡视频| 国产午夜亚洲精品不卡| 欧美日本高清视频在线观看| 成人免费av在线| 亚洲大片精品永久免费| 亚洲视频香蕉人妖| 中文字幕不卡的av| 精品少妇一区二区三区视频免付费 | 国产精品综合在线视频| 亚洲国产欧美日韩另类综合 | 国产成人三级在线观看| 久久er99精品| 日韩国产欧美在线观看| 亚洲黄色在线视频| 中文字幕综合网| 国产精品毛片高清在线完整版| 久久蜜臀精品av| 欧美视频自拍偷拍| 日韩欧美在线影院| 日韩欧美色综合| 日韩欧美国产一二三区| 91精品欧美福利在线观看| 欧美日韩综合在线免费观看| 色婷婷av一区二区三区软件| 91黄视频在线观看| 91黄视频在线| 欧美色网一区二区| 欧美人成免费网站| 日韩欧美国产麻豆| 欧美色图一区二区三区| 91福利视频在线| 欧美精品在线一区二区三区| 欧美日韩极品在线观看一区| 欧美日韩高清不卡| 日韩欧美国产三级电影视频| 久久亚洲一级片| 亚洲男人天堂av| 亚洲成人在线网站| 免费久久精品视频| 国产不卡视频一区| 欧美亚洲高清一区| 精品欧美一区二区在线观看| 国产欧美一区二区三区在线老狼| 国产欧美日韩卡一| 亚洲午夜免费福利视频| 一区视频在线播放| 美女网站色91| youjizz久久|