BSP and Device Driver Development Guide
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
.
On success, the number of bytes written is returned (zero indicates nothing
was written). On error, -1
is returned.
NOTE: Due to the current implementation of termios, any data passed into the write function will be lost.
static ssize_t my_driver_poll_write(int minor, const char *buf, size_t 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 n; }
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; } }
BSP and Device Driver Development Guide
Copyright © 1988-2008 OAR Corporation