LKD: Chapter 7 Interrupts and Interrupt Handlers

  Recently I realized my English is still far from good. So in order to improve my English, I must not only read in English, but also think and write in English. I know I'm gonna make a lot of mistake in using English, but everything has a process so I just need to keep practiing my English.

  I use 2.6.34 instead of 2.6.32 as the book describes.

  There're two similar concepts:

Exceptions: synchronous interrupts generated by the processor.

Interrupts: asynchronous interrupts generated by hardware.

  In this chapter, we focus on the interrupts.

  Interrupt handlers are running in interrupt context, which cannot block.

  The processing of interrupts is split into two parts, or halves: 

Top Half(interrupt handler): time-critical

Bottom Half: deferred work.

Resgitering an Interrupt Handler(P116):  

/*     <linux/interrupt.h>     */
int request_irq ( unsigned int irq,      /* interrupt number */
                  irq_handler_t handler,   /* function pointer to the actual interrupt handler */
           unsigned long flags,    /* can be either zero or a bit mask */
           const char *name,      /* an ASCII text representation of the device */
           void *dev)          /* used for shared interrupt lines */

  The third parameter, flags: IRQF_DISABLED, IRQF_SAMPLE_RANDOM, IRQF_TIMER, IRQF_SHARED.

Freeing an Interrupt Handler:

void free_irq (unsigned int irq, void *dev)

  A call to free_irq() must be made from process context.

Writing an Interrupt Handler:

  The following is a declaration of an interrupt handler:

static irqreturn_t intr_handler ( int irq, void *dev)

  An interrupt handler return two special value:

IRQ_NONE: when the interrupt handler detects an interrupt for which its device was not the originator.

IRQ_HANDLED: the interrupt handler was correctly invoked, and its device did indeed cause the interrupt.

原文地址:https://www.cnblogs.com/justforfun12/p/5063518.html