Download presentation
Presentation is loading. Please wait.
Published byAllan Shields Modified over 9 years ago
1
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16
2
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 2
3
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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.RSWiki CSL Course Software 2014/12/23/16 3
4
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 4 Reference: wiki info: interrupt, http://en.wikipedia.org/wiki/Interrupthttp://en.wikipedia.org/wiki/Interrupt
5
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 5 Reference: Daniel P. Bovert & Marco Cesati, “Understanding the Linux Kernel 3 rd ”, chapter 4, O’Reilly
6
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 6 Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub
7
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 7 Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub
8
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 8
9
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 9 Reference: wiki info: timer, http://en.wikipedia.org/wiki/Timerhttp://en.wikipedia.org/wiki/Timer
10
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 10 Reference: VMWare, “Timekeeping in VMware Virtual Machines”, http://www.vmware.com/vmtn/resources/238http://www.vmware.com/vmtn/resources/238
11
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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.Intel PXA27x Processor Family Developer’s Manual 2014/12/23/16 11
12
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 12 Reference: Jonathan Corbet et al., “Linux Device Drivers 3 rd ”, chapter 10, O’Reilly
13
Lab 13 Department of Computer Science and Information Engineering National Taiwan University You can see /include/linux/jiffies.h which defines the timer interrupt frequency. #define ACTHZ And see /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/16 13
14
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 14
15
Lab 13 Department of Computer Science and Information Engineering National Taiwan University 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/16 15
16
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Show your sparkling 8-bit LED lamps in PXA270. Show your stopwatch. Display the time in 4-Digits 7 segment LED. Control the stopwatch by the keypad in PXA270. 2014/12/23/16 16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.