SlideShare a Scribd company logo
LINUX SERIAL DRIVER
1
2
Byte Frame
8N1 signifies 8 Data bits, No Parity and 1 Stop Bit
TTL/CMOS Serial Logic Waveform
RS-232 Logic Waveform
Frame
Baud rate
1) 50 – 921.6kbps
Data bits
1) 5, 6, 7, 8
Parity
1) None, Odd, Even, Mark, Space
Stop bits
1) 1, 1.5/2 (1.5 for data bits=5)
Flow control
1) RTS/CTS, Xon/Xoff, DTR/DSR
3
Serial Parameter/Setting
N81 is common used in RS-232.
Sometimes E71/E72/O71/O72 will also be selected.
Modem line (in/out define)
Neck Name In/Out Comment
RTS Out Control the remote send or pause, to do
flow control
CTS In the remote note me to send or not, to do
flow control
DTR Out DTE ready, the old method to do flow
control
DSR In DCE ready, the old method to do flow
control
DCD In for DTE
Out for DCE
to indicate the phone is hank off
RI In for DTE
Out for DCE
Ring, the telephone is ringed
5
How to connect to remote – RS232
Tx
Rx
RTS
CTS
DTR
DSR
DCD
RI
Tx
Rx
RTS
CTS
DTR
DSR
DCD
RI
Hardware flow control to use RTS/CTS
1) RTS low to let the remoter to stop transmitting
2) RTS high to let the remoter to restart transmitting
3) CTS low to stop my transmitting
4) CTS high to restart my transmitting
Software flow control to use some character, so the data must
be escape it
1) Send Xoff to let the remoter to stop transmitting
2) Send Xon to let the remoter to restart transmitting
3) Receive Xoff to stop my transmitting
4) Receive Xon to restart my transmitting
6
Flow control
7
Flow Control with RTS/CTS (H/W)
Tx
Tx
Rx
Rx
Rx Buffer
low
high
RTS
CTS
high
low
8
Flow Control with Xon/Xoff (S/W)
Tx
Tx
Rx
Rx
Rx Buffer
low
high
Xoff
Xon
Xoff
Xon
9
Serial Device Driver Architecture
Hardware Serial Device
Serial Device Driver
tty Device Driver
Line description Device Driver
Application by termio/termios API Kernel
To do the basic
terminal
read/write/ioc
tl control
To control the
hardware
receive/transfer
To do about
the terminal
control
8250是一種不成文的硬件規格
原始碼所在目錄:drivers/serial
SoC的serial port通常都會使用
10
標準8250 serial device driver
serial_core.c
8250.c
tty
console
宣告一個resource sturcture如下:
static struct uart_port my_uart_init[] __initdata = {
[0] = {
.membase = VA_UART_BASE, // virtual address
.mapbase = PA_UART_BASE, // physical address
.irq = IRQ_UART,
.flags = UPF_SKIP_TEST,
.iotype = UPIO_MEM32,
.regshift = 2,
.uartclk = 921600 * 16,
.line = 0, // which port number on system
.type = PORT_16550A,
.fifosize = 16,
},
};
呼叫kernel API加入
early_serial_setup(&my_uart_init[0]); // embedded UART port
11
如何增加一個8250的port
Examlpe
MACHINE_START(MOXACPU, "Moxa CPU development platform")
.phys_io = 0x80000000,
.io_pg_offst = ((IO_ADDRESS(0x80000000)>>18)&0xfffc),
.map_io = map_io,
.init_irq = irq_init_irq,
.timer = &moxacpu_timer,
.fixup = fixup,
.boot_params = 0x100,
.init_machine = moxacpu_init,
MACHINE_END
void __init map_io(void)
{
iotable_init(mycpu_io_desc, sizeof(mycpu_io_desc)/sizeof(struct
map_desc));
early_serial_setupS
除了標準的8250暫存器之外,還有其它額
外的暫存器
FIFO大小通常是大於16個
會有多個port在系統上
有的會有CPU的智能卡
13
非標準的8250 serial driver
struct tty_driver myuart_sdriver =
alloc_tty_driver(TOTAL_PORTS);
Initialize the tty_driver structure
myuart_sdriver->owner = THIS_MODULE;
myuart_sdriver->magic = TTY_DRIVER_MAGIC;
myuart_sdriver->name = "ttyMI";
myuart_sdriver->major = ttymajor;
myuart_sdriver->minor_start = 0;
myuart_sdriver->num = MXSER_PORTS + 1;
myuart_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
myuart_sdriver->subtype = SERIAL_TYPE_NORMAL;
myuart_sdriver->init_termios = tty_std_termios;
myuart_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
myuart_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
tty_set_operations(myuart_sdriver, &myuart_ops);
retval = tty_register_driver(myuart_sdriver);
tty_register_device(myuart_sdriver, ports, NULL);
14
Driver的初始化
static const struct tty_operations mxser_ops = {
.open = myuart_open,
.close = myuart_close,
.write = myuart_write,
.put_char = myuart_put_char,
.flush_chars = myuart_flush_chars,
.write_room = myuart_write_room,
.chars_in_buffer = myuart_chars_in_buffer,
.flush_buffer = myuart_flush_buffer,
.ioctl = myuart_ioctl,
.throttle = myuart_throttle,
.unthrottle = myuart_unthrottle,
.set_termios = myuart_set_termios,
.stop = myuart_stop,
.start = myuart_start,
.hangup = myuart_hangup,
.break_ctl = myuart_rs_break,
.wait_until_sent = myuart_wait_until_sent,
.tiocmget = myuart_tiocmget,
.tiocmset = myuart_tiocmset,
};
15
Set tty operations
Driver Initialize Example
static int __init mxser_module_init(void)
{
mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
mxvar_sdriver->name = "ttyMI";
mxvar_sdriver->major = ttymajor;
mxvar_sdriver->minor_start = 0;
mxvar_sdriver->num = MXSER_PORTS + 1;
mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
mxvar_sdriver->init_termios = tty_std_termios;
mxvar_sdriver->init_termios.c_cflag =B9600|CS8|CREAD|HUPCL|CLOCAL;
mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
tty_set_operations(mxvar_sdriver, &mxser_ops);
retval = tty_register_driver(mxvar_sdriver);
retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser",
brd);
…………………………..
for (i = 0; i < brd->info->nports; i++)
tty_register_device(mxvar_sdriver, brd->idx + i, NULL);
……………………….
return 0;
}
Driver Open/Close Example
static int mxser_open(struct tty_struct *tty, struct file *filp)
{
port = tty->index; // minor or port number
tty->driver_data = info; // set private data
spin_lock_irqsave(&info->slock, flags);
info->port.count++;
spin_unlock_irqrestore(&info->slock, flags);
retval = mxser_startup(info);
return 0;
}
static void mxser_close(struct tty_struct *tty, struct file *filp)
{
struct mxser_port *info = tty->driver_data;
if (--info->port.count) {
return;
}
…………………………
if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
tty_wait_until_sent(tty, info->port.closing_wait);
mxser_shutdown(info);
mxser_flush_buffer(tty);
tty_ldisc_flush(tty);
}
Driver Write Example
static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
………………………..
while (1) {
…………………..
memcpy(info->port.xmit_buf + info->xmit_head, buf, c);
…………………..
}
if (info->xmit_cnt && !tty->stopped) {
if (!tty->hw_stopped ||
(info->type == PORT_16550A) ||
(info->board->chip_flag)) {
spin_lock_irqsave(&info->slock, flags);
outb(info->IER & ~UART_IER_THRI, info->ioaddr +
UART_IER);
info->IER |= UART_IER_THRI;
outb(info->IER, info->ioaddr + UART_IER);
spin_unlock_irqrestore(&info->slock, flags);
}
}
return total;
}
Receive Interrupt Example
recv_room = tty->receive_room;
if ((recv_room == 0) && (!port->ldisc_stop_rx))
mxser_stoprx(tty);
…………………………………
while (gdl--) {
ch = inb(port->ioaddr + UART_RX);
tty_insert_flip_char(tty, ch, 0);
cnt++;
}
…………………………………..
spin_unlock(&port->slock);
tty_flip_buffer_push(tty);
spin_lock(&port->slock);
……………………………
#define NCCS 32
struct termios
{
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
};
20
termios structure
/* c_cc characters */
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16
#include <termios.h>
#include <unistd.h>
int tcgetattr(int fd, struct termios *termios_p);
int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
int tcsendbreak(int fd, int duration);
int tcdrain(int fd);
int tcflush(int fd, int queue_selector);
int tcflow(int fd, int action);
void cfmakeraw(struct termios *termios_p);
speed_t cfgetispeed(const struct termios *termios_p);
speed_t cfgetospeed(const struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);
int cfsetspeed(struct termios *termios_p, speed_t speed);
21
API
AP example
#include <termios.h>
int main(int argc, char *argv[])
{
int fd;
struct termios trem;
fd = open(“/dev/ttyS0”, O_RDWR);
tcgetattr(fd, &term);
term.lflag = 0;
term.iflag = 0;
term.cflag = B115200 | CS8|CREAD|CLOCAL;
term.oflag = 0;
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 1;
tcsetattr(fd, TCDRAIN, &term);
tcflush(fd,TCIOFLUSH);
……………
write(fd, buf, len);
……………………
read(fd, buf, len);
………………..
close(fd);
}

