📄 fx469.c
字号:
#include "fx469.h"static int read_fx469(struct file *files,char *buf,size_t count,loff_t *f_pos){ int left; if(verify_area(VERIFY_WRITE,buf,count)==-EFAULT) { printk("user space can not be writed\n"); return -EFAULT; } user_read_count=count; fx469_read_bit_count=0; interruptible_sleep_on(&fx469_read_queue); left=copy_to_user(buf,fx469_read_buf,count); if(left<0) { printk("copy data to user error\n"); return -EFAULT; } return count;}static int write_fx469(struct file *files,const char *buf,size_t count,loff_t *f_pos){/* int i,j; char *temp_buf; printk("<0>the boy write data to fx469\n"); printk("<0>count=%d\n",count); if((count<=0)||(count>100)) { temp_buf=kmalloc(50,GFP_KERNEL); } else { temp_buf=kmalloc(count,GFP_KERNEL); } if(!temp_buf) { printk("<0>kmalloc temp_buf error\n"); return -EFAULT; } if(copy_from_user(temp_buf,buf,count))*/ if(copy_from_user(fx469_write_buf,buf,count)) { printk("<0>copy_from_user error\n"); return -EFAULT; }/* for(i=0;i<count;i++) printk("%d ",*(temp_buf+i)); printk("<0>\n"); for(i=0;i<(count/8);i++) { printk("\ni=%d\n",i); for(j=0;j<64;j++) { if((*(task_ptr+i))&0x8000000000000000) printk("1 "); else printk("0 "); *(task_ptr+i)=(*(task_ptr+i))<<1; } }*/ fx469_write_data1=*(write_task_ptr); fx469_write_data2=*(write_task_ptr+1); fx469_write_bit_count=0; interruptible_sleep_on(&fx469_write_queue); // kfree(temp_buf); return count;}static int open_fx469(struct inode *node,struct file *files){ MOD_INC_USE_COUNT; write_task_ptr=(ullong *)fx469_write_buf; read_task_ptr=(ullong *)fx469_read_buf; printk("<0>someone open fx469\n"); return 0;}static int release_fx469(struct inode *node,struct file *files){ MOD_DEC_USE_COUNT; printk("<0>the boy close fx469\n"); return 0;}//fx469 write interrupt servicevoid fx469_write_service(int irq,void *dev_id,struct pt_regs *regs){ CLEAR_PEND_INT(FX469_WRITE_IRQ); if(set_led2) { set_led2=0; SET_IOPDATA(1); } else { set_led2=1; CLEAR_IOPDATA(1); }/* irq_count++; if(irq_count>=200) irq_count=0; fx469_read_buf[irq_count%10]=irq_count; if((irq_count%10)==9) { printk("<0>wake up read\n"); wake_up_interruptible(&fx469_read_queue); }*/ if(fx469_write_bit_count<64) { if(fx469_write_data1&0x8000000000000000) SET_IOPDATA(FX469_WRITE_BIT); else CLEAR_IOPDATA(FX469_WRITE_BIT); fx469_write_data1=fx469_write_data1<<1; } else { if(fx469_write_data2&0x8000000000000000) SET_IOPDATA(FX469_WRITE_BIT); else CLEAR_IOPDATA(FX469_WRITE_BIT); fx469_write_data2=fx469_write_data2<<1; } fx469_write_bit_count++; if(fx469_write_bit_count>=128) { fx469_write_bit_count=0; wake_up_interruptible(&fx469_write_queue); }}//fx469 read interrupt servicevoid fx469_read_service(int irq,void *dev_id,struct pt_regs *regs){ long temp; CLEAR_PEND_INT(FX469_READ_IRQ); temp=IOPDATA; temp&=(1<<(FX469_READ_BIT)); if(fx469_read_bit_count<64) { fx469_read_data1=fx469_read_data1<<1; if(temp) fx469_read_data1|=1; } else { fx469_read_data2=fx469_read_data2<<1; if(temp) fx469_read_data2|=1; } fx469_read_bit_count++; if(fx469_read_bit_count>127) { fx469_read_bit_count=0; *(read_task_ptr)=fx469_read_data1; *(read_task_ptr+1)=fx469_read_data2; wake_up_interruptible(&fx469_read_queue); } if(set_led2) { set_led2=0; SET_IOPDATA(1); } else { set_led2=1; CLEAR_IOPDATA(1); }/* irq_count++; if(irq_count>=200) irq_count=0; fx469_read_buf[irq_count%10]=irq_count; if((irq_count%10)==9) {// printk("<0>wake up read\n"); wake_up_interruptible(&fx469_read_queue); }*/ }void init_fx469(void){ int result; result=register_chrdev(254,"fx469",&fx469_files); CLEAR_PEND_INT(FX469_READ_IRQ); result=request_irq(FX469_READ_IRQ,fx469_read_service,SA_INTERRUPT,"fx469_read",NULL); INT_ENABLE(FX469_READ_IRQ); CLEAR_PEND_INT(FX469_WRITE_IRQ); result=request_irq(FX469_WRITE_IRQ,fx469_write_service,SA_INTERRUPT,"fx469_write",NULL); INT_ENABLE(FX469_WRITE_IRQ); irq_count=0; fx469_buf_count=0; user_read_count=0; fx469_write_count=0; printk("<0>request irq 0 1 \n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -