<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Interrupt Handling</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Video4Linux Programming" HREF="book1.html"><LINK REL="UP" TITLE="Video Capture Devices" HREF="c261.html"><LINK REL="PREVIOUS" TITLE="Opening And Closing The Capture Device" HREF="x312.html"><LINK REL="NEXT" TITLE="Reading The Video Image" HREF="x325.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Video4Linux Programming</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x312.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Video Capture Devices</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x325.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="IRQVID" ></A >Interrupt Handling</H1 ><P > Our example handler is for an ISA bus device. If it was PCI you would be able to share the interrupt and would have set SA_SHIRQ to indicate a shared IRQ. We pass the device pointer as the interrupt routine argument. We don't need to since we only support one card but doing this will make it easier to upgrade the driver for multiple devices in the future. </P ><P > Our interrupt routine needs to do little if we assume the card can simply queue one frame to be read after it captures it. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > static struct wait_queue *capture_wait; static int capture_ready = 0; static void camera_irq(int irq, void *dev_id, struct pt_regs *regs) { capture_ready=1; wake_up_interruptible(&capture_wait); } </PRE ></TD ></TR ></TABLE ><P > The interrupt handler is nice and simple for this card as we are assuming the card is buffering the frame for us. This means we have little to do but wake up anybody interested. We also set a capture_ready flag, as we may capture a frame before an application needs it. In this case we need to know that a frame is ready. If we had to collect the frame on the interrupt life would be more complex. </P ><P > The two new routines we need to supply are camera_read which returns a frame, and camera_poll which waits for a frame to become ready. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > static int camera_poll(struct video_device *dev, struct file *file, struct poll_table *wait) { poll_wait(file, &capture_wait, wait); if(capture_read) return POLLIN|POLLRDNORM; return 0; } </PRE ></TD ></TR ></TABLE ><P > Our wait queue for polling is the capture_wait queue. This will cause the task to be woken up by our camera_irq routine. We check capture_read to see if there is an image present and if so report that it is readable. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x312.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x325.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Opening And Closing The Capture Device</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c261.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Reading The Video Image</TD ></TR ></TABLE ></DIV ></BODY ></HTML >