More Related Content

What's hot

qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
Adrian Huang
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
Linux kernel status in RISC-V
Linux kernel status in RISC-VLinux kernel status in RISC-V
Linux kernel status in RISC-V
Atish Patra
 
Platform Drivers
Platform DriversPlatform Drivers
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
Macpaul Lin
 
Linux booting process
Linux booting processLinux booting process
Linux booting process
Prashant Hegde
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
SUSE Labs Taipei
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
RajKumar Rampelli
 
Spi drivers
Spi driversSpi drivers
Spi drivers
pradeep_tewani
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
Linaro
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
Adrian Huang
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
Satpal Parmar
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
Adrian Huang
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image艾鍗科技
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
Abhishek Sagar
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
Gene Chang
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
linuxlab_conf
 

What's hot (20)

Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Linux kernel status in RISC-V
Linux kernel status in RISC-VLinux kernel status in RISC-V
Linux kernel status in RISC-V
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
 
Linux booting process
Linux booting processLinux booting process
Linux booting process
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Character Drivers
Character DriversCharacter Drivers
Character Drivers
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 

Viewers also liked

Linux Jffs2 & Linux MTD Device
Linux Jffs2 & Linux  MTD DeviceLinux Jffs2 & Linux  MTD Device
Linux Jffs2 & Linux MTD Device
艾鍗科技
 
GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用
艾鍗科技
 
成果展簡報-Zigbee無線自動燈光及溫度調控系統
成果展簡報-Zigbee無線自動燈光及溫度調控系統成果展簡報-Zigbee無線自動燈光及溫度調控系統
成果展簡報-Zigbee無線自動燈光及溫度調控系統
艾鍗科技
 
銀髮幼童健康定位手環
銀髮幼童健康定位手環銀髮幼童健康定位手環
銀髮幼童健康定位手環
艾鍗科技
 
用Raspberry Pi 完成一個智慧型六足機器人
用Raspberry Pi 完成一個智慧型六足機器人用Raspberry Pi 完成一個智慧型六足機器人
用Raspberry Pi 完成一個智慧型六足機器人
艾鍗科技
 
智能風扇
智能風扇智能風扇
智能風扇
艾鍗科技
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
Aniket Thakur
 
Programming The Arm Microprocessor For Embedded Systems
Programming The Arm Microprocessor For Embedded SystemsProgramming The Arm Microprocessor For Embedded Systems
Programming The Arm Microprocessor For Embedded Systemsjoshparrish13
 

Viewers also liked (8)

Linux Jffs2 & Linux MTD Device
Linux Jffs2 & Linux  MTD DeviceLinux Jffs2 & Linux  MTD Device
Linux Jffs2 & Linux MTD Device
 
GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用GPS + Google fusion table 雲端應用
GPS + Google fusion table 雲端應用
 
成果展簡報-Zigbee無線自動燈光及溫度調控系統
成果展簡報-Zigbee無線自動燈光及溫度調控系統成果展簡報-Zigbee無線自動燈光及溫度調控系統
成果展簡報-Zigbee無線自動燈光及溫度調控系統
 
銀髮幼童健康定位手環
銀髮幼童健康定位手環銀髮幼童健康定位手環
銀髮幼童健康定位手環
 
