Smart210学习记录------linux串口驱动

发布者:technology1最新更新时间:2025-01-20 来源: cnblogs关键字:Smart210  linux  串口驱动 手机看文章 扫描二维码
随时随地手机看文章

一、核心数据结构 串口驱动有3个核心数据结构,它们都定义在<#include linux/serial_core.h> 1、uart_driver uart_driver包含了串口设备名、串口驱动名、主次设备号、串口控制台(可选)等信息,还封装了tty_driver(底层串口驱动无需关心tty_driver)。


 


 


struct uart_driver {    


 struct module     *owner;           /* 拥有该uart_driver的模块,一般为THIS_MODULE */     


const char        *driver_name;     /* 串口驱动名,串口设备文件名以驱动名为基础 */     


const char        *dev_name;        /* 串口设备名 */    


 int                major;           /* 主设备号 */     


int                minor;           /* 次设备号 */     


int                nr;              /* 该uart_driver支持的串口个数(最大) */     


struct console    *cons;            /* 其对应的console.若该uart_driver支持serial console,否则为NULL */

    /*      * these are private; the low level driver should not      * touch these; they should be initialised to NULL      */     


struct uart_state *state;    


 struct tty_driver *tty_driver;


};


 


2、uart_port uart_port用于描述串口端口的I/O端口或I/O内存地址、FIFO大小、端口类型、串口时钟等信息。实际上,一个uart_port实例对应一个串口设备


struct uart_port {     


spinlock_t             lock;           /* 串口端口锁 */     


unsigned int           iobase;         /* IO端口基地址 */     


unsigned char __iomem *membase;        /* IO内存基地址,经映射(如ioremap)后的IO内存虚拟基地址 */    


 unsigned int           irq;            /* 中断号 */    


 unsigned int           uartclk;        /* 串口时钟 */     


unsigned int           fifosize;       /* 串口FIFO缓冲大小 */    


 unsigned char          x_char;         /* xon/xoff字符 */    


 unsigned char          regshift;       /* 寄存器位移 */     


unsigned char          iotype;         /* IO访问方式 */     


unsigned char          unused1;

#define UPIO_PORT        (0)               /* IO端口 */


#define UPIO_HUB6        (1)


#define UPIO_MEM         (2)               /* IO内存 */


#define UPIO_MEM32       (3)


#define UPIO_AU          (4)               /* Au1x00 type IO */


#define UPIO_TSI         (5)               /* Tsi108/109 type IO */


#define UPIO_DWAPB       (6)               /* DesignWare APB UART */


#define UPIO_RM9000      (7)               /* RM9000 type IO */

    unsigned int        read_status_mask;  /* 关心的Rx error status */     


unsigned int        ignore_status_mask;/* 忽略的Rx error status */     


struct uart_info      *info;           /* pointer to parent info */     


struct uart_icount     icount;         /* 计数器 */

    struct console        *cons;           /* console结构体 */


#ifdef CONFIG_SERIAL_CORE_CONSOLE     


unsigned long         sysrq;           /* sysrq timeout */


#endif

    upf_t                 flags;

#define UPF_FOURPORT         ((__force upf_t) (1 << 1))


#define UPF_SAK              ((__force upf_t) (1 << 2))


#define UPF_SPD_MASK         ((__force upf_t) (0x1030))


#define UPF_SPD_HI           ((__force upf_t) (0x0010))


#define UPF_SPD_VHI          ((__force upf_t) (0x0020))


#define UPF_SPD_CUST         ((__force upf_t) (0x0030))


#define UPF_SPD_SHI          ((__force upf_t) (0x1000))


#define UPF_SPD_WARP         ((__force upf_t) (0x1010))


#define UPF_SKIP_TEST        ((__force upf_t) (1 << 6))


#define UPF_AUTO_IRQ         ((__force upf_t) (1 << 7))


#define UPF_HARDPPS_CD       ((__force upf_t) (1 << 11))


#define UPF_LOW_LATENCY      ((__force upf_t) (1 << 13))


#define UPF_BUGGY_UART       ((__force upf_t) (1 << 14))


#define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16))


#define UPF_CONS_FLOW        ((__force upf_t) (1 << 23))


#define UPF_SHARE_IRQ        ((__force upf_t) (1 << 24))


#define UPF_BOOT_AUTOCONF    ((__force upf_t) (1 << 28))


#define UPF_FIXED_PORT       ((__force upf_t) (1 << 29))


#define UPF_DEAD             ((__force upf_t) (1 << 30))


#define UPF_IOREMAP          ((__force upf_t) (1 << 31))

#define UPF_CHANGE_MASK      ((__force upf_t) (0x17fff))


#define UPF_USR_MASK         ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))

