BSP and Device Driver Development Guide
The console_open function is called whenever a serial device is opened.
The device registered as "/dev/console" (CONSOLE_DEVICE_NAME) is
opened automatically during RTEMS initialization. For instance, if UART
channel 2 is registered as "/dev/tty1", the console_open entry point
will be called as the result of an fopen("/dev/tty1", mode) in the
application.
The console_open function has to inform Termios of the low-level
functions for serial line support.
rtems_device_driver console_open(
rtems_device_major_number major,
rtems_device_minor_number minor,
void *arg
)
{
struct rtems_termios_callbacks *callbacks =
&my_driver_callbacks_polled;
/*
* Check the minor number. Termios does currently not check
* the return value of the first open call so the minor
* number must be checked here.
*/
if (MY_DRIVER_IS_MINOR_INVALID(minor)) {
return RTEMS_INVALID_NUMBER;
}
/*
* Depending on the IO mode you need to pass a different set of
* callback functions to Termios.
*/
if (MY_DRIVER_USES_INTERRUPTS(minor)) {
callbacks = &my_driver_callbacks_interrupt;
}
return rtems_termios_open(major, minor, arg, callbacks);
}
During the first open of the device Termios will call my_driver_first_open.
static int my_driver_first_open(int major, int minor, void *arg)
{
my_driver_entry *e = &my_driver_table [minor];
struct rtems_termios_tty *tty =
((rtems_libio_open_close_args_t *) arg)->iop->data1;
/* Check minor number */
if (MY_DRIVER_IS_MINOR_INVALID(minor)) {
return -1;
}
/* Connect the TTY data structure */
e->tty = tty;
/*
* You may add some initialization code here.
*/
/*
* Sets the inital baud rate. This should be set to the value of
* the boot loader.
*/
return rtems_termios_set_initial_baud(e->tty, MY_DRIVER_BAUD_RATE);
}
BSP and Device Driver Development Guide
Copyright © 1988-2008 OAR Corporation