用Raspberry Pi 完成一個智慧型六足機器人
用Raspberry Pi 完成一個智慧型六足機器人用Raspberry Pi 完成一個智慧型六足機器人
用Raspberry Pi 完成一個智慧型六足機器人
 
智能風扇
智能風扇智能風扇
智能風扇
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
 
Programming The Arm Microprocessor For Embedded Systems
Programming The Arm Microprocessor For Embedded SystemsProgramming The Arm Microprocessor For Embedded Systems
Programming The Arm Microprocessor For Embedded Systems
 

Similar to Linux Serial Driver

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
Syed Ghufran Hassan
 
Cs423 raw sockets_bw
Cs423 raw sockets_bwCs423 raw sockets_bw
Cs423 raw sockets_bw
jktjpc
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -evechiportal
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
Jens Siebert
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
SANTIAGO PABLO ALBERTO
 
An Example MIPS
An Example  MIPSAn Example  MIPS
An Example MIPS
Sandra Long
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
Flor Ian
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15종인 전
 
Micro
MicroMicro
Micro
Moaz Zahid
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
hairilfaiz86
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
Svet Ivantchev
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
Michelle Holley
 
Vectorization on x86: all you need to know
Vectorization on x86: all you need to knowVectorization on x86: all you need to know
Vectorization on x86: all you need to knowRoberto Agostino Vitillo
 
-----------------------------------------------------CPU.java------.pdf
 -----------------------------------------------------CPU.java------.pdf -----------------------------------------------------CPU.java------.pdf
-----------------------------------------------------CPU.java------.pdf
annikasarees
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
footstatus
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321Teddy Hsiung
 

Similar to Linux Serial Driver (20)

codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Cs423 raw sockets_bw
Cs423 raw sockets_bwCs423 raw sockets_bw
Cs423 raw sockets_bw
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
An Example MIPS
An Example  MIPSAn Example  MIPS
An Example MIPS
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15
 
Intel Quark HSUART
Intel Quark HSUARTIntel Quark HSUART
Intel Quark HSUART
 
Micro
MicroMicro
Micro
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Seminar
SeminarSeminar
Seminar
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
 
Vectorization on x86: all you need to know
Vectorization on x86: all you need to knowVectorization on x86: all you need to know
Vectorization on x86: all you need to know
 
Uart
UartUart
Uart
 
-----------------------------------------------------CPU.java------.pdf
 -----------------------------------------------------CPU.java------.pdf -----------------------------------------------------CPU.java------.pdf
-----------------------------------------------------CPU.java------.pdf
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
 

More from 艾鍗科技

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
艾鍗科技
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
艾鍗科技
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用
艾鍗科技
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
艾鍗科技
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
艾鍗科技
 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
艾鍗科技
 
Step motor
Step motorStep motor
Step motor
艾鍗科技
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介
艾鍗科技
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
艾鍗科技
 
3. data features
3. data features3. data features
3. data features
艾鍗科技
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進
艾鍗科技
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆
艾鍗科技
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作
艾鍗科技
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車
艾鍗科技
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作
艾鍗科技
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車
艾鍗科技
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
艾鍗科技
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
艾鍗科技
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統
艾鍗科技
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home
艾鍗科技
 

More from 艾鍗科技 (20)

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
 
Step motor
Step motorStep motor
Step motor
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
 
3. data features
3. data features3. data features
3. data features
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home
 

Recently uploaded

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