    unsigned int             mctrl;        /* 当前的moden设置 */    


 unsigned int             timeout;      /* character-based timeout */            


 unsigned int             type;         /* 端口类型 */    


 const struct uart_ops   *ops;          /* 串口端口操作函数集 */   


  unsigned int             custom_divisor;   


  unsigned int             line;         /* 端口索引 */    


 resource_size_t          mapbase;      /* IO内存物理基地址,可用于ioremap */    


 struct device           *dev;          /* 父设备 */    


 unsigned char            hub6;         /* this should be in the 8250 driver */    


 unsigned char            suspended;    


 unsigned char            unused[2];     


void                    *private_data; /* 端口私有数据,一般为platform数据指针 */ };


uart_iconut为串口信息计数器,包含了发送字符计数、接收字符计数等。在串口的发送中断处理函数和接收中断处理函数中,我们需要管理这些计数。


 


struct uart_icount {     __u32    cts;     __u32    dsr;     __u32    rng;     __u32    dcd;     __u32    rx;      /* 发送字符计数 */     __u32    tx;      /* 接受字符计数 */     __u32    frame;   /* 帧错误计数 */     __u32    overrun; /* Rx FIFO溢出计数 */     __u32    parity;  /* 帧校验错误计数 */     __u32    brk;     /* break计数 */     __u32    buf_overrun; };


 


uart_info有两个成员在底层串口驱动会用到:xmit和tty。用户空间程序通过串口发送数据时,上层驱动将用户数据保存在xmit;而串口发送中断处理函数就是通过xmit获取到用户数据并将它们发送出去。串口接收中断处理函数需要通过tty将接收到的数据传递给行规则层。


 


/* uart_info实例仅在串口端口打开时有效,它可能在串口关闭时被串口核心层释放。因此,在使用uart_port的uart_info成员时必须保证串口已打开。底层驱动和核心层驱动都可以修改uart_info实例。


 * This is the state information which is only valid when the port  * is open; it may be freed by the core driver once the device has  * been closed. Either the low level driver or the core can modify  * stuff here.  */


struct uart_info {    


     struct tty_struct     *tty;     


     struct circ_buf        xmit;


    uif_t                  flags;

/*  * Definitions for info->flags. These are _private_ to serial_core, and  * are specific to this structure. They may be queried by low level drivers.  */


#define UIF_CHECK_CD        ((__force uif_t) (1 << 25))


#define UIF_CTS_FLOW        ((__force uif_t) (1 << 26))


#define UIF_NORMAL_ACTIVE    ((__force uif_t) (1 << 29))


#define UIF_INITIALIZED        ((__force uif_t) (1 << 31))


#define UIF_SUSPENDED        ((__force uif_t) (1 << 30))

    int                     blocked_open;

    struct tasklet_struct   tlet;

