Changeset 07edbef5 in rtems


Ignore:
Timestamp:
May 22, 2008, 8:34:22 PM (12 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.9, master
Children:
923dd7a
Parents:
c0357a8
Message:

2008-05-22 Joel Sherrill <joel.sherrill@…>

  • console/console.c: Remove explicit switch and call termios_baud_to_number().
Location:
c/src/lib/libbsp/powerpc/gen5200
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/powerpc/gen5200/ChangeLog

    rc0357a8 r07edbef5  
     12008-05-22      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * console/console.c: Remove explicit switch and call
     4        termios_baud_to_number().
     5
    162008-05-22      Joel Sherrill <joel.sherrill@oarcorp.com>
    27
  • c/src/lib/libbsp/powerpc/gen5200/console/console.c

    rc0357a8 r07edbef5  
    119119
    120120#if defined(UARTS_USE_TERMIOS_INT)
    121   uint8_t psc_minor_to_irqname[NUM_PORTS] =
    122     {BSP_SIU_IRQ_PSC1,
     121  uint8_t psc_minor_to_irqname[NUM_PORTS] = {
     122     BSP_SIU_IRQ_PSC1,
    123123     BSP_SIU_IRQ_PSC2,
    124124     BSP_SIU_IRQ_PSC3,
    125125     BSP_SIU_IRQ_PSC4,
    126126     BSP_SIU_IRQ_PSC5,
    127      BSP_SIU_IRQ_PSC6};
    128 
    129   static int mpc5200_psc_irqname_to_minor(int name)
    130   {
    131     int minor;
     127     BSP_SIU_IRQ_PSC6
     128  };
     129
     130  static int mpc5200_psc_irqname_to_minor(int name) {
     131    int      minor;
    132132    uint8_t *chrptr;
    133133
     
    149149
    150150/* per channel info structure */
    151 struct per_channel_info
    152   {
     151struct per_channel_info {
    153152  uint16_t shadow_imr;
    154153  uint8_t shadow_mode1;
     
    163162  int parity_errors;
    164163  int overrun_errors;
    165   };
     164};
    166165
    167166/* Used to handle more than one channel */
    168167struct per_channel_info channel_info[NUM_PORTS];
    169168
    170   /*
    171    * XXX: there are only 6 PSCs, but PSC6 has an extra register gap
    172    *      from PSC5, therefore we instantiate seven(!) PSC register sets
    173    */
     169/*
     170 * XXX: there are only 6 PSCs, but PSC6 has an extra register gap
     171 *      from PSC5, therefore we instantiate seven(!) PSC register sets
     172 */
    174173uint8_t psc_minor_to_regset[MPC5200_PSC_NO] = {0,1,2,3,4,6};
    175174
     
    177176struct rtems_termios_tty *ttyp[NUM_PORTS];
    178177
    179 int mpc5200_psc_setAttributes(int minor, const struct termios *t)
    180   {
     178int mpc5200_psc_setAttributes(
     179  int                   minor,
     180  const struct termios *t
     181)
     182{
    181183  int baud;
    182184  uint8_t csize=0, cstopb, parenb, parodd;
     
    185187
    186188  /* Baud rate */
    187   switch(t->c_cflag & CBAUD)
    188     {
    189     default:      baud = -1;      break;
    190     case B50:     baud = 50;      break;
    191     case B75:     baud = 75;      break;
    192     case B110:    baud = 110;     break;
    193     case B134:    baud = 134;     break;
    194     case B150:    baud = 150;     break;
    195     case B200:    baud = 200;     break;
    196     case B300:    baud = 300;     break;
    197     case B600:    baud = 600;     break;
    198     case B1200:   baud = 1200;    break;
    199     case B1800:   baud = 1800;    break;
    200     case B2400:   baud = 2400;    break;
    201     case B4800:   baud = 4800;    break;
    202     case B9600:   baud = 9600;    break;
    203     case B19200:  baud = 19200;   break;
    204     case B38400:  baud = 38400;   break;
    205     case B57600:  baud = 57600;   break;
    206     case B115200: baud = 115200;  break;
    207     case B230400: baud = 230400;  break;
    208     case B460800: baud = 460800;  break;
    209     }
    210 
    211   if(baud > 0)
    212     {
    213 
     189  baud = termios_baud_to_number(t->c_cflag & CBAUD);
     190  if (baud > 0) {
    214191   /*
    215192    * Calculate baud rate
     
    217194    */
    218195    baud = (IPB_CLOCK + baud *16) / (baud * 32);
    219 
    220     }
     196  }
    221197
    222198  /* Number of data bits */
    223   switch ( t->c_cflag & CSIZE )
    224     {
     199  switch ( t->c_cflag & CSIZE ) {
    225200    case CS5:     csize = 0x00;  break;
    226201    case CS6:     csize = 0x01;  break;
    227202    case CS7:     csize = 0x02;  break;
    228203    case CS8:     csize = 0x03;  break;
    229     }
     204  }
    230205
    231206  /* Stop bits */
    232   if(csize == 0)
    233     {
    234 
     207  if(csize == 0) {
    235208    if(t->c_cflag & CSTOPB)
    236209      cstopb = 0x0F;           /* Two stop bits */
    237210    else
    238211      cstopb = 0x00;           /* One stop bit */
    239 
    240     }
    241   else
    242     {
    243 
     212  } else {
    244213    if(t->c_cflag & CSTOPB)
    245214      cstopb = 0x0F;           /* Two stop bits */
    246215    else
    247216      cstopb = 0x07;           /* One stop bit */
    248 
    249     }
     217  }
    250218
    251219  /* Parity */
     
    289257  return 0;
    290258
    291   }
     259}
    292260
    293261
    294262int mpc5200_uart_setAttributes(int minor, const struct termios *t)
    295   {
    296 
    297 
     263{
    298264  /*
    299265   * Check that port number is valid
     
    304270  return mpc5200_psc_setAttributes(minor, t);
    305271
    306   }
    307 
     272}
    308273
    309274#ifdef UARTS_USE_TERMIOS_INT
     
    312277 */
    313278static void mpc5200_psc_interrupt_handler(rtems_irq_hdl_param handle)
    314   {
     279{
    315280  unsigned char c;
    316281  uint16_t isr;
     
    328293   * Character received?
    329294   */
    330   if(isr & ISR_RX_RDY_FULL)
    331     {
     295  if (isr & ISR_RX_RDY_FULL) {
    332296
    333297    channel_info[minor].rx_interrupts++;
     
    335299
    336300#ifndef SINGLE_CHAR_MODE
    337     while(psc->rfnum)
    338       {
     301    while(psc->rfnum) {
    339302#endif
    340 
    341      /*
    342       * get the character
    343       */
    344       c = (psc->rb_tb >> 24);
     303      /*
     304       * get the character
     305       */
     306       c = (psc->rb_tb >> 24);
    345307
    346308      if (ttyp[minor] != NULL) {
     
    351313
    352314#ifndef SINGLE_CHAR_MODE
    353       }
     315    }
    354316#endif
    355317
    356     }
     318  }
    357319
    358320  /*
    359321   * Character transmitted ?
    360322   */
    361   if(isr & ISR_TX_RDY & channel_info[minor].shadow_imr)
    362     {
    363 
     323  if (isr & ISR_TX_RDY & channel_info[minor].shadow_imr) {
    364324    channel_info[minor].tx_interrupts++;
    365325
     
    370330
    371331    if (ttyp[minor] != NULL) {
    372 #ifndef SINGLE_CHAR_MODE
    373            rtems_termios_dequeue_characters((void *)ttyp[minor], channel_info[minor].cur_tx_len);
    374 
    375            channel_info[minor].tx_characters += channel_info[minor].cur_tx_len;
    376 #else
    377            rtems_termios_dequeue_characters((void *)ttyp[minor], (int)1);
    378 
    379            channel_info[minor].tx_characters++;
    380 #endif
    381       }
     332      #ifndef SINGLE_CHAR_MODE
     333        rtems_termios_dequeue_characters(
     334           (void *)ttyp[minor], channel_info[minor].cur_tx_len);
     335        channel_info[minor].tx_characters += channel_info[minor].cur_tx_len;
     336      #else
     337        rtems_termios_dequeue_characters((void *)ttyp[minor], (int)1);
     338        channel_info[minor].tx_characters++;
     339      #endif
    382340    }
    383 
    384   if(isr & ISR_ERROR)
    385     {
    386 
     341  }
     342
     343  if(isr & ISR_ERROR) {
    387344    if(isr & ISR_RB)
    388345      channel_info[minor].breaks_detected++;
    389 
    390346    if(isr & ISR_FE)
    391347      channel_info[minor].framing_errors++;
    392 
    393348    if(isr & ISR_PE)
    394349      channel_info[minor].parity_errors++;
    395 
    396350    if(isr & ISR_OE)
    397351      channel_info[minor].overrun_errors++;
     
    401355     */
    402356    psc->cr = ((4 << 4) << 8);
    403 
    404     }
    405 
    406   }
    407 
    408 void mpc5200_psc_enable(const rtems_irq_connect_data* ptr) {
     357  }
     358}
     359
     360void mpc5200_psc_enable(
     361  const rtems_irq_connect_data* ptr
     362)
     363{
    409364  struct mpc5200_psc *psc;
    410365  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
     
    418373
    419374
    420 void mpc5200_psc_disable(const rtems_irq_connect_data* ptr) {
     375void mpc5200_psc_disable(
     376  const rtems_irq_connect_data* ptr
     377)
     378{
    421379  struct mpc5200_psc *psc;
    422380  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
     
    429387}
    430388
    431 
    432 int mpc5200_psc_isOn(const rtems_irq_connect_data* ptr) {
     389int mpc5200_psc_isOn(
     390  const rtems_irq_connect_data* ptr
     391)
     392{
    433393  struct mpc5200_psc *psc;
    434394  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
     
    438398    return ((psc->isr_imr & IMR_RX_RDY_FULL) & (psc->isr_imr & IMR_TX_RDY));
    439399  }
    440   else {
    441     return FALSE;
    442   }
     400  return FALSE;
    443401}
    444402
     
    447405#endif
    448406
    449 void mpc5200_uart_psc_initialize(int minor) {
     407void mpc5200_uart_psc_initialize(
     408  int minor
     409)
     410{
    450411  uint32_t baud_divider;
    451412  struct mpc5200_psc *psc =
     
    455416   * Check that minor number is valid
    456417   */
    457   if((minor < PSC1_MINOR) || (minor >= (PSC1_MINOR + NUM_PORTS)))
     418  if ((minor < PSC1_MINOR) || (minor >= (PSC1_MINOR + NUM_PORTS)))
    458419    return;
    459420
     
    462423   */
    463424  memset((void *)&channel_info[minor], 0, sizeof(struct per_channel_info));
    464 
    465425
    466426  /*
     
    537497   * Install rtems irq handler
    538498   */
    539   if(!BSP_install_rtems_irq_handler (&consoleIrqData))
    540     {
    541 
     499  if (!BSP_install_rtems_irq_handler (&consoleIrqData)) {
    542500    printk("Unable to connect PSC Irq handler\n");
    543501    rtems_fatal_error_occurred(1);
    544 
    545     }
     502  }
    546503#endif
    547504
     
    572529   */
    573530  psc->cr = ((1 << 2) << 8);
    574 
    575   }
    576 
    577 
    578 int mpc5200_uart_pollRead(int minor)
    579   {
     531}
     532
     533
     534int mpc5200_uart_pollRead(
     535  int minor
     536)
     537{
    580538  unsigned char c;
    581539  struct mpc5200_psc *psc =
    582540    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
    583541
    584   if(psc->sr_csr & (1 << 8))
     542  if (psc->sr_csr & (1 << 8))
    585543     c = (psc->rb_tb >> 24);
    586       else
    587         return -1;
     544  else
     545     return -1;
    588546
    589547  return c;
    590 
    591   }
    592 
    593 
    594 int mpc5200_uart_pollWrite(int minor, const char *buf, int len)
    595   {
     548}
     549
     550
     551int mpc5200_uart_pollWrite(
     552  int minor,
     553  const char *buf,
     554  int len
     555)
     556{
    596557  const char *tmp_buf = buf;
    597558  struct mpc5200_psc *psc =
    598559    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
    599560
    600   while(len--)
    601     {
    602 
     561  while(len--) {
    603562    while(!(psc->sr_csr & (1 << 11)))
    604563      continue;
     
    610569    tmp_buf++;
    611570
    612     }
    613 
     571  }
    614572  return 0;
    615573
    616   }
    617 
    618 
    619 int mpc5200_uart_write(int minor, const char *buf, int len)
    620   {
     574}
     575
     576
     577int mpc5200_uart_write(
     578  int         minor,
     579  const char *buf,
     580  int len
     581)
     582{
    621583  int frame_len = len;
    622584  const char *frame_buf = buf;
     
    638600 /*rtems_cache_flush_multiple_data_lines( (void *)frame_buf, frame_len);*/
    639601
    640   while(frame_len--)
     602  while (frame_len--)
    641603    /* perform byte write to avoid extra NUL characters */
    642604    (* (volatile char *)&(psc->rb_tb)) = *frame_buf++;
     
    648610
    649611  return 0;
    650 
    651   }
     612}
    652613
    653614/*
    654615 *  Print functions prototyped in bspIo.h
    655616 */
    656 static void A_BSP_output_char( char c )
     617static void A_BSP_output_char(
     618  char c
     619)
    657620{
    658621  char cr = '\r';
     
    683646 */
    684647
    685 
    686648/*
    687649 * Initialize and register the device
     
    692654  void *arg
    693655)
    694   {
    695 
     656{
    696657  rtems_status_code status;
    697658  rtems_device_minor_number console_minor;
     
    706667
    707668  for (console_minor = PSC1_MINOR;
    708       console_minor < PSC1_MINOR + NUM_PORTS;
    709       console_minor++) {
     669       console_minor < PSC1_MINOR + NUM_PORTS;
     670       console_minor++) {
    710671     /*
    711672      * check, whether UART is available for this board
     
    719680      status = rtems_io_register_name (dev_name, major, console_minor);
    720681
    721       if(status != RTEMS_SUCCESSFUL)
    722         {
     682      if (status != RTEMS_SUCCESSFUL)
    723683        rtems_fatal_error_occurred(status);
    724         }
    725684
    726685      tty_num++;
     
    736695  console_initialized = TRUE;
    737696  return RTEMS_SUCCESSFUL;
    738 
    739   }
    740 
     697}
    741698
    742699/*
     
    753710
    754711#ifdef UARTS_USE_TERMIOS_INT
    755   static const rtems_termios_callbacks intrCallbacks =
    756     {
     712  static const rtems_termios_callbacks intrCallbacks = {
    757713    NULL,                           /* firstOpen */
    758714    NULL,                           /* lastClose */
     
    763719    NULL,
    764720    1                               /* outputUsesInterrupts */
    765     };
     721  };
    766722#else
    767   static const rtems_termios_callbacks pollCallbacks =
    768     {
     723  static const rtems_termios_callbacks pollCallbacks = {
    769724    NULL,                           /* firstOpen */
    770725    NULL,                           /* lastClose */
     
    775730    NULL,
    776731    0                               /* output don't use Interrupts */
    777     };
     732  };
    778733#endif
    779734
     
    800755 * Close the device
    801756 */
    802 rtems_device_driver console_close(rtems_device_major_number major, rtems_device_minor_number minor, void *arg)
    803   {
    804 
     757rtems_device_driver console_close(
     758  rtems_device_major_number  major,
     759  rtems_device_minor_number  minor,
     760  void                      *arg
     761)
     762{
    805763  if ( minor > NUM_PORTS-1 )
    806764    return RTEMS_INVALID_NUMBER;
     
    809767
    810768  return rtems_termios_close( arg );
    811   return 0;
    812 
    813   }
     769}
    814770
    815771
     
    817773 * Read from the device
    818774 */
    819 rtems_device_driver console_read(rtems_device_major_number major, rtems_device_minor_number minor, void *arg)
    820   {
    821 
     775rtems_device_driver console_read(
     776  rtems_device_major_number  major,
     777  rtems_device_minor_number  minor,
     778  void                      *arg
     779)
     780{
    822781  if(minor > NUM_PORTS-1)
    823782    return RTEMS_INVALID_NUMBER;
    824783
    825784  return rtems_termios_read(arg);
    826 
    827   return 0;
    828 
    829   }
    830 
     785}
    831786
    832787/*
    833788 * Write to the device
    834789 */
    835 rtems_device_driver console_write(rtems_device_major_number major,rtems_device_minor_number minor,void *arg)
    836   {
    837 
    838   if( minor > NUM_PORTS-1 )
    839     return RTEMS_INVALID_NUMBER;
    840 
    841   return rtems_termios_write(arg);
    842 
    843   return 0;
    844   }
    845 
    846 
    847 /*
    848  * Handle ioctl request.
    849  */
    850 rtems_device_driver console_control(rtems_device_major_number major,rtems_device_minor_number minor,void *arg)
    851   {
    852 
     790rtems_device_driver console_write(
     791  rtems_device_major_number  major,
     792  rtems_device_minor_number  minor,
     793  void                      *arg
     794)
     795{
    853796  if ( minor > NUM_PORTS-1 )
    854797    return RTEMS_INVALID_NUMBER;
     798  return rtems_termios_write(arg);
     799}
     800
     801/*
     802 * Handle ioctl request.
     803 */
     804rtems_device_driver console_control(
     805  rtems_device_major_number  major,
     806  rtems_device_minor_number  minor,
     807  void                      *arg
     808)
     809{
     810  if ( minor > NUM_PORTS-1 )
     811    return RTEMS_INVALID_NUMBER;
    855812
    856813  return rtems_termios_ioctl(arg);
    857 
    858   return 0;
    859 
    860   }
     814}
Note: See TracChangeset for help on using the changeset viewer.