s3c2440串口驱动(一)

s3c2440串口驱动(一)

 


 

s3c2440_serial.c源代码

/* * ===================================================================================== * * Filename: s3c2440_serial.c * * Description: s3c2440 serial driver program * * Version: 1.0 * Created: 2011年01月10日 18时28分33秒 * Revision: none * Compiler: gcc * * Author: YOUR NAME (), * Company: * * ===================================================================================== */ #include #include #include //copy_to_user, copy_from_user #include #include //寄存器宏 #include //readl, readb, writel, writeb #define iobase S3C24XX_VA_UART1 #define UART_ULCON1 iobase #define UART_UCON1 iobase + 0x4 #define UART_UFCON1 iobase + 0x8 #define UART_UTRSTAT1 iobase + 0x10 #define UART_UTXH1 iobase + 0x20 #define UART_URXH1 iobase + 0x24 #define UART_UBRDIV1 iobase + 0x28 MODULE_AUTHOR("sunsea"); MODULE_DESCRIPTION("s3c2440 serial driver"); MODULE_LICENSE("GPL"); void serial_init(void) { /* 8N1 */ writel(3, UART_ULCON1); /* 115200 */ writel(26, UART_UBRDIV1); /* poll mode */ writel(5, UART_UCON1); /* 关闭FIFO */ writel(0, UART_UFCON1); return; } void serial_write(void) { int state; char *str = "This is a s3c2440 serial driver example!"; while(*str != '/0') { state = readl(UART_UTRSTAT1); if((0x02 & state) == 2) { writeb(*str, UART_UTXH1); str++; } } return; } void serial_read(void) { int state; char ch; int read_count = 20; while(read_count) { state = readl(UART_UTRSTAT1); if((0x01 & state) == 1) { ch = readb(UART_URXH1); printk("%c/n", ch); read_count--; } else { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(10); } } return; } int __init sunsea_init(void) { printk("s3c2440 serial driver loaded!"); /* 串口初始化 */ serial_init(); /* 串口写函数 */ serial_write(); /* 串口读函数 */ serial_read(); return 0; } void __exit sunsea_exit(void) { printk("s3c2440 serial driver exit!"); return; } module_init(sunsea_init); module_exit(sunsea_exit);  

 


 

Makefile源代码

ifneq ($(KERNELRELEASE),) obj-m := s3c2440_serial.o else KERNELSRC := /home/zsx/study/term6/build-embedded/kernel-2.6.27-android_ok modules: make -C $(KERNELSRC) SUBDIRS=$(PWD) $@ clean: rm -f *.o *.ko *.mod *.mod.c *.order *.symvers endif

 

你可能感兴趣的:(驱动,c,module,makefile,compiler,gcc,user)