    wait_queue_head_t       open_wait;     

[1] [2] [3] [4]
关键字:Smart210  linux  串口驱动 引用地址:Smart210学习记录------linux串口驱动

上一篇:linux网卡驱动移植
下一篇:Smart210学习记录-----SD/MMC/SDIO驱动

推荐阅读最新更新时间:2026-03-20 11:27

Smart210学习记录-----linux定时器
1.内核定时器:   Linux 内核所提供的用于操作定时器的数据结构和函数如下: (1) timer_list   在 Linux 内核中,timer_list 结构体的一个实例对应一个定时器   1 struct timer_list { 2        struct list_head entry; /* 定时器列表 */ 3       unsigned long expires; /*定时器到期时间*/ 4        void (*function)(unsigned long); /* 定时器处理函数 */ 5       unsigned long data; /* 作为参数被传入定
[单片机]
基于Linux-2.6.32.2在mini2440驱动分析一:串口驱动
串口驱动文件位于: linux-2.6.32.2/drivers/serial/s3c2440.c,省去非重点部分分析。 #include linux/module.h #include linux/ioport.h #include linux/io.h #include linux/platform_device.h #include linux/init.h #include linux/serial_core.h #include linux/serial.h #include asm/irq.h #include mach/hardware.h #include plat/regs-serial
[单片机]
linux串口驱动——s3c6410平台(一)
1、serial文件夹下Kconfig分析 config SERIAL_SAMSUNG tristate Samsung SoC serial support depends on ARM && PLAT_S3C select SERIAL_CORE help Support for the on-chip UARTs on the Samsung S3C24XX series CPUs,为支持三星的片上UARTs控制器 providing /dev/ttySAC0, 1 and 2 (note, some machines may not provide all of these ports, depending
[单片机]
[smart210] UART设置与编程
平台:smart210 CPU:S5PV210 目标:通过官方文档【S5PV210_UM_REV1.1.pdf】,获取UART设置的相关信息,进一步学习UART编程 1.通过搜索UART,在P853找到该芯片的串口功能介绍 1. 摘取关键点,我们能够知道,210提供了4个UART接口,支持中断模式或者DMA(直接存储器访问)模式,每个UART包含有两个FIFO缓冲区(读与写),当然每个UART通道所支持的最大FIFO缓冲区也是有限制的,其中UART0支持256字节,UART1支持64字节,UART2与UART3各支持16字节的缓冲区。 2. 然后就是串口常见的波特率、停止位、校验位、帧宽、等设置,其中波特率来源于PCLK
[单片机]
[<font color='red'>smart210</font>] UART设置与编程
13.Smart210串口驱动基于12的补充
上面的12节里,已经讲了2440有关串口的设置和操作。本来,2440,6410和210的串口操作应该是几乎一样的。在进行6410和210的设置的时候,发现在波特率的设置,6410和210的原理是一样的,但是跟2440有点不一样。所以下面以210为例子,说明6410和210波特率的设置。 寄存器: UBRDIV0=(int)(PCLK_PSYS/(BAUD*16)-1);//UBRDIV0保存该公式计算后的整数部分。 UBRDIV0=(int)(66000000/(115200*16)-1)=(int)(35.8-1)=(int)(34.8)=34。即取整数部分为34. //UDISLOT0=保存该公式计算后的小数部分*
[单片机]
13.Smart210<font color='red'>串口驱动</font>基于12的补充
tiny4412 串口驱动分析四 --- 修改默认的串口输出
开发板:tiny4412ADK+S700 4GB Flash 主机:Wind7 64位 虚拟机:Vmware+Ubuntu12_04 u-boot:U-Boot 2010.12 Linux内核版本:linux-3.0.31 Android版本:android-4.1.2 tiny4412默认是从uart0来输出和读取信息的,而tiny4412上留了两个串口,分别对应的是uart0和uart3,下面我们修改配置,使控制终端从uart0变成uart3 修改u-boot配置 在前面分析u-boot串口驱动的时候发现,在tiny4412.h中定义了 #define CONFIG_SERIAL0 1 然后再初始化串口的时候会根据这个
[单片机]
老查的ARM学习笔记:chapter-3(串口驱动程序分析 )
tty子系统架构概念简述 在Linux系统中,终端是一类字符型设备,它包括多种类型,通常使用tty来简称各种类型的终端设备。 1 串口终端(/dev/ttyS*) 串口终端是使用计算机串口连接的终端设备。Linux把每个串行端口都看作是一个字符设备。这些串行端口所对应的设备名称是/dev/ttySAC0; /dev/ttySAC1…… 2 控制台终端(/dev/console) 在Linux系统中,计算机的输出设备通常被称为控制台终端(Console),这里特指printk信息输出到的设备。/dev/console是一个虚拟的设备,它需要映射到真正的tty上,比如通过内核启动参数” console=ttySAC0”就把co
[单片机]
老查的ARM学习笔记:chapter-3(<font color='red'>串口驱动</font>程序分析 )
串口驱动设计(基于S3C6410)
串口通讯 串口充当的角色有两个,一个是数据传输,还有一个就是充当控制台。串口通讯分为同步和异步,我们通常使用的是异步串口。通讯时,双方先约定好数据帧的格式,即波特率,数据位,停止位,奇偶校验位等。我们通常使用的是RS232的9帧串口,其中,最重要的是2,3,5脚。 2:RXD接收数据 3:TXD发送数据 5:GND接地 接下来,我们开始进行串口的初始化。在此使用的开发板是飞凌S3C6410。初始化内容主要分为以下四个方面,引脚设置,帧格式设置,工作模式设置,波特率设置。 引脚设置 由核心板原理图上可找到RXD和TXD是通过GPA这个寄存器控制的,所以,在芯片手册中找到GPACON这个寄存器。 由芯片手册可得,只要设
[单片机]
<font color='red'>串口驱动</font>设计(基于S3C6410)
小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved