Changeset ba692232 in rtems


Ignore:
Timestamp:
Oct 18, 2011, 6:23:51 PM (10 years ago)
Author:
Jennifer Averett <Jennifer.Averett@…>
Branches:
4.11, 5, master
Children:
0a91018f
Parents:
4ec8180
Message:

2011-10-18 Jennifer Averett <Jennifer.Averett@…>

PR 1917/bsps

  • console.c: Modifications to add dynamic tables for libchip serial drivers.
  • console_control.c, console_private.h, console_read.c, console_select.c, console_write.c: New files.
Location:
c/src/lib/libbsp/shared
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/shared/ChangeLog

    r4ec8180 rba692232  
     12011-10-18      Jennifer Averett <Jennifer.Averett@OARcorp.com>
     2
     3        PR 1917/bsps
     4        * console.c: Modifications to add dynamic tables for libchip serial
     5        drivers.
     6        * console_control.c, console_private.h, console_read.c,
     7        console_select.c, console_write.c: New files.
     8
    192011-08-30      Joel Sherrill <joel.sherrill@oarcorp.com>
    210
  • c/src/lib/libbsp/shared/console.c

    r4ec8180 rba692232  
    1 /*
    2  *  This file contains the generic console driver shell used
    3  *  by all console drivers using libchip.
    4  *
    5  *  This driver uses the termios pseudo driver.
    6  *
    7  *  COPYRIGHT (c) 1989-1997.
     1/**
     2 * @file
     3 *
     4 * @ingroup Console
     5 *
     6 * @brief Extension of the generic libchip console driver shell
     7 */
     8
     9/*
     10 *  COPYRIGHT (c) 1989-2011.
    811 *  On-Line Applications Research Corporation (OAR).
    912 *
     
    1720#include <bsp.h>
    1821#include <rtems/libio.h>
    19 #include <rtems/console.h>
    2022#include <stdlib.h>
    2123#include <assert.h>
     
    2426#include <rtems/termiostypes.h>
    2527#include <libchip/serial.h>
    26 
    27 /*
    28  *  Configuration Information
    29  */
    30 
    31 extern console_data  Console_Port_Data[];
    32 extern unsigned long  Console_Port_Count;
    33 extern rtems_device_minor_number  Console_Port_Minor;
    34 
    35 /*PAGE
    36  *
     28#include "console_private.h"
     29
     30unsigned long               Console_Port_Count  = 0;
     31console_tbl               **Console_Port_Tbl    = NULL;
     32console_data               *Console_Port_Data   = NULL;
     33rtems_device_minor_number   Console_Port_Minor  = 0;
     34bool                        console_initialized = false;
     35
     36/*
     37 *  console_initialize_pointers
     38 *
     39 *  This method is used to initialize the table of pointers to the
     40 *  serial port configuration structure entries.
     41 */
     42static void console_initialize_pointers(void)
     43{
     44  int i;
     45
     46  if ( Console_Port_Tbl )
     47    return;
     48
     49  Console_Port_Count = Console_Configuration_Count;
     50  Console_Port_Tbl   = malloc( Console_Port_Count * sizeof( console_tbl * ) );
     51  if (Console_Port_Tbl == NULL)
     52    rtems_panic("No memory for console pointers");
     53   
     54  for (i=0 ; i < Console_Port_Count ; i++)
     55    Console_Port_Tbl[i] = &Console_Configuration_Ports[i];
     56}
     57
     58/*
     59 *  console_register_devices
     60 *
     61 *  This method is used to add dynamically discovered devices to the
     62 *  set of serial ports supported.
     63 */
     64void console_register_devices(
     65  console_tbl *new_ports,
     66  size_t       number_of_ports
     67)
     68{
     69  int  old_number_of_ports;
     70  int  i;
     71
     72  console_initialize_pointers();
     73
     74  /*
     75   *  console_initialize has been invoked so it is now too late to
     76   *  register devices.
     77   */
     78  if ( console_initialized == true ) {
     79    printk( "Attempt to register console devices after driver initialized\n" );
     80    rtems_fatal_error_occurred( 0xdead0001 );
     81  }
     82
     83  /*
     84   *  Allocate memory for the console port extension
     85   */
     86  old_number_of_ports = Console_Port_Count;
     87  Console_Port_Count += number_of_ports;
     88  Console_Port_Tbl = realloc(
     89    Console_Port_Tbl,
     90    Console_Port_Count * sizeof( console_tbl * )
     91  );
     92  if ( Console_Port_Tbl == NULL ) {
     93    printk( "Unable to allocate pointer table for registering console devices\n" );
     94    rtems_fatal_error_occurred( 0xdead0002 );
     95  }
     96
     97  Console_Port_Data  = calloc( Console_Port_Count, sizeof( console_data ) );
     98  if ( Console_Port_Data == NULL ) {
     99    printk( "Unable to allocate data table for console devices\n" );
     100    rtems_fatal_error_occurred( 0xdead0003 );
     101  }
     102
     103  /*
     104   *  Now add the new devices at the end.
     105   */
     106 
     107  for (i=0 ; i < number_of_ports ; i++) {
     108    Console_Port_Tbl[old_number_of_ports + i] = &new_ports[i];
     109  }
     110}
     111
     112/*
    37113 *  console_open
    38114 *
    39115 *  open a port as a termios console.
    40  *
    41  */
    42 
     116 */
    43117rtems_device_driver console_open(
    44118  rtems_device_major_number major,
     
    66140   */
    67141
    68   cptr = &Console_Port_Tbl[minor];
     142  cptr = Console_Port_Tbl[minor];
    69143  Callbacks.firstOpen            = cptr->pDeviceFns->deviceFirstOpen;
    70144  Callbacks.lastClose            = cptr->pDeviceFns->deviceLastClose;
     
    73147  Callbacks.setAttributes        = cptr->pDeviceFns->deviceSetAttributes;
    74148  if (cptr->pDeviceFlow != NULL) {
    75     Callbacks.stopRemoteTx = cptr->pDeviceFlow->deviceStopRemoteTx;
     149    Callbacks.stopRemoteTx  = cptr->pDeviceFlow->deviceStopRemoteTx;
    76150    Callbacks.startRemoteTx = cptr->pDeviceFlow->deviceStartRemoteTx;
    77151  } else {
    78     Callbacks.stopRemoteTx = NULL;
     152    Callbacks.stopRemoteTx  = NULL;
    79153    Callbacks.startRemoteTx = NULL;
    80154  }
     
    86160   */
    87161
    88   status = rtems_termios_open ( major, minor, arg, &Callbacks );
     162  status = rtems_termios_open( major, minor, arg, &Callbacks );
    89163  Console_Port_Data[minor].termios_data = args->iop->data1;
    90164
     
    104178     * If it's the first open, modified, if need, the port parameters
    105179     */
    106     if (minor!=Console_Port_Minor) {
     180    if ( minor != Console_Port_Minor ) {
    107181      /*
    108        * If this is not the console we do not want ECHO and
    109        * so forth
     182       * If this is not the console we do not want ECHO and so forth
    110183       */
    111       IoctlArgs.iop=args->iop;
    112       IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES;
    113       IoctlArgs.buffer=&Termios;
    114       rtems_termios_ioctl(&IoctlArgs);
    115       Termios.c_lflag=ICANON;
    116       IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES;
    117       rtems_termios_ioctl(&IoctlArgs);
     184      IoctlArgs.iop     = args->iop;
     185      IoctlArgs.command = RTEMS_IO_GET_ATTRIBUTES;
     186      IoctlArgs.buffer  = &Termios;
     187      rtems_termios_ioctl( &IoctlArgs );
     188
     189      Termios.c_lflag   = ICANON;
     190      IoctlArgs.command = RTEMS_IO_SET_ATTRIBUTES;
     191      rtems_termios_ioctl( &IoctlArgs );
    118192    }
    119193  }
    120194
    121195  if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
    122       Console_Port_Tbl[minor].pDeviceFlow &&
    123       Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) {
    124     Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor);
     196      cptr->pDeviceFlow &&
     197      cptr->pDeviceFlow->deviceStartRemoteTx) {
     198    cptr->pDeviceFlow->deviceStartRemoteTx(minor);
    125199  }
    126200
     
    128202}
    129203
    130 /*PAGE
    131  *
     204/*
    132205 *  console_close
    133206 *
    134207 *  This routine closes a port that has been opened as console.
    135208 */
    136 
    137209rtems_device_driver console_close(
    138210  rtems_device_major_number major,
     
    143215  rtems_libio_open_close_args_t *args = arg;
    144216  struct rtems_termios_tty      *current_tty;
    145 
    146   /* Get tty pointeur from the Console_Port_Data */
     217  console_tbl                   *cptr;
     218
     219  cptr  = Console_Port_Tbl[minor];
     220
     221  /* Get tty pointer from the Console_Port_Data */
    147222  current_tty = Console_Port_Data[minor].termios_data;
    148223
     
    152227  if ( (current_tty->refcount == 1) ) {
    153228    if ( (args->iop->flags&LIBIO_FLAGS_READ) &&
    154           Console_Port_Tbl[minor].pDeviceFlow &&
    155           Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) {
    156       Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
     229          cptr->pDeviceFlow &&
     230          cptr->pDeviceFlow->deviceStopRemoteTx) {
     231      cptr->pDeviceFlow->deviceStopRemoteTx(minor);
    157232    }
    158233  }
     
    161236}
    162237
    163 /*PAGE
    164  *
    165  *  console_read
    166  *
    167  *  This routine uses the termios driver to read a character.
    168  */
    169 
    170 rtems_device_driver console_read(
    171   rtems_device_major_number major,
    172   rtems_device_minor_number minor,
    173   void                    * arg
    174 )
    175 {
    176   return rtems_termios_read (arg);
    177 }
    178 
    179 /*PAGE
    180  *
    181  *  console_write
    182  *
    183  *  this routine uses the termios driver to write a character.
    184  */
    185 
    186 rtems_device_driver console_write(
    187   rtems_device_major_number major,
    188   rtems_device_minor_number minor,
    189   void                    * arg
    190 )
    191 {
    192   return rtems_termios_write (arg);
    193 }
    194 
    195 /*PAGE
    196  *
    197  *  console_control
    198  *
    199  *  this routine uses the termios driver to process io
    200  */
    201 
    202 rtems_device_driver console_control(
    203   rtems_device_major_number major,
    204   rtems_device_minor_number minor,
    205   void                    * arg
    206 )
    207 {
    208   return rtems_termios_ioctl (arg);
    209 }
    210 
    211 /*PAGE
    212  *
     238/*
    213239 *  console_initialize
    214240 *
    215241 *  Routine called to initialize the console device driver.
    216242 */
    217 
    218243rtems_device_driver console_initialize(
    219244  rtems_device_major_number  major,
    220   rtems_device_minor_number  minor,
     245  rtems_device_minor_number  minor_arg,
    221246  void                      *arg
    222247)
    223248{
    224   rtems_status_code sc = RTEMS_SUCCESSFUL;
    225   bool first = true;
    226 
     249  rtems_status_code          status;
     250  rtems_device_minor_number  minor;
     251  console_tbl               *port;
     252
     253  /*
     254   * If we have no devices which were registered earlier then we
     255   * must still initialize pointers and set Console_Port_Data.
     256   */
     257  if ( ! Console_Port_Tbl ) {
     258    console_initialize_pointers();
     259    Console_Port_Data  = calloc( Console_Port_Count, sizeof( console_data ) );
     260    if ( Console_Port_Data == NULL ) {
     261      printk( "Unable to allocate data table for console devices\n" );
     262      rtems_fatal_error_occurred( 0xdead0003 );
     263    }
     264  }
     265
     266  /*
     267   *  console_initialize has been invoked so it is now too late to
     268   *  register devices.
     269   */
     270  console_initialized = true;
     271
     272  /*
     273   *  Initialize the termio interface, our table of pointers to device
     274   *  information structures, and determine if the user has explicitly
     275   *  specified which device is to be used for the console.
     276   */
    227277  rtems_termios_initialize();
    228 
    229   for (minor = 0; minor < Console_Port_Count; ++minor) {
    230     const console_tbl *device = &Console_Port_Tbl [minor];
    231 
    232     if (
    233       (device->deviceProbe == NULL || device->deviceProbe(minor))
    234         && device->pDeviceFns->deviceProbe(minor)
    235     ) {
    236       device->pDeviceFns->deviceInitialize(minor);
    237       if (first) {
    238         first = false;
    239         Console_Port_Minor = minor;
    240         sc = rtems_io_register_name(CONSOLE_DEVICE_NAME, major, minor);
    241         if (sc != RTEMS_SUCCESSFUL) {
    242           rtems_fatal_error_occurred(sc);
     278  bsp_console_select();
     279
     280  /*
     281   *  Iterate over all of the console devices we know about
     282   *  and initialize them.
     283   */
     284  for (minor=0 ; minor < Console_Port_Count ; minor++) {
     285    /*
     286     *  First perform the configuration dependent probe, then the
     287     *  device dependent probe
     288     */
     289    port = Console_Port_Tbl[minor];
     290
     291    if ( (!port->deviceProbe || port->deviceProbe(minor)) &&
     292         port->pDeviceFns->deviceProbe(minor)) {
     293
     294      status = rtems_io_register_name( port->sDeviceName, major, minor );
     295      if (status != RTEMS_SUCCESSFUL) {
     296        printk( "Unable to register /dev/console\n" );
     297        rtems_fatal_error_occurred(status);
     298      }
     299
     300      if (minor == Console_Port_Minor) {
     301        if (RTEMS_DEBUG)
     302          printk( "Register %s as the CONSOLE\n", port->sDeviceName );
     303        status = rtems_io_register_name( "dev/console", major, minor );
     304        if (status != RTEMS_SUCCESSFUL) {
     305          printk( "Unable to register /dev/console\n" );
     306          rtems_fatal_error_occurred(status);
    243307        }
    244308      }
    245       if (device->sDeviceName != NULL) {
    246         sc = rtems_io_register_name(device->sDeviceName, major, minor);
    247         if (sc != RTEMS_SUCCESSFUL) {
    248           rtems_fatal_error_occurred(sc);
    249         }
    250       }
     309
     310      /*
     311       * Initialize the hardware device.
     312       */
     313      port->pDeviceFns->deviceInitialize(minor);
     314
    251315    }
    252316  }
    253317
    254   if (first) {
    255     /*
    256      * Failed to find a working device
    257      */
    258     rtems_fatal_error_occurred(RTEMS_IO_ERROR);
    259   }
    260 
    261318  return RTEMS_SUCCESSFUL;
    262319}
Note: See TracChangeset for help on using the changeset viewer.