1 / 16

Computer System Laboratory

Computer System Laboratory. Lab13 – Interrupt + Timer. 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. Keypad. 4-Digits 7 Segment LED. 8-bit LED Lamps.

gezana
Download Presentation

Computer System Laboratory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer System Laboratory Lab13 – Interrupt + Timer

  2. 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. Keypad 4-Digits 7 Segment LED 8-bit LED Lamps / 16

  3. 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 / 16

  4. 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. Reference: wiki info: interrupt, http://en.wikipedia.org/wiki/Interrupt / 16

  5. 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 Reference: Daniel P. Bovert & Marco Cesati, “Understanding the Linux Kernel 3rd”, chapter 4, O’Reilly / 16

  6. 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. Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub / 16

  7. 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. Reference: David Rusling, “The Linux Kernel”, chapter 7, New Riders Pub / 16

  8. 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. intrequest_irq( unsigned intirq, void (*handler) (int, void *, structpt_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. / 16

  9. 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. Reference: wiki info: timer, http://en.wikipedia.org/wiki/Timer / 16

  10. 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. Reference: VMWare, “Timekeeping in VMware Virtual Machines”, http://www.vmware.com/vmtn/resources/238 / 16

  11. 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. / 16

  12. 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. Reference: Jonathan Corbet et al., “Linux Device Drivers 3rd”, chapter 10, O’Reilly / 16

  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(…) / 16

  14. 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 ScanTimerin 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. / 16

  15. 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. / 16

  16. 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. / 16

More Related