Application of Interrupt and Timer : Measurement of Motor Speed.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13...
-
Upload
allan-shields -
Category
Documents
-
view
216 -
download
0
Transcript of Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13...
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /161
Computer System Laboratory
Lab13 – Interrupt + Timer
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /162
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.
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /163
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.
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /164
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.
2014/12/23
Reference: wiki info: interrupt, http://en.wikipedia.org/wiki/Interrupt
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /165
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 call
2014/12/23
Reference: Daniel P. Bovert & Marco Cesati, “Understanding the Linux Kernel 3rd”, chapter 4, O’Reilly
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /166
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.
2014/12/23
Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /167
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.
2014/12/23
Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /168
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.
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /169
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.
2014/12/23
Reference: wiki info: timer, http://en.wikipedia.org/wiki/Timer
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1610
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.
2014/12/23
Reference: VMWare, “Timekeeping in VMware Virtual Machines”, http://www.vmware.com/vmtn/resources/238
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1611
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.
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1612
Top and Bottom Halves
Interrupt handlers need to finish up quickly and do not keep interrupts blocked for long.
Therefore, Linux splits an interrupt handler into two halves. Top-half
Perform time critical tasks, and schedule its bottom half. Bottom-half
Awake waiting processes, and start up another I/O operation and so on.
2014/12/23
Reference: Jonathan Corbet et al., “Linux Device Drivers 3rd”, chapter 10, O’Reilly
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1613
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 both top-half and bottom-half of interrupt handlers. Top-half: do_timer(…) Bottom-half: run_timer_softirq(…)
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1614
Lab Steps (1/2)
Trace the driver’s code for 8-bit LED lamps, 4-Digits 7 segment LED and keypad, and 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.
2014/12/23
Lab 13 Department of Computer Science and Information EngineeringNational Taiwan University /1615
Lab Steps (2/2)
Implement a stopwatch. The resolution should be in 0.1 second and 0.01 second which can be switched
by the keypad. The value of the counter should be displayed 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 actions of the keypad by yourselves.
2014/12/23