computer system laboratory lab13 – interrupt + timer

16
COMPUTER SYSTEM LABORATORY Lab13 – Interrupt + Timer

Upload: debra-dalton

Post on 22-Dec-2015

223 views

Category:

Documents


3 download

TRANSCRIPT

COMPUTER SYSTEM

LABORATORYLab13 – Interrupt + Timer

/ 162Lab 13

Experimental Goal

•Understand the Linux interrupt handling, the hardware timer and Linux timer, and also learn how to control 8-bit LED lamps, 4-Digits 7 segment LED and keypad.

2013/12/17

4-Digits 7 Segment LED8-bit LED Lamps Keypad

/ 163Lab 13

Environment

•Host System• Windows XP

•Build System• VirtualBox + Ubuntu 8.04

•Target System• Creator XScale PXA270

•Software• Creator PXA270 LCD driver, please refer to Lab12

•You can download all software from RSWiki CSL Course Software

2013/12/17

/ 164Lab 13

Introduction to Interrupt

•An interrupt is a signal to the processor.

•The processor responds by suspending its current activities, saving its state, and executing a small program called an interrupt handler (interrupt service routine, ISR) to deal with the event.

•The act of initiating a hardware interrupt is referred to as an interrupt request (IRQ).

• Interrupts are a commonly used technique for computer multitasking.

2013/12/17

Reference: wiki info: interrupt, http://en.wikipedia.org/wiki/Interrupt

/ 165Lab 13

Two Types of Interrupt

• Asynchronous interrupt: caused by an external event.• Maskable interrupt (IRQ)

• E.g., I/O request

• Non-maskable interrupt

• E.g., watchdog timer

• Synchronous interrupt (Exception)• Faults

• E.g., page fault

• Traps

• E.g., divide by zero

• Aborts

• E.g., machine check

• Software interrupt

• E.g., system call2013/12/17

Reference: Daniel P. Bovert & Marco Cesati, “Understanding the Linux Kernel 3rd”, chapter 4, O’Reilly

/ 166Lab 13

Interrupt Routing

•Systems often use a programmable interrupt controller (PIC) to group the device interrupts together before passing on the signal to a single interrupt pin on the CPU.

2013/12/17

Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub

/ 167Lab 13

Linux Interrupt Handling

•Linux uses a table (irq_action) of pointers to data structures (irqaction) containing the addresses of the interrupt service routine (ISR).

•When interrupt happens, the kernel will execute the corresponding ISR to handle it.

2013/12/17

Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub

/ 168Lab 13

Register an Interrupt Handler

• In Linux, there is a related API, request_irq(), to register an interrupt handler, so developers can set their own handler with a specific IRQ.int request_irq(

unsigned int irq,

void (*handler) (int, void *, struct pt_regs *),

unsigned long irqflags,

const char *devname,

void *dev_id

);

• In the Creator PXA270 LCD driver, you can find this API which registers a timer interrupt.

2013/12/17

/ 169Lab 13

Introduction to Timer

•Computer systems usually have at least one timer. These are typically digital counters that decrement at a fixed frequency, which are often configurable and interrupt the processor when reaching zero.

•As the number of hardware timers in a computer system or processor is finite, OSes often use a single hardware timer to implement an extensible set of software timers.

•Some timer devices count up instead of down and have a register whose value is compared with the counter to determine when to interrupt and restart the count at zero.

2013/12/17

Reference: wiki info: timer, http://en.wikipedia.org/wiki/Timer

/ 1610Lab 13

Timer

•The oscillator provides a fixed input frequency to the timer device, and the counter counts down one unit for each cycle of the oscillator.

•When it reaches zero, it generates an interrupt signal.

•There might also be a counter input register whose value is loaded into the counter when it reaches zero.

2013/12/17

Reference: VMWare, “Timekeeping in VMware Virtual Machines”, http://www.vmware.com/vmtn/resources/238

/ 1611Lab 13

Timer Registers on PXA270

•PXA270 provides a set of timers that allows software to generate timer interrupts.

•The related registers on PXA270 are as follows:• OS Timer Count Registers (OSCRx): counter

• Count up one unit for each cycle of the oscillator.

• OS Timer Match Registers (OSMRx): counter input

• When OSCR reaches the value of OSMR, it will generate an interrupt.

• OS Match Control Registers (OMCRx): control OS timers

• Set the frequency of oscillator, set periodic timer, automatically reset OSCRx after it reaches the value of OSMRx, etc.

•For more information about these registers, please refer to Intel PXA27x Processor Family Developer’s Manual, Chapter 22.

2013/12/17

/ 1612Lab 13

Top and Bottom Halves

• Interrupt handlers need to finish up quickly and not keep interrupts blocked for long.

•Therefore, Linux splits the interrupt handler into two halves.• Top-half

• Perform time critical tasks, schedule its bottom half.

• Bottom-half

• Awake waiting processes, start up another I/O operation and so on.

2013/12/17

Reference: Jonathan Corbet et al., “Linux Device Drivers 3rd”, chapter 10, O’Reilly

/ 1613Lab 13

Linux Timer Interrupt

•You can see <Linux src>/include/linux/jiffies.h which defines the timer interrupt frequency.• #define ACTHZ

•And see <Linux src>/kernel/timer.c which defines the interrupt handler including both top-half and bottom-half.• Top-half: do_timer(…)

• Bottom-half: run_timer_softirq(…)

2013/12/17

/ 1614Lab 13

Lab Steps (1/2)

•Trace the driver’s code for 8-bit LED lamps, 4-Digits 7 segment LED and keypad to see how they work.

•Modify the driver codes such that the 8-bit LED lamps can sparkle in your own pattern.

•Hints• See creator_pxa270_lcdtxt_ioctl for these operations.

• See _7segment_timer_irq which is the timer interrupt handler.

• Trace ScanTimer in the driver to know how the keypad works.

• For more information about hardware registers, please refer to Create Creator PreSOCes Development Kit User’s Guide, 3.7.2, 3.7.3 and 3.7.4.

2013/12/17

/ 1615Lab 13

Lab Steps (2/2)

• Implement a stopwatch application.• The resolution should be in 0.1 second and 0.01 second, and switch it

by keypad.

• The value of the counter should be display on the 4-digit 7-segment LED in decimal form.

• It can be started, suspended, resumed, and reset by pressing the buttons of the keypad.

• Define these buttons’ action by yourself.

• You don’t have to (You’d better) modify the driver codes but you might need to create a header file for some input constants in your application.

2013/12/17

/ 1616Lab 13

Lab Requirement

•Please do teamwork for tracing codes of each device.• For example, two guys trace the timer interrupt handler, the others

trace the keypad.

•Show your sparkling 8-bit LED lamps in PXA270.

•Show your stopwatch application.• Display the time in 4-Digits 7 segment LED.

• Control the stopwatch by the keypad in PXA270.

2013/12/17