📄 atp.c
字号:
/*************************************************************************** Used on :the User Station** Pro name:atp.c** Date :2005.9** Company :STJ** Designed:Anly** Function:the module can be used to write and read the bus data, and can get the data by the write() and read() function, the data addr writed from 0 to 920, and the dataread from 0 to 460.*///**********the common library # include "linux/types.h"# include "linux/fs.h"# include "linux/mm.h"# include "linux/errno.h"# include "asm/segment.h"# include "asm/io.h"# include <asm/uaccess.h>//**********for the module #include "linux/kernel.h"#include "linux/module.h"//**********for the read/write the memory#include "linux/ioport.h"//**********for the interrupt#include "linux/sched.h"#include "linux/interrupt.h"#include "asm/irq.h"#include "linux/timer.h"//*********************************#define irq_addr 0x0fffff06c#define irq_len 4#define irq_mod 0x23//memory define #define Len_Wr 924#define Len_Re 460#define Base_addr_wr 0x40000200 //write address from 0x40000000#define Base_addr_re 0x40000000#define Len_Wr_bus 920 //the size of write buff is bytes#define Len_Re_bus 460#define Num_buf 50//#define Len_Wr_mod 1514//#define Len_Re_mod 1514#define IRQ_EXTIRQ 27 volatile unsigned int * Ext_r_GPFCON;//********** THE memory#define Rev_from_bus_ok 0x01;#define Rev_form_lan_ok 0x01;//the write buff to the buschar unsigned Mod_to_Bus[Num_buf][920]; // buffer and every is 920 byteschar unsigned Bus_to_Mod[Num_buf][460]; //buffer for write modulechar unsigned Mod_to_Bus_buff[1514];char unsigned Bus_to_mod_buff[1514];char unsigned mod_red;char unsigned bus_to_mod_flag;char unsigned mod_to_bus_flag;int *To_bus_wpointer;int *To_bus_rpointer;char unsigned Bus_wr_in;char unsigned Bus_re_in;char unsigned Mod_wr_in;char unsigned Mod_re_in;int Mod_re_len;//*********************************//the read buff to the buschar unsigned _ReadBuff[460]; //10 buffer and every is 460 byteschar unsigned _ReadBuffTo[Num_buf][1514]; //10 buffer and every is 1514 byte max//void irq_handler();//********************************* char unsigned SendNull[921]; //the NULLdata pack to sendunsigned int test_major = 0; int *addr_Wr; //the pointer of the write point the vit addr int *addr_Re; //the pointer of the read point the vit addr int *addr_wrt; int *addr_ref; int *addr_Ir; int ttp = 0; int addt = 0;struct timer_list mytimer;char unsigned yy,zz;char unsigned xx[920];char unsigned *pp;init_mem(){ int Ha,Hb;//**************************** for(Ha = 0; Ha < Num_buf; Ha++) { Mod_to_Bus[Ha][4] = 0x77; Mod_to_Bus[Ha][5] = 0x0ff; Mod_to_Bus[Ha][916] = 0x47; Mod_to_Bus[Ha][917] = 0x48; Mod_to_Bus[Ha][918] = 0x0ff; Mod_to_Bus[Ha][919] = 0x7d; } for (Ha = 0; Ha < 920; Ha++) { SendNull[Ha] = 0x0; } SendNull[4] = 0x0; SendNull[5] = 0x0; SendNull[6] = 0x0; SendNull[7] = 0x0; SendNull[8] = 0x0; SendNull[916] = 0x47; SendNull[917] = 0x48; SendNull[918] = 0x0ff; SendNull[919] = 0x7d; Bus_wr_in = 0; Bus_re_in = 0; Mod_wr_in = 0; Mod_re_in = 0; bus_to_mod_flag = 0; mod_to_bus_flag = 0;}void myfun(unsigned long i){ printk("%d \n", addt); addt = 0; mytimer.expires+=1*HZ; add_timer(&mytimer);}static int read_test(struct file *file, char *buf, size_t count, loff_t *loff){ if((Mod_re_in == Bus_re_in) && (bus_to_mod_flag == 0)) return 0;//1 package data is one buf data else {// printk("'"); if(Bus_to_Mod[Mod_re_in][6] == 1) {// printk("1"); Mod_re_len = 0x0; Mod_re_len = Bus_to_Mod[Mod_re_in][7]; Mod_re_len = (Mod_re_len << 8) | Bus_to_Mod[Mod_re_in][8]; memcpy(buf, &(Bus_to_Mod[Mod_re_in][16]), Mod_re_len); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } return Mod_re_len; }// 1 package data was splited to 2 buf data else if(Bus_to_Mod[Mod_re_in][6] == 2) {// printk("2 "); mod_red = Mod_re_in; mod_red++; if(mod_red == Num_buf) { mod_red = 0;// bus_to_mod_flag = 0; } if(mod_red == Bus_re_in) return 0; if(Bus_to_Mod[Mod_re_in][9] != 1) //get the first package { Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } else return 0; } else { memcpy(buf, &(Bus_to_Mod[Mod_re_in][16]), 440);//****** Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } Mod_re_len = 0x0; if(Bus_to_Mod[Mod_re_in][9] != 2) return 0; // printk("%d, %d =====",Bus_to_Mod[Mod_re_in][7],Bus_to_Mod[Mod_re_in][8]); Mod_re_len = Bus_to_Mod[Mod_re_in][7]; Mod_re_len = ((Mod_re_len << 8) | Bus_to_Mod[Mod_re_in][8]); memcpy((buf+440), &(Bus_to_Mod[Mod_re_in][16]), Mod_re_len); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } return (440+Mod_re_len); } }//1 package data was splited to 3 buf data else if(Bus_to_Mod[Mod_re_in][6] == 3) {// printk("3 "); mod_red = Mod_re_in; mod_red++; if(mod_red == Num_buf) mod_red = 0; if(mod_red == Bus_re_in) return 0; mod_red++; if(mod_red == Num_buf) mod_red = 0; if(mod_red == Bus_re_in) return 0; if(Bus_to_Mod[Mod_re_in][9] != 1) { Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } return 0; } memcpy(buf, (&Bus_to_Mod[Mod_re_in][16]), 440); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } if(Bus_to_Mod[Mod_re_in][9] != 2) return 0; memcpy((buf+440), &(Bus_to_Mod[Mod_re_in][16]), 440); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } if(Bus_to_Mod[Mod_re_in][9] != 3) return 0; Mod_re_len = Bus_to_Mod[Mod_re_in][7]; Mod_re_len = (Mod_re_len << 8) | Bus_to_Mod[Mod_re_in][8]; memcpy((buf+440*2), &(Bus_to_Mod[Mod_re_in][16]), Mod_re_len); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } return (440*2+Mod_re_len); }//1 package data was splited to 4 buf data else //if(Bus_to_Mod[Mod_re_in][6] == 4) { // printk("4 "); mod_red = Mod_re_in; mod_red++; if(mod_red == Num_buf) mod_red = 0; if(mod_red == Bus_re_in) return 0; mod_red++; if(mod_red == Num_buf) mod_red = 0; if(mod_red == Bus_re_in) return 0; mod_red++; if(mod_red == Num_buf) mod_red = 0; if(mod_red == Bus_re_in) return 0; if(Bus_to_Mod[Mod_re_in][9] != 1) { Mod_re_in++; bus_to_mod_flag = 0; return 0; } memcpy(buf, &(Bus_to_Mod[Mod_re_in][16]), 440); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } if(Bus_to_Mod[Mod_re_in][9] != 2) return 0; memcpy((buf+440), &(Bus_to_Mod[Mod_re_in][16]), 440); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } if(Bus_to_Mod[Mod_re_in][9] != 3) return 0; memcpy((buf+440*2), &(Bus_to_Mod[Mod_re_in][16]), 440); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; } if(Bus_to_Mod[Mod_re_in][9] != 4) return 0; Mod_re_len = 0x0; Mod_re_len = Bus_to_Mod[Mod_re_in][7]; Mod_re_len = (Mod_re_len << 8) | Bus_to_Mod[Mod_re_in][8]; memcpy((buf+440*3), &(Bus_to_Mod[Mod_re_in][16]), Mod_re_len); Mod_re_in++; if(Mod_re_in == Num_buf) { Mod_re_in = 0; bus_to_mod_flag = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -