串口 ---linux-3.5.3

刚开始看Linux 感觉不像之前vxworks代码那些东西。linux更讲究结构体的设计和使用,类似C++对象的继承什么的。
 
设计才是真思维。堆代码完全不是问题,设计好才是关键。
 
 
UART是指Universal Asynchronous Receiver Transmitter,通用异步收发器。主要包含发送模块、接收模块、波特率发生器模块、数据存储模块和总线接口模块。serial指串行,一般我们常用的就是异步串行通信接口,用于CPU和外设之前的通信。
 
 
 
  

struct uart_port {  spinlock_t  lock;   /* port lock */  unsigned long  iobase;   /* in/out[bwl] */  unsigned char __iomem *membase;  /* read/write[bwl] */  unsigned int  (*serial_in)(struct uart_port *, int);  void   (*serial_out)(struct uart_port *, int, int);  void   (*set_termios)(struct uart_port *,                    struct ktermios *new,                    struct ktermios *old);  int   (*handle_irq)(struct uart_port *);  void   (*pm)(struct uart_port *, unsigned int state,           unsigned int old);  void   (*handle_break)(struct uart_port *);  unsigned int  irq;   /* irq number */  unsigned long  irqflags;  /* irq flags  */  unsigned int  uartclk;  /* base uart clock */  unsigned int  fifosize;  /* tx fifo size */  unsigned char  x_char;   /* xon/xoff char */  unsigned char  regshift;  /* reg offset shift */  unsigned char  iotype;   /* io access style */  unsigned char  unused1;

 

 unsigned int  read_status_mask; /* driver specific */  unsigned int  ignore_status_mask; /* driver specific */  struct uart_state *state;   /* pointer to parent state */  struct uart_icount icount;   /* statistics */

 struct console  *cons;   /* struct console, if any */ #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(SUPPORT_SYSRQ)  unsigned long  sysrq;   /* sysrq timeout */ #endif

 upf_t   flags;

 

 unsigned int  mctrl;   /* current modem ctrl settings */  unsigned int  timeout;  /* character-based timeout */  unsigned int  type;   /* port type */  const struct uart_ops *ops;  unsigned int  custom_divisor;  unsigned int  line;   /* port index */  resource_size_t  mapbase;  /* for ioremap */  struct device  *dev;   /* parent device */  unsigned char  hub6;   /* this should be in the 8250 driver */  unsigned char  suspended;  unsigned char  irq_wake;  unsigned char  unused[2];  void   *private_data;  /* generic platform data pointer */ };

 
 
 
  

struct uart_state {  struct tty_port  port;

 int   pm_state;  struct circ_buf  xmit;

 struct uart_port *uart_port; };

 
struct tty_port {
 struct tty_struct *tty;  /* Back pointer */
 const struct tty_port_operations *ops; /* Port operations */
 spinlock_t  lock;  /* Lock protecting tty field */
 int   blocked_open; /* Waiting to open */
 int   count;  /* Usage count */
 wait_queue_head_t open_wait; /* Open waiters */
 wait_queue_head_t close_wait; /* Close waiters */
 wait_queue_head_t delta_msr_wait; /* Modem status change */
 unsigned long  flags;  /* TTY flags ASY_*/
 unsigned char  console:1; /* port is a console */
 struct mutex  mutex;  /* Locking */
 struct mutex  buf_mutex; /* Buffer alloc lock */
 unsigned char  *xmit_buf; /* Optional buffer */
 unsigned int  close_delay; /* Close port delay */
 unsigned int  closing_wait; /* Delay for output */
 int   drain_delay; /* Set to zero if no pure time
         based drain is needed else
         set to size of fifo */
 struct kref  kref;  /* Ref counter */
};
 
 
 
  

struct uart_driver {  struct module  *owner;  const char  *driver_name;  const char  *dev_name;  int    major;  int    minor;  int    nr;  struct console  *cons;

 struct uart_state *state;  struct tty_driver *tty_driver; };

 
 
 
一些基本接口:
set_baud
port_init 
config
write
startup shutdown
serial_init / exit
 
 

你可能感兴趣的:(linux)