Linux Serial Driver

  • 2. 2 Byte Frame 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit TTL/CMOS Serial Logic Waveform RS-232 Logic Waveform Frame
  • 3. Baud rate 1) 50 – 921.6kbps Data bits 1) 5, 6, 7, 8 Parity 1) None, Odd, Even, Mark, Space Stop bits 1) 1, 1.5/2 (1.5 for data bits=5) Flow control 1) RTS/CTS, Xon/Xoff, DTR/DSR 3 Serial Parameter/Setting N81 is common used in RS-232. Sometimes E71/E72/O71/O72 will also be selected.
  • 4. Modem line (in/out define) Neck Name In/Out Comment RTS Out Control the remote send or pause, to do flow control CTS In the remote note me to send or not, to do flow control DTR Out DTE ready, the old method to do flow control DSR In DCE ready, the old method to do flow control DCD In for DTE Out for DCE to indicate the phone is hank off RI In for DTE Out for DCE Ring, the telephone is ringed
  • 5. 5 How to connect to remote – RS232 Tx Rx RTS CTS DTR DSR DCD RI Tx Rx RTS CTS DTR DSR DCD RI
  • 6. Hardware flow control to use RTS/CTS 1) RTS low to let the remoter to stop transmitting 2) RTS high to let the remoter to restart transmitting 3) CTS low to stop my transmitting 4) CTS high to restart my transmitting Software flow control to use some character, so the data must be escape it 1) Send Xoff to let the remoter to stop transmitting 2) Send Xon to let the remoter to restart transmitting 3) Receive Xoff to stop my transmitting 4) Receive Xon to restart my transmitting 6 Flow control
  • 7. 7 Flow Control with RTS/CTS (H/W) Tx Tx Rx Rx Rx Buffer low high RTS CTS high low
  • 8. 8 Flow Control with Xon/Xoff (S/W) Tx Tx Rx Rx Rx Buffer low high Xoff Xon Xoff Xon
  • 9. 9 Serial Device Driver Architecture Hardware Serial Device Serial Device Driver tty Device Driver Line description Device Driver Application by termio/termios API Kernel To do the basic terminal read/write/ioc tl control To control the hardware receive/transfer To do about the terminal control
  • 11. 宣告一個resource sturcture如下: static struct uart_port my_uart_init[] __initdata = { [0] = { .membase = VA_UART_BASE, // virtual address .mapbase = PA_UART_BASE, // physical address .irq = IRQ_UART, .flags = UPF_SKIP_TEST, .iotype = UPIO_MEM32, .regshift = 2, .uartclk = 921600 * 16, .line = 0, // which port number on system .type = PORT_16550A, .fifosize = 16, }, }; 呼叫kernel API加入 early_serial_setup(&my_uart_init[0]); // embedded UART port 11 如何增加一個8250的port
  • 12. Examlpe MACHINE_START(MOXACPU, "Moxa CPU development platform") .phys_io = 0x80000000, .io_pg_offst = ((IO_ADDRESS(0x80000000)>>18)&0xfffc), .map_io = map_io, .init_irq = irq_init_irq, .timer = &moxacpu_timer, .fixup = fixup, .boot_params = 0x100, .init_machine = moxacpu_init, MACHINE_END void __init map_io(void) { iotable_init(mycpu_io_desc, sizeof(mycpu_io_desc)/sizeof(struct map_desc)); early_serial_setupS
  • 14. struct tty_driver myuart_sdriver = alloc_tty_driver(TOTAL_PORTS); Initialize the tty_driver structure myuart_sdriver->owner = THIS_MODULE; myuart_sdriver->magic = TTY_DRIVER_MAGIC; myuart_sdriver->name = "ttyMI"; myuart_sdriver->major = ttymajor; myuart_sdriver->minor_start = 0; myuart_sdriver->num = MXSER_PORTS + 1; myuart_sdriver->type = TTY_DRIVER_TYPE_SERIAL; myuart_sdriver->subtype = SERIAL_TYPE_NORMAL; myuart_sdriver->init_termios = tty_std_termios; myuart_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; myuart_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(myuart_sdriver, &myuart_ops); retval = tty_register_driver(myuart_sdriver); tty_register_device(myuart_sdriver, ports, NULL); 14 Driver的初始化
  • 15. static const struct tty_operations mxser_ops = { .open = myuart_open, .close = myuart_close, .write = myuart_write, .put_char = myuart_put_char, .flush_chars = myuart_flush_chars, .write_room = myuart_write_room, .chars_in_buffer = myuart_chars_in_buffer, .flush_buffer = myuart_flush_buffer, .ioctl = myuart_ioctl, .throttle = myuart_throttle, .unthrottle = myuart_unthrottle, .set_termios = myuart_set_termios, .stop = myuart_stop, .start = myuart_start, .hangup = myuart_hangup, .break_ctl = myuart_rs_break, .wait_until_sent = myuart_wait_until_sent, .tiocmget = myuart_tiocmget, .tiocmset = myuart_tiocmset, }; 15 Set tty operations
  • 16. Driver Initialize Example static int __init mxser_module_init(void) { mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1); mxvar_sdriver->name = "ttyMI"; mxvar_sdriver->major = ttymajor; mxvar_sdriver->minor_start = 0; mxvar_sdriver->num = MXSER_PORTS + 1; mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL; mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; mxvar_sdriver->init_termios = tty_std_termios; mxvar_sdriver->init_termios.c_cflag =B9600|CS8|CREAD|HUPCL|CLOCAL; mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(mxvar_sdriver, &mxser_ops); retval = tty_register_driver(mxvar_sdriver); retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser", brd); ………………………….. for (i = 0; i < brd->info->nports; i++) tty_register_device(mxvar_sdriver, brd->idx + i, NULL); ………………………. return 0; }
  • 17. Driver Open/Close Example static int mxser_open(struct tty_struct *tty, struct file *filp) { port = tty->index; // minor or port number tty->driver_data = info; // set private data spin_lock_irqsave(&info->slock, flags); info->port.count++; spin_unlock_irqrestore(&info->slock, flags); retval = mxser_startup(info); return 0; } static void mxser_close(struct tty_struct *tty, struct file *filp) { struct mxser_port *info = tty->driver_data; if (--info->port.count) { return; } ………………………… if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) tty_wait_until_sent(tty, info->port.closing_wait); mxser_shutdown(info); mxser_flush_buffer(tty); tty_ldisc_flush(tty); }
  • 18. Driver Write Example static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count) { ……………………….. while (1) { ………………….. memcpy(info->port.xmit_buf + info->xmit_head, buf, c); ………………….. } if (info->xmit_cnt && !tty->stopped) { if (!tty->hw_stopped || (info->type == PORT_16550A) || (info->board->chip_flag)) { spin_lock_irqsave(&info->slock, flags); outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER); info->IER |= UART_IER_THRI; outb(info->IER, info->ioaddr + UART_IER); spin_unlock_irqrestore(&info->slock, flags); } } return total; }
  • 19. Receive Interrupt Example recv_room = tty->receive_room; if ((recv_room == 0) && (!port->ldisc_stop_rx)) mxser_stoprx(tty); ………………………………… while (gdl--) { ch = inb(port->ioaddr + UART_RX); tty_insert_flip_char(tty, ch, 0); cnt++; } ………………………………….. spin_unlock(&port->slock); tty_flip_buffer_push(tty); spin_lock(&port->slock); ……………………………
  • 20. #define NCCS 32 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ speed_t c_ispeed; /* input speed */ speed_t c_ospeed; /* output speed */ #define _HAVE_STRUCT_TERMIOS_C_ISPEED 1 #define _HAVE_STRUCT_TERMIOS_C_OSPEED 1 }; 20 termios structure /* c_cc characters */ #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VEOF 4 #define VTIME 5 #define VMIN 6 #define VSWTC 7 #define VSTART 8 #define VSTOP 9 #define VSUSP 10 #define VEOL 11 #define VREPRINT 12 #define VDISCARD 13 #define VWERASE 14 #define VLNEXT 15 #define VEOL2 16
  • 21. #include <termios.h> #include <unistd.h> int tcgetattr(int fd, struct termios *termios_p); int tcsetattr(int fd, int optional_actions, const struct termios *termios_p); int tcsendbreak(int fd, int duration); int tcdrain(int fd); int tcflush(int fd, int queue_selector); int tcflow(int fd, int action); void cfmakeraw(struct termios *termios_p); speed_t cfgetispeed(const struct termios *termios_p); speed_t cfgetospeed(const struct termios *termios_p); int cfsetispeed(struct termios *termios_p, speed_t speed); int cfsetospeed(struct termios *termios_p, speed_t speed); int cfsetspeed(struct termios *termios_p, speed_t speed); 21 API
  • 22. AP example #include <termios.h> int main(int argc, char *argv[]) { int fd; struct termios trem; fd = open(“/dev/ttyS0”, O_RDWR); tcgetattr(fd, &term); term.lflag = 0; term.iflag = 0; term.cflag = B115200 | CS8|CREAD|CLOCAL; term.oflag = 0; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 1; tcsetattr(fd, TCDRAIN, &term); tcflush(fd,TCIOFLUSH); …………… write(fd, buf, len); …………………… read(fd, buf, len); ……………….. close(fd); }