⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.c

📁 基于arm s3c2410下的串口设备驱动
💻 C
字号:
#include <linux/module.h>#include <linux/kernel.h>#include <asm/uaccess.h>#include <asm/arch-s3c2410/regs-serial.h>#include <asm/io.h>MODULE_AUTHOR("akae");MODULE_DESCRIPTION("serial module test");MODULE_LICENSE("GPL");#define iobase           S3C24XX_VA_UART1 #define UART_ULCON	 (iobase + 0x00)#define UART_UCON	 (iobase + 0x04)#define UART_UTRSTAT  	 (iobase + 0x10)#define UART_UTXH	 (iobase + 0x20)#define UART_URXH	 (iobase + 0x24)#define UART_UBRDIV	 (iobase + 0x28)void serial_write (void);void serial_read (void);int __initserial_init(void){	/*8N1*/	writel(3, UART_ULCON);	// 00000011	/*poll mode */	writel(5, UART_UCON);	// 00000101	/*115200*/	writel(26, UART_UBRDIV);			serial_write ();	serial_read ();	return 0;}voidserial_write (void){	int state;	char *str="akae serial write test\r\n";		while('\0' != *str)	{		state = readl(UART_UTRSTAT);		if((state & 2)  ==  0x02)		{			writel(*str, UART_UTXH);			str++;		}	}	}voidserial_read (void){	int state;	int read_count = 15;	while(read_count)	 {		state = readl(UART_UTRSTAT);				if((state & 1)  ==  0x01)			{			char ch;			ch = readl(UART_URXH);			printk("%c", ch);			read_count --;		}		else		{			        	set_current_state(TASK_INTERRUPTIBLE);	        	schedule_timeout(1);		}	 } 	printk("\n");}void __exitserial_exit(void){	printk("module exit\n");	return;}module_init(serial_init);module_exit(serial_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -