Changeset d22147e in rtems


Ignore:
Timestamp:
Sep 12, 2018, 9:47:19 AM (9 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
688e101a
Parents:
68920e7f
git-author:
Sebastian Huber <sebastian.huber@…> (09/12/18 09:47:19)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/17/18 06:56:32)
Message:

bsp/tqm8xx: Convert console to new Termios API

Update #3513.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/powerpc/tqm8xx/console/console.c

    r68920e7f rd22147e  
    4747 */
    4848
    49 #include <stdio.h>
    50 #include <stdlib.h>
    51 #include <termios.h>
    5249#include <unistd.h>
    5350
    5451#include <rtems.h>
    5552#include <rtems/console.h>
    56 #include <rtems/libio.h>
    5753#include <rtems/termiostypes.h>
    5854#include <rtems/bspIo.h>
     
    116112 */
    117113typedef struct m8xx_console_chan_desc_s {
    118   void *tty;
     114  rtems_termios_device_context base;
    119115  volatile m8xxBufferDescriptor_t *sccFrstRxBd;
    120116  volatile m8xxBufferDescriptor_t *sccCurrRxBd;
     
    291287 */
    292288
    293 static int sccBRGalloc(m8xx_console_chan_desc_t *cd,int baud)
     289static bool sccBRGalloc(m8xx_console_chan_desc_t *cd,int baud)
    294290{
    295291  rtems_interrupt_level level;
     
    383379                     M8xx_SIMODE_SMCCS(cd->chan - CONS_CHN_SMC1,new_brg));
    384380    }
    385   }
    386   return (new_brg < 0);
     381
     382    return true;
     383  } else {
     384    return false;
     385  }
    387386}
    388387
     
    391390 * Hardware-dependent portion of tcsetattr().
    392391 */
    393 static int
    394 sccSetAttributes (int minor, const struct termios *t)
    395 {
    396   m8xx_console_chan_desc_t *cd = &m8xx_console_chan_desc[minor];
    397   int baud;
    398 
    399   switch (t->c_ospeed) {
    400   default:      baud = -1;      break;
    401   case B50:     baud = 50;      break;
    402   case B75:     baud = 75;      break;
    403   case B110:    baud = 110;     break;
    404   case B134:    baud = 134;     break;
    405   case B150:    baud = 150;     break;
    406   case B200:    baud = 200;     break;
    407   case B300:    baud = 300;     break;
    408   case B600:    baud = 600;     break;
    409   case B1200:   baud = 1200;    break;
    410   case B1800:   baud = 1800;    break;
    411   case B2400:   baud = 2400;    break;
    412   case B4800:   baud = 4800;    break;
    413   case B9600:   baud = 9600;    break;
    414   case B19200:  baud = 19200;   break;
    415   case B38400:  baud = 38400;   break;
    416   case B57600:  baud = 57600;   break;
    417   case B115200: baud = 115200;  break;
    418   case B230400: baud = 230400;  break;
    419   case B460800: baud = 460800;  break;
    420   }
     392static bool
     393sccSetAttributes (rtems_termios_device_context *base, const struct termios *t)
     394{
     395  m8xx_console_chan_desc_t *cd = (m8xx_console_chan_desc_t *)base;
     396  speed_t speed;
     397  rtems_termios_baud_t baud;
     398
     399  speed = cfgetispeed(t);
     400  if (speed == B0) {
     401        speed = cfgetospeed(t);
     402  }
     403
     404  baud = rtems_termios_baud_to_number(speed);
     405  if (baud == 0) {
     406    return false;
     407  }
     408
    421409  return sccBRGalloc(cd,baud);
    422   return 0;
    423410}
    424411
     
    429416sccInterruptHandler (void *arg)
    430417{
    431   m8xx_console_chan_desc_t *cd = arg;
     418  rtems_termios_tty *tty = arg;
     419  m8xx_console_chan_desc_t *cd = rtems_termios_get_device_context(tty);
    432420
    433421  /*
     
    443431     */
    444432    while ((cd->sccCurrRxBd->status & M8xx_BD_EMPTY) == 0) {
    445       if (cd->tty != NULL) {
    446         rtems_cache_invalidate_multiple_data_lines((void *)cd->sccCurrRxBd->buffer,
    447                                                    cd->sccCurrRxBd->length);
    448         rtems_termios_enqueue_raw_characters (cd->tty,
    449                                               (char *)cd->sccCurrRxBd->buffer,
    450                                               cd->sccCurrRxBd->length);
    451       }
     433      rtems_cache_invalidate_multiple_data_lines((void *)cd->sccCurrRxBd->buffer,
     434                                                  cd->sccCurrRxBd->length);
     435      rtems_termios_enqueue_raw_characters (tty,
     436                                            (char *)cd->sccCurrRxBd->buffer,
     437                                            cd->sccCurrRxBd->length);
    452438      /*
    453439       * clear status
     
    484470    while((cd->sccDequTxBd != cd->sccPrepTxBd) &&
    485471          ((cd->sccDequTxBd->status & M8xx_BD_READY) == 0)) {
    486       if (cd->tty != NULL) {
    487         rtems_termios_dequeue_characters (cd->tty,
    488                                           cd->sccDequTxBd->length);
    489       }
     472      rtems_termios_dequeue_characters (tty, cd->sccDequTxBd->length);
    490473      /*
    491474       * advance to next BD
     
    689672    cd->regs.smcr->smcmr |= 0x0003;
    690673  }
    691 
    692   if (cd->mode != TERMIOS_POLLED) {
    693     rtems_status_code sc;
    694 
    695     sc = rtems_interrupt_handler_install(
    696       cd->ivec_src,
    697       "SCC",
    698       RTEMS_INTERRUPT_UNIQUE,
    699       sccInterruptHandler,
    700       cd
    701     );
    702     if (sc != RTEMS_SUCCESSFUL) {
    703       rtems_panic("console: cannot install IRQ handler");
    704     }
    705     mpc8xx_console_irq_on(cd);
    706   }
    707674}
    708675
     
    711678 */
    712679static int
    713 sccPollRead (int minor)
    714 {
    715   m8xx_console_chan_desc_t *cd = &m8xx_console_chan_desc[minor];
     680sccPollRead (rtems_termios_device_context *base)
     681{
     682  m8xx_console_chan_desc_t *cd = (m8xx_console_chan_desc_t *)base;
    716683  int c = -1;
    717684
     
    761728 *      Transmit all characters.
    762729 */
    763 static ssize_t
    764 sccInterruptWrite (int minor, const char *buf, size_t len)
     730static void
     731sccInterruptWrite (rtems_termios_device_context *base, const char *buf, size_t len)
    765732{
    766733  if (len > 0) {
    767     m8xx_console_chan_desc_t *cd = &m8xx_console_chan_desc[minor];
     734    m8xx_console_chan_desc_t *cd = (m8xx_console_chan_desc_t *)base;
    768735    if ((cd->sccPrepTxBd->status & M8xx_BD_READY) == 0) {
    769736      cd->sccPrepTxBd->buffer = (char *)buf;
     
    785752    }
    786753  }
    787 
    788   return 0;
    789 }
    790 
    791 static ssize_t
    792 sccPollWrite (int minor, const char *buf, size_t len)
    793 {
    794   m8xx_console_chan_desc_t *cd = &m8xx_console_chan_desc[minor];
     754}
     755
     756static void
     757sccPollWrite (rtems_termios_device_context *base, const char *buf, size_t len)
     758{
     759  m8xx_console_chan_desc_t *cd = (m8xx_console_chan_desc_t *)base;
    795760  static char txBuf[CONS_CHN_CNT][SCC_TXBD_CNT];
    796761  int chan = cd->chan;
    797762  int bd_used;
    798   size_t retval = len;
    799763
    800764  while (len--) {
     
    818782    }
    819783  }
    820   return retval;
    821784}
    822785
     
    833796    rtems_interrupt_disable(irq_level);
    834797
    835     sccPollWrite (BSP_output_chan,&c,1);
     798    sccPollWrite (&m8xx_console_chan_desc[BSP_output_chan].base,&c,1);
    836799    rtems_interrupt_enable(irq_level);
    837800  }
     
    860823};
    861824
     825static bool m8xx_console_first_open(
     826  rtems_termios_tty *tty,
     827  rtems_termios_device_context *base,
     828  struct termios *term,
     829  rtems_libio_open_close_args_t *args
     830)
     831{
     832  m8xx_console_chan_desc_t *cd = (m8xx_console_chan_desc_t *)base;
     833
     834  if (cd->mode == TERMIOS_IRQ_DRIVEN) {
     835    rtems_status_code sc;
     836
     837    sc = rtems_interrupt_handler_install(
     838      cd->ivec_src,
     839      "SCC",
     840      RTEMS_INTERRUPT_UNIQUE,
     841      sccInterruptHandler,
     842      tty
     843    );
     844    if (sc != RTEMS_SUCCESSFUL) {
     845      return false;
     846    }
     847
     848    mpc8xx_console_irq_on(cd);
     849  }
     850
     851  return true;
     852}
     853
     854static const rtems_termios_device_handler m8xx_console_handler_polled = {
     855  .first_open = m8xx_console_first_open,
     856  .set_attributes = sccSetAttributes,
     857  .write = sccPollWrite,
     858  .poll_read = sccPollRead,
     859  .mode = TERMIOS_POLLED
     860};
     861
     862static const rtems_termios_device_handler m8xx_console_handler_irq_driven = {
     863  .first_open = m8xx_console_first_open,
     864  .set_attributes = sccSetAttributes,
     865  .write = sccInterruptWrite,
     866  .mode = TERMIOS_IRQ_DRIVEN
     867};
    862868
    863869/*
     
    888894    if (channel_list[entry].driver_mode != CONS_MODE_UNUSED) {
    889895      m8xx_console_chan_desc_t *cd =
    890         &m8xx_console_chan_desc[channel_list[entry].driver_mode];
     896        &m8xx_console_chan_desc[channel_list[entry].minor];
    891897      /*
    892898       * Do device-specific initialization
     
    903909       * Register the device
    904910       */
    905       status = rtems_io_register_name (tty_name,
    906                                        major,
    907                                        channel_list[entry].minor);
     911      status = rtems_termios_device_install(
     912        tty_name,
     913        cd->mode == TERMIOS_IRQ_DRIVEN ?
     914          &m8xx_console_handler_irq_driven : &m8xx_console_handler_polled,
     915        NULL,
     916        &cd->base
     917      );
    908918      if (status != RTEMS_SUCCESSFUL) {
    909919        rtems_fatal_error_occurred (status);
    910920      }
    911     }
    912   }
    913   /*
    914    * register /dev/console
    915    */
    916   status = rtems_io_register_name ("/dev/console",
    917                                    major,
    918                                    CONSOLE_CHN);
    919   if (status != RTEMS_SUCCESSFUL) {
    920     rtems_fatal_error_occurred (status);
    921   }
    922   /*
    923    * enable printk support
    924    */
    925   BSP_output_chan = PRINTK_CHN;
    926 
    927   return RTEMS_SUCCESSFUL;
    928 }
    929 
    930 /*
    931  * Open the device
    932  */
    933 rtems_device_driver console_open(
    934                                  rtems_device_major_number major,
    935                                  rtems_device_minor_number minor,
    936                                  void                    * arg
    937                                  )
    938 {
    939   m8xx_console_chan_desc_t *cd = &m8xx_console_chan_desc[minor];
    940   rtems_status_code status;
    941   int chan = minor;
    942   rtems_libio_open_close_args_t *args = (rtems_libio_open_close_args_t *)arg;
    943   static const rtems_termios_callbacks interruptCallbacks = {
    944     NULL,               /* firstOpen */
    945     NULL,               /* lastClose */
    946     NULL,               /* pollRead */
    947     sccInterruptWrite,  /* write */
    948     sccSetAttributes,   /* setAttributes */
    949     NULL,               /* stopRemoteTx */
    950     NULL,               /* startRemoteTx */
    951     TERMIOS_IRQ_DRIVEN  /* outputUsesInterrupts */
    952   };
    953   static const rtems_termios_callbacks pollCallbacks = {
    954     NULL,               /* firstOpen */
    955     NULL,               /* lastClose */
    956     sccPollRead,        /* pollRead */
    957     sccPollWrite,       /* write */
    958     sccSetAttributes,   /* setAttributes */
    959     NULL,               /* stopRemoteTx */
    960     NULL,               /* startRemoteTx */
    961     0                   /* outputUsesInterrupts */
    962   };
    963 
    964   if (cd->mode == TERMIOS_IRQ_DRIVEN) {
    965     status = rtems_termios_open (major, minor, arg, &interruptCallbacks);
    966     m8xx_console_chan_desc[chan].tty = args->iop->data1;
    967   }
    968   else {
    969     status = rtems_termios_open (major, minor, arg, &pollCallbacks);
    970     m8xx_console_chan_desc[chan].tty = args->iop->data1;
    971   }
    972   return status;
    973 }
    974 
    975 /*
    976  * Close the device
    977  */
    978 rtems_device_driver console_close(
    979                                   rtems_device_major_number major,
    980                                   rtems_device_minor_number minor,
    981                                   void                    * arg
    982                                   )
    983 {
    984   rtems_status_code rc;
    985 
    986   rc = rtems_termios_close (arg);
    987   m8xx_console_chan_desc[minor].tty = NULL;
    988 
    989   return rc;
    990 
    991 }
    992 
    993 /*
    994  * Read from the device
    995  */
    996 rtems_device_driver console_read(
    997                                  rtems_device_major_number major,
    998                                  rtems_device_minor_number minor,
    999                                  void                    * arg
    1000                                  )
    1001 {
    1002   return rtems_termios_read (arg);
    1003 }
    1004 
    1005 /*
    1006  * Write to the device
    1007  */
    1008 rtems_device_driver console_write(
    1009                                   rtems_device_major_number major,
    1010                                   rtems_device_minor_number minor,
    1011                                   void                    * arg
    1012                                   )
    1013 {
    1014   return rtems_termios_write (arg);
    1015 }
    1016 
    1017 #if 0
    1018 static int scc_io_set_trm_char(rtems_device_minor_number minor,
    1019                                rtems_libio_ioctl_args_t *ioa)
    1020 {
    1021   rtems_status_code rc                = RTEMS_SUCCESSFUL;
    1022   con360_io_trm_char_t *trm_char_info = ioa->buffer;
    1023 
    1024   /*
    1025    * check, that parameter is non-NULL
    1026    */
    1027   if ((rc == RTEMS_SUCCESSFUL) &&
    1028       (trm_char_info == NULL)) {
    1029     rc = RTEMS_INVALID_ADDRESS;
    1030   }
    1031   /*
    1032    * transfer max_idl
    1033    */
    1034   if (rc == RTEMS_SUCCESSFUL) {
    1035     if (trm_char_info->max_idl >= 0x10000) {
    1036       rc = RTEMS_INVALID_NUMBER;
    1037     }
    1038     else if (trm_char_info->max_idl > 0) {
    1039       CHN_PARAM_SET(minor,un.uart.max_idl ,trm_char_info->max_idl);
    1040     }
    1041     else if (trm_char_info->max_idl == 0) {
    1042       CHN_PARAM_SET(minor,un.uart.max_idl ,MAX_IDL_DEFAULT);
    1043     }
    1044   }
    1045   /*
    1046    * transfer characters
    1047    */
    1048   if (rc == RTEMS_SUCCESSFUL) {
    1049     if (trm_char_info->char_cnt > CON8XX_TRM_CHAR_CNT) {
    1050       rc = RTEMS_TOO_MANY;
    1051     }
    1052     else if (trm_char_info->char_cnt >= 0) {
    1053       /*
    1054        * check, whether device is a SCC
    1055        */
    1056       if ((rc == RTEMS_SUCCESSFUL) &&
    1057           !m8xx_console_chan_desc[minor].is_scc) {
    1058         rc = RTEMS_UNSATISFIED;
    1059       }
    1060       else {
    1061         int idx = 0;
    1062         for(idx = 0;idx < trm_char_info->char_cnt;idx++) {
    1063           m8xx_console_chan_desc[minor].parms.sccp->un.uart.character[idx] =
    1064             trm_char_info->character[idx] & 0x00ff;
    1065         }
    1066         if (trm_char_info->char_cnt < CON8XX_TRM_CHAR_CNT) {
    1067           m8xx_console_chan_desc[minor].parms.sccp
    1068             ->un.uart.character[trm_char_info->char_cnt] = 0x8000;
     921
     922      if (cd->chan == CONSOLE_CHN) {
     923        int rv;
     924
     925        rv = link(tty_name, CONSOLE_DEVICE_NAME);
     926        if (rv != 0) {
     927          rtems_fatal_error_occurred (RTEMS_IO_ERROR);
    1069928        }
    1070929      }
     
    1072931  }
    1073932
    1074   return rc;
    1075 }
    1076 #endif
    1077 
    1078 /*
    1079  * Handle ioctl request.
    1080  */
    1081 rtems_device_driver console_control(
    1082                                     rtems_device_major_number major,
    1083                                     rtems_device_minor_number minor,
    1084                                     void                    * arg
    1085                                     )
    1086 {
    1087   rtems_libio_ioctl_args_t *ioa=arg;
    1088 
    1089   switch (ioa->command) {
    1090 #if 0
    1091   case CON8XX_IO_SET_TRM_CHAR:
    1092     return scc_io_set_trm_char(minor, ioa);
    1093 #endif
    1094   default:
    1095     return rtems_termios_ioctl (arg);
    1096     break;
    1097   }
    1098 }
    1099 
     933  /*
     934   * enable printk support
     935   */
     936  BSP_output_chan = PRINTK_CHN;
     937
     938  return RTEMS_SUCCESSFUL;
     939}
  • c/src/lib/libbsp/powerpc/tqm8xx/Makefile.am

    r68920e7f rd22147e  
    3333
    3434# console
     35librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
    3536librtemsbsp_a_SOURCES += ../../../../../../bsps/powerpc/tqm8xx/console/console.c
    3637# spi
Note: See TracChangeset for help on using the changeset viewer.