Handling a UART interrupt A look at some recent changes in the Linux kernel’s programming interface for device-interrupts.

Slides:



Advertisements
Similar presentations
Jim Chen ( 14/06/2011 Hytec Electronics Ltd.
Advertisements

Linux device-driver issues
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
RT_FIFO, Device driver.
Computer System Laboratory
1 Homework Reading (linked from my web page) –S and S Extracts –National Semiconductor UART Data Sheet Machine Projects –mp2 due at start of class 12 Labs.
Tutorial 3 - Linux Interrupt Handling -
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Programmable Interval Timer
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
The ATA/IDE Interface Can we write a character-mode device driver for the hard disk?
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Interfacing The Serial/RS-232 Port Hardware Serial Port Registers Programming.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Using x86 “protected mode” on our anchor-cluster’s machines A look at some terminal emulation features utilized in the “console- redirection” mechanism.
1 Homework Reading –Review previous material on “interrupts” Machine Projects –MP4 Due today –Starting on MP5 (Due at start of Class 28) Labs –Continue.
On using ‘tasklets’ An example of the Linux kernel’s ‘tasklet’ mechanism for deferring some interrupt-handling work.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
The RealTek interface Introduction to the RTL-8139 network controller registers.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Implementing interrupt driven IO. Why use interrupt driven IO? Positive points –Allows asynchronous operation of IO events –Good use of resources –Leads.
Testing Communication Systems  When point-to-point communication between two DTEs is not functioning, which DTE is at fault? Or which DTE is correctly.
Examining network packets Information about the RTL8139 needed for understanding our ‘watch235.c’ pseudo driver.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
The UART project Applying what we’ve learned about Linux device-drivers to the PC’s serial-port controller.
PC Modem Control The 8250 UART supplied with the PC supports a limited number of RS-232-C modem functions: The UART can be programmed to interrupt the.
Chapter 7 Interupts DMA Channels Context Switching.
Our ‘nic.c’ module We create a ‘character-mode’ device-driver for the 82573L NIC to use in future experiments.
Computer Science 686 Spring 2007 Special Topic: Intel EM64T and VT Extensions.
A network driver ‘framework’ We construct a ‘skeleton’ module showing just the essential pieces of a Linux network device driver.
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati. I/O Port Addressing UART Port Basic – Standardized UART UART Programming in C Loop back program.
Operating System Program 5 I/O System DMA Device Driver.
COMP201 Computer Systems Exceptions and Interrupts.
Interrupt Handling Sarah Diesburg COP Interrupt Handling One big responsibility of an operating system is to handle hardware connected to the machine.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Industrial Reference Design Platform RS-232 Interface Developed by the TSC Americas Release 1.0.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
CS 6560 Operating System Design Lecture 5: System Calls Interrupts.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
NFC Forum Type 2 Tag Platform Operations with the TRF7970A TI NFC/RFID Applications Team.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Ch 6. Interrupts and Interrupt Handlers. Overview (1) A primary responsibility of the kernel is managing the hardware connected to the machine  The kernel.
Amdahl’s Law & I/O Control Method 1. Amdahl’s Law The overall performance of a system is a result of the interaction of all of its components. System.
Using Linux with ARM Tutorial #3.
8251 USART.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Lecture 7 Interrupt ,Trap and System Call
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
Lecture 15. Modem Controller Register 4310 DTR 0 = Polling Operator 1 = Interrupts Enabled RTS 1 =Self Test 0 =Normal.
Homework Reading Machine Projects
Linux Kernel Development - Robert Love
CS-401 Computer Architecture & Assembly Language Programming
Homework Reading (linked from my web page) Machine Projects Labs
Homework Reading Machine Projects Labs
Transmitter Interrupts
Linux Kernel Programming CIS 4930/COP 5641
UART PC16550 (Universal Asynchronous Receiver/Transmitter) By Derwyn Hollobaugh
Who’s listening? Some experiments with an ‘echo’ service on our anchor-cluster’s local network of 82573L nic’s.
Presentation transcript:

Handling a UART interrupt A look at some recent changes in the Linux kernel’s programming interface for device-interrupts

The new ‘anchor’ cluster To reduce contention for CS workstations that have null-modem cables attached, we are bringing online an additional cluster of eight servers – you access them remotely ‘anchor00’‘anchor01’ ‘anchor02’‘anchor03’ ‘anchor04’‘anchor05’ ‘anchor06’‘anchor07’ Thanks to overnight efforts by Alex Fedosov and our CS support-team!

LDD3: kernel Our text “Linux Device Drivers (3 rd Ed)” is published by O’Reilly in February 2005 The kernel version it covers is But in our classroom we are using a more recent version of the kernel (i.e., ) which was released in mid-August 2007 Various changes (improvements) are now implemented (and differ from LDD3 book)

Example 1 Our textbook shows the prototype for a device-driver’s interrupt service routine: irqreturn_t isr( int irq, void *dev_id, struct pt_regs *regs ); But this has changed in kernel to: Irqreturn_t isr( int irq, void *dev_id ); What prompted the kernel developers to remove that third function-argument? Just a guess, but probably it was because programmers were not actually using it

Example 2 The kernel’s header-files provided symbolic names for important interrupt-related constants in : #define SA_SHIRQ0x Such definitions, formerly replicated for each supported CPU architecture, have now been consolidated (and renamed) in the kernel header-file : #define IRQF_SHARED0x

Consequences If you try to apply the textbook discussion about interrupt-handlers to your LKMs for this class, the compiler will generate error messages and/or warning messages So you will need to use the “new” kernel’s interfaces, not documented in our textbook Maybe you can locate an online tutorial, or look at other device-drivers’ source-code

Our ‘uartintr.c’ module We have written a kernel module that you can study (and experiment with) showing an interrupt-handler for the UART device that we created purely for demonstration purposes using kernel version Obviously you would need to modify it if you wanted to use an interrupt-handler in your solution for our course’s Project #2

Module’s components init exit The isr function The LKM layout registers the ‘isr’ and then enables the UART device to generate interrupt-signals disables the UART’s interrupt-signals and then unregisters this module’s ‘isr’ module’s ‘payload’ is just a single callback-function that will ‘handle’ a UART interrupt the usual pair of module-administration functions

Interrupt Identification Register = FIFO-mode has not been enabled 11 = FIFO-mode is currently enabled 1 = No UART interrupts are pending 0 = At least one UART interrupt is pending ‘highest priority’ UART interrupt still pending highest 011 = receiver line-status 010 = received data ready 100 = character timeout 001 = Tx Holding Reg empty 000 = modem-status change lowest

An interrupt service routine Whenever the UART receives a new byte of data, it will transmit it back to the sender #include #define UART_BASE0x03F8 irqreturn_t my_uart_isr( int irq, void *dev_id ) { intintr_identify = inb( UART_BASE + 2 ) & 0x0F; if ( intr_identify == 0x01 ) return IRQ_NONE; if ( intr_identify == 0x04 ) // a new character has arrived outb( inb( UART_BASE ), UART_BASE ); return IRQ_HANDLED; }

Installing the ‘isr()’ Here is how your module asks the kernel to execute your UART interrupt-handler: #define UART_IRQ4 // signal-line’s number to the IO-APIC char modname[] = “uartintr”; // kernel displays this in ‘/proc/interrupts’ static int __init my_init( void ) { … if ( request_irq( UART_IRQ, &my_uart_isr, IRQF_SHARED, modname, &modname ) < 0 ) return –EBUSY; … // your code to enable the UART’s interrupts goes here … return 0; // SUCCESS }

Interrupt Enable Register 0000 Modem Status change Rx Line Status change THR is empty Received data is available If enabled (by setting the bit to 1), the UART will generate an interrupt: (bit 3) whenever modem status changes (bit 2) whenever a receive-error is detected (bit 1) whenever the transmit-buffer is empty (bit 0) whenever the receive-buffer is nonempty Also, in FIFO mode, a ‘timeout’ interrupt will be generated if neither FIFO has been ‘serviced’ for at least four character-clock times

FIFO Control Register RCVR FIFO trigger-level reserved DMA Mode select XMIT FIFO reset RCVR FIFO reset FIFO enable Writing 0 will disable the UART’s FIFO-mode, writing 1 will enable FIFO-mode Writing 1 empties the FIFO, writing 0 has no effect 00 = 1 byte 01 = 4 bytes 10 = 8 bytes 11 = 14 bytes NOTE: DMA is unsupported for the UART on our systems

Modem Control Register 000 LOOP BACK OUT2OUT1RTSDTR Legend: DTR = Data Terminal Ready (1=yes, 0=no) RTS = Request To Send (1=yes, 0=no) OUT1 = not used (except in loopback mode) OUT2 = enables the UART to issue interrupts LOOPBACK-mode (1=enabled, 0=disabled)

UART initialization Here is code that initializes the UART (its baud-rate and data-format) and enables it to generate ‘character received’ interrupts: // initialize the UART device for the desired demo operations outb( 0x01, UART_BASE + 1 );// issue RDR interrupts outb( 0x00, UART_BASE + 2 );// turn off FIFO-mode outb( 0x80, UART_BASE + 3 );// SET DLAB=1 outw( 0x0001, UART_BASE );// DIVISOR_LATCH = 1 outb( 0x03, UART_BASE + 3 );// data-format is 8-N-1 outb( 0x0B, UART_BASE + 4 );// DSR=1, RTS=1, OUT2=1

Disabling UART interrupts Here is code that disables any more UART interrupts, so that your module’s ‘cleanup’ can safely remove your interrupt-handler: static __exit my_exit( void ) { … // disable any further UART interrupt-requests outb( 0x00, UART_BASE + 1 );// INTERRUPT_ENABLE outb( 0x00, UART_BASE + 4 );// MODEM_CONTROL // remove your UART interrupt-service routine free_irq( UART_IRQ, modname ); … }

In-class exercise Try running our ‘trycable.cpp’ application on an adjacent workstation after you have downloaded, compiled, and installed our ‘uartintr.c’ demo-module What do you see on the two screens? Tonight’s class ends early -- so that you can attend the ACM Chapter’s Pizza Night