RTEMS Logo

RTEMS 4.9.2 On-Line Library


Console Driver Termios and Polled IO

PREV UP NEXT Bookshelf BSP and Device Driver Development Guide

8.4.2: Termios and Polled IO

The following functions are provided by the driver and invoked by Termios for simple character IO.

The my_driver_poll_write routine is responsible for writing n characters from buf to the serial device specified by minor.

static int my_driver_poll_write(int minor, const char *buf, int n)
{
    my_driver_entry *e = &my_driver_table [minor];
    int i = 0;

    /*
     * There is no need to check the minor number since it is derived
     * from a file descriptor.  The upper layer takes care that it is
     * in a valid range.
     */

    /* Write */
    for (i = 0; i < n; ++i) {
        my_driver_write_char(e, buf [i]);
    }

    return 0;
}

The my_driver_poll_read routine is responsible for reading a single character from the serial device specified by minor. If no character is available, then the routine should return minus one.

static int my_driver_poll_read(int minor)
{
    my_driver_entry *e = &my_driver_table [minor];

    /*
     * There is no need to check the minor number since it is derived
     * from a file descriptor.  The upper layer takes care that it is
     * in a valid range.
     */

    /* Check if a character is available */
    if (my_driver_can_read_char(e)) {
        /* Return the character */
        return my_driver_read_char(e);
    } else {
        /* Return an error status */
        return -1;
    }
}


PREV UP NEXT Bookshelf BSP and Device Driver Development Guide

Copyright © 1988-2008 OAR Corporation