[plug] Any kernel hackers out there...?

Michael Hunt michael.j.hunt at usa.net
Tue Mar 5 18:36:49 WST 2002


Can't help you with _your_ code (not a C programmer). Try looking at the
source of setserial/minicom/other term program for example code of serial
initialisation.

Michael Hunt

> -----Original Message-----
> From: Kim Covil [mailto:Kim.Covil at csiro.au]
> Sent: Tuesday, 5 March 2002 4:56 PM
> To: plug at plug.linux.org.au
> Subject: [plug] Any kernel hackers out there...?
>
>
> Hi,
>
> Is there anyone on the list who might be able to give me some hints on
> how to talk to a serial device from within a 2.2 kernel...?
>
> I have a device running a 2.2 kernel on a strongarm processor. The
> kernel is not modular (and is quite highly modified). There is a serial
> device I would like to query on boot to determine whether it is attached
> and what id it returns, and then set a variable within the kernel before
> it carries on with the rest of its boot sequence. The initialisation
> sequence is pretty simple, so I just need to know how to send a few
> bytes to the device and read back a few bytes in reply with a timeout in
> case the device is not attached.
>
> At the moment I have some userspace code to do this via /dev/ttyS0 and I
> set the kernel variable via an ioctl, but I would like to be able to do
> the same thing from within the kernel itself to save having to put the
> user space program on the filesystem and have the filesystem mounted
> before the code is called.
>
> Currently my rough scratching around looking for example code has come
> up with something like the code at the bottom. But I have no idea
> whether this is in anyway correct, and I can't find any examples on how
> I read 3 bytes from the serial device. Also I have been told I should
> wrap the code in a busy-wait but I am not sure about that one either.
>
> Any help would be appreciated,
>
> Cheers
>
> Kim
>
>
> #include <linux/tty.h>
> static int /* detect the presence of a tuner module and return its id */
> tuner_detect ()
> {
>    int ret;
>    char buf[5];
>    char init_data[3] = { 0x01, 0x00, 0x01 };
>    struct async_struct *info = IRQ_ports[15]; /* tuner on ttyS0 */
>    struct tty_struct *tty = info->tty;
>    tty->termios->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|
> INLCR|IGNCR|ICRNL|IXON);
>    tty->termios->c_oflag &= ~OPOST;
>    tty->termios->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
>    tty->termios->c_cflag &= ~(CSIZE|PARENB);
>    tty->termios->c_cflag |= CS8;
>    tty->termios->c_iflag |= B19200;
>    tty->termios->c_oflag |= B19200;
>
>    if ( tty->driver.write(tty, 0, init_data, 3) < 3 ) {
>       /* failed to send data to the tuner */
>       return -1;
>    }
>
>
>    /*
>     * here's where I want to read 3 bytes from the tty...
>     * with a timeout in case the tuner doesn't exist and therefore
>     * doesn't reply
>     */
>
>
>    return ret;
> }
>
> --
> ==================================================================
> =========
> Kim Covil - CSIRO Exploration & Mining  E-mail:  kim.covil at csiro.au
> ,-_!\
>             PO Box 1130, Bentley,       Direct:  +61 8 6436 8638    /
> \
>             Western Australia  6102     Fax:     +61 8 6436 8555
> *_,-._/
> ========================================================================
> v
>         Please direct all personal e-mail to kimbotha at covil.com.au
>



More information about the plug mailing list