s3c2440_serial.c源代码
[cpp:nogutter] view plaincopyprint?
/*
* =====================================================================================
*
* 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 <linux/kernel.h>
#include <linux/module.h>
#include <asm/uaccess.h> //copy_to_user, copy_from_user
#include <linux/serial_core.h>
#include <asm/plat-s3c/regs-serial.h> //寄存器宏
#include <asm/io.h> //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);
UART.rar_linux uart_s3c2440
版权申诉
92 浏览量
2022-09-20
18:59:32
上传
评论
收藏 1KB RAR 举报
周楷雯
- 粉丝: 78
- 资源: 1万+
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