Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > 98e91bc877e03cf3582cd163550eb7e3 > files > 1058

kernel-doc-html-2.4.19-16mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Radio Devices</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Video4Linux Programming"
HREF="book1.html"><LINK
REL="PREVIOUS"
TITLE="Introduction"
HREF="c20.html"><LINK
REL="NEXT"
TITLE="Opening And Closing The Radio"
HREF="x65.html"></HEAD
><BODY
CLASS="CHAPTER"
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="c20.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x65.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="RADIO"
></A
>Radio Devices</H1
><P
>        There are a wide variety of radio interfaces available for PC's, and these
        are generally very simple to program. The biggest problem with supporting
        such devices is normally extracting documentation from the vendor.
  </P
><P
>        The radio interface supports a simple set of control ioctls standardised
        across all radio and tv interfaces. It does not support read or write, which
        are used for video streams. The reason radio cards do not allow you to read
        the audio stream into an application is that without exception they provide
        a connection on to a soundcard. Soundcards can be used to read the radio
        data just fine. 
  </P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="REGISTERRADIO"
></A
>Registering Radio Devices</H1
><P
>        The Video4linux core provides an interface for registering devices. The
        first step in writing our radio card driver is to register it.
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;
static struct video_device my_radio
{
        "My radio",
        VID_TYPE_TUNER,
        VID_HARDWARE_MYRADIO,
        radio_open.
        radio_close,
        NULL,                /* no read */
        NULL,                 /* no write */
        NULL,                /* no poll */
        radio_ioctl,
        NULL,                /* no special init function */
        NULL                /* no private data */
};


  </PRE
></TD
></TR
></TABLE
><P
>        This declares our video4linux device driver interface. The VID_TYPE_ value
        defines what kind of an interface we are, and defines basic capabilities.
  </P
><P
>        The only defined value relevant for a radio card is VID_TYPE_TUNER which
        indicates that the device can be tuned. Clearly our radio is going to have some
        way to change channel so it is tuneable.
  </P
><P
>        The VID_HARDWARE_ types are unique to each device. Numbers are assigned by
        <TT
CLASS="EMAIL"
>&#60;<A
HREF="mailto:alan@redhat.com"
>alan@redhat.com</A
>&#62;</TT
> when device drivers are going to be released. Until then you
        can pull a suitably large number out of your hat and use it. 10000 should be
        safe for a very long time even allowing for the huge number of vendors
        making new and different radio cards at the moment.
  </P
><P
>        We declare an open and close routine, but we do not need read or write,
        which are used to read and write video data to or from the card itself. As
        we have no read or write there is no poll function.
  </P
><P
>        The private initialise function is run when the device is registered. In
        this driver we've already done all the work needed. The final pointer is a
        private data pointer that can be used by the device driver to attach and
        retrieve private data structures. We set this field "priv" to NULL for
        the moment.
  </P
><P
>        Having the structure defined is all very well but we now need to register it
        with the kernel. 
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;
static int io = 0x320;

int __init myradio_init(struct video_init *v)
{
        if(check_region(io, MY_IO_SIZE))
        {
                printk(KERN_ERR 
                    "myradio: port 0x%03X is in use.\n", io);
                return -EBUSY;
        }

        if(video_device_register(&#38;my_radio, VFL_TYPE_RADIO)==-1)
                return -EINVAL;
        request_region(io, MY_IO_SIZE, "myradio");
        return 0;
}

  </PRE
></TD
></TR
></TABLE
><P
>        The first stage of the initialisation, as is normally the case, is to check 
        that the I/O space we are about to fiddle with doesn't belong to some other 
        driver. If it is we leave well alone. If the user gives the address of the 
        wrong device then we will spot this. These policies will generally avoid 
        crashing the machine.
  </P
><P
>        Now we ask the Video4Linux layer to register the device for us. We hand it
        our carefully designed video_device structure and also tell it which group
        of devices we want it registered with. In this case VFL_TYPE_RADIO.
  </P
><P
>        The types available are
  </P
><DIV
CLASS="TABLE"
><A
NAME="AEN43"
></A
><P
><B
>Table 1. Device Types</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
CELLSPACING="0"
CELLPADDING="4"
CLASS="CALSTABLE"
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>VFL_TYPE_RADIO</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>/dev/radio{n}</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>&#13;        Radio devices are assigned in this block. As with all of these
        selections the actual number assignment is done by the video layer
        accordijng to what is free.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>VFL_TYPE_GRABBER</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>/dev/video{n}</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>        Video capture devices and also -- counter-intuitively for the name --
        hardware video playback devices such as MPEG2 cards.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>VFL_TYPE_VBI</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>/dev/vbi{n}</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>        The VBI devices capture the hidden lines on a television picture
        that carry further information like closed caption data, teletext
        (primarily in Europe) and now Intercast and the ATVEC internet
        television encodings.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
>VFL_TYPE_VTX</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>/dev/vtx[n}</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>        VTX is 'Videotext' also known as 'Teletext'. This is a system for
        sending numbered, 40x25, mostly textual page images over the hidden
        lines. Unlike the /dev/vbi interfaces, this is for 'smart' decoder 
        chips. (The use of the word smart here has to be taken in context,
        the smartest teletext chips are fairly dumb pieces of technology).
	</TD
></TR
></TBODY
></TABLE
></DIV
><P
>        We are most definitely a radio.
  </P
><P
>        Finally we allocate our I/O space so that nobody treads on us and return 0
        to signify general happiness with the state of the universe.
  </P
></DIV
></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="c20.html"
ACCESSKEY="P"
>&#60;&#60;&#60; 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="x65.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Introduction</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Opening And Closing The Radio</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>