📄 xu.c
字号:
#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/malloc.h>#include <linux/timer.h>#include <linux/module.h>#include <linux/init.h>#include <linux/poll.h>#include <asm/irq.h>#include <asm/arch/io.h>#include <asm/arch/hardware.h>#include <asm/hardware/clps7111.h>#define barrier() __asm__ __volatile__("": : :"memory")#define __raw_readl(p) (*(unsigned long *)(p))#define __raw_writel(v,p) (*(unsigned long *)(p) = (v))#define SYSFLGx2 SYSFLG2#define UARTDRx2 UARTDR2//# define copy_to_user(t,f,n) (memcpy_tofs(t,f,n), 0)#define UART2_MAJOR 61#define BUF_LEN 100static char Message[BUF_LEN];static char *Message_Ptr;static short Ready;static unsigned short AdcValue;static DECLARE_WAIT_QUEUE_HEAD(Uart2Wait);static void delay2(int n){ int i, j; for(i = 0; i < 1000; i++) for(j = 0; j < n; j++) ;}static int Uart2Close(struct inode * inode, struct file * file){ return 0;}static int Uart2Open(struct inode * inode, struct file * file){ Message_Ptr=Message; return 0;}/*static int Uart2Read(struct file * file, char * buf, size_t count, loff_t *ppos){ char Value;// printk("enter kernel uart2 read.....\n"); *(unsigned long *)0xfc000000 = 0x0; Value = *(unsigned char *)0xfc000000;// printk("0x20000000 : 0x%02x\n", Value); printk("value : 0x%02x\n", Value); delay2(2000); copy_to_user(buf, &Value, sizeof Value); return 1;}*/static int Uart2Read(struct inode *inode,struct file *file,char *buffer,int length){ int bytes_read=0; if(*Message_Ptr==0) return 0; while(length&&*Message_Ptr) { copy_to_user(buffer++,*(Message_Ptr++),length--); bytes_read++; } return bytes_read;}/* * select for mouse input */static unsigned int Uart2Select( struct file *file, struct poll_table_struct *wait){ if (Ready) return 1; poll_wait(file, &Uart2Wait, wait); return 0;}static int Uart2Ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int i; char c; switch(cmd) { case 0: {// printk("enter ioctl 0......\n"); i = Uart2Read(inode, file, (char *)arg, 100); return i; } case 1: { uart2_putc('U'); break; } case 2: { c = serial_getc(); uart2_putc (c); break; } case 3: { uart2_putc((char) arg); break; } case 4: { c=serial_getc(); copy_to_user((char *)arg,&c,sizeof(char)); break; } default: return -EINVAL; }}struct file_operations Uart2_fops = { read: Uart2Read, poll: Uart2Select, /* select */ open: Uart2Open, ioctl: Uart2Ioctl, release: Uart2Close,};void uart2_putc(const char c){ int tmo = 0; while((*(volatile unsigned long*)0xff001140 & (1 << 23))){ tmo++; if (tmo == 5000) break; } *(volatile unsigned char *)0xff001480 = c;}int serial_getc(void){ while (SYSFLGx2 & SYSFLG_URXFE) ; return *(volatile unsigned char *)0xff001480 & 0xff;}int Uart2_Init(void){ int rc; long val; unsigned char status; char c; Ready = 0; *(volatile unsigned long *)0xff0014C0 = 0x00070001; *(volatile unsigned long *)0xff001100 = (*(volatile unsigned long *)0xff001100) | 0x0100;// *(unsigned long *)0xff001100 |= 0x100;// *(unsigned long *)0xff0014c0 |= 0x101; printk("0xff001100 : 0x%08x\n", *(unsigned long *)0xff001100); printk("0xff0014c0 : 0x%08x\n", *(unsigned long *)0xff0014c0); printk("=====================================\n))"); printk("=====================================\n))"); printk("=====================================\n))"); printk("=====================================\n))"); printk("=====================================\n))"); delay2(10000);#if 0 while(1) { uart2_putc('U');// c = serial_getc();// uart2_putc (c); } #endif rc = register_chrdev(UART2_MAJOR, "ep7312-uart2", &Uart2_fops); if (rc < 0) { printk("uart2: can not get Major %d\n",UART2_MAJOR); return rc; } printk("uart2............Support, by soso, 2002.10\n"); return 0;}void Uart2_Cleanup(void){ unregister_chrdev(UART2_MAJOR, "ep7312-uart2"); return;}module_init(Uart2_Init);module_exit(Uart2_Cleanup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -