<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi guys,<br>
    <br>
    I am new to RTEMS and am trying to build a motor controller with
    LEON3 architecture. <br>
    <br>
    I have set the console to use it in "raw-mode". I tried my code in
    both polling-mode and interrupt-mode of the console. <br>
    <br>
    In polling-mode, it works, it takes up a lot of cpu (~70% @ 90MHz)
    and it looses data if it runs any slower.  It is effectively useless
    for running the controller.<br>
    <br>
    In interrupt-mode, at first nothing worked. The console was being
    opened twice by RTEMS causing an error. Then I figured out a bug in
    the console driver and modified it to sort it out. It now works, but
    creates segmentation fault after running for sometime, the cause of
    which I can't figure out.<br>
    <br>
    Am I doing it the wrong way? Is the console bug fix somehow causing
    the segmentation fault? Is it a bad idea to use the console driver
    for this?<br>
    <br>
    I need to use it to send and receive lots of data. Any help would be
    appreciated !!!!!!<br>
    <br>
    regards<br>
    Ajish Babu<br>
    <br>
    <i><big>my code: </big></i><br>
    <small><br>
      #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER<br>
      #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER<br>
      <br>
      #define CONFIGURE_RTEMS_INIT_TASKS_TABLE<br>
      #define CONFIGURE_MAXIMUM_TASKS 3<br>
      #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10<br>
      <br>
      #define CONFIGURE_INIT<br>
      #define CONFIGURE_MICROSECONDS_PER_TICK 1000<br>
      <br>
      #include <rtems/confdefs.h><br>
      <br>
      rtems_id tid_print, tid_read;<br>
      <br>
      extern int errno;<br>
      unsigned int size, data_length;<br>
      int serialPort;<br>
      char buffer[255];<br>
      char data[255];<br>
      <br>
      void assert_status(rtems_status_code status)<br>
      {<br>
          if ( status != RTEMS_SUCCESSFUL ) {<br>
              printk( "RTMES assertion failed with status of %d.\n",
      status );<br>
              exit( 1 );<br>
          }<br>
      }<br>
      <br>
      void OpenPort()<br>
      {<br>
          size = 0;<br>
          data_length = 0;<br>
          assert_status( rtems_termios_bufsize( 1024, 512, 512 ) );<br>
          // Opens console for writing<br>
          serialPort = open("/dev/console", O_RDONLY );<br>
          if (serialPort == -1) <br>
          {<br>
              printk("Opening Console error: %s", strerror(errno));<br>
              exit( 1 );<br>
          } <br>
          struct termios config;<br>
          // gets the current configuration<br>
          tcgetattr( serialPort, &config);<br>
      <br>
          // Raw mode<br>
          config.c_iflag &=
      ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);<br>
          config.c_oflag &= ~OPOST;<br>
          config.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);<br>
          config.c_cflag &= ~(CSIZE|PARENB);<br>
          config.c_cflag |= CS8;<br>
          cfsetospeed( &config, B19200 );<br>
          cfsetispeed( &config, B19200 );<br>
          // Sets the modified configuration<br>
          if(tcsetattr(serialPort, TCSANOW, &config) < 0)<br>
          {<br>
              printk("\nERROR: Set console attribites : %s\n",
      strerror(errno));<br>
          }<br>
      }<br>
      <br>
      rtems_task ReadStream(rtems_task_argument argument)<br>
      {<br>
          int i;<br>
          OpenPort();<br>
          do<br>
          {<br>
              // Reads the data<br>
              size = read( serialPort, buffer, 255 );<br>
              if( size > 0 )<br>
              {<br>
                  // Stores the data to print it in PrintData<br>
                  for( i = 0; i < size; i++ )<br>
                  {<br>
                      data[data_length++] = buffer[i];<br>
                      if( data_length >= 255 )<br>
                          data_length = 0;<br>
                  }<br>
                  data[data_length] = '\0';<br>
              }<br>
          } <br>
          while( 1 ); //rtems_clock_get_ticks_since_boot() < 60000 );<br>
      <br>
          close( serialPort );<br>
          rtems_cpu_usage_report();<br>
          assert_status( rtems_task_delete( tid_print ) ); <br>
          assert_status( rtems_task_delete( RTEMS_SELF ) ); <br>
      }<br>
      <br>
      rtems_task PrintData(rtems_task_argument argument)<br>
      {<br>
          while(1)  <br>
          {<br>
              printk("DATA: \n");<br>
              rtems_print_buffer( (unsigned char *)data, data_length );<br>
              rtems_task_wake_after( 1000 );<br>
          }<br>
          assert_status( rtems_task_delete( RTEMS_SELF ) );<br>
      }<br>
      <br>
      rtems_task Init( rtems_task_argument argument )<br>
      {<br>
          assert_status( <br>
                  rtems_task_create(<br>
                      rtems_build_name( 'R', 'E', 'A', 'D' ),<br>
                      2, <br>
                      RTEMS_MINIMUM_STACK_SIZE,<br>
                      RTEMS_PREEMPT, <br>
                      RTEMS_NO_FLOATING_POINT, <br>
                      &tid_read<br>
                      ) <br>
                  );<br>
          assert_status(<br>
                  rtems_task_create(<br>
                      rtems_build_name( 'P', 'R', 'I', 'N' ), <br>
                      1, <br>
                      RTEMS_MINIMUM_STACK_SIZE,<br>
                      RTEMS_PREEMPT, <br>
                      RTEMS_NO_FLOATING_POINT, <br>
                      &tid_print<br>
                      )<br>
                  );<br>
      <br>
          assert_status( rtems_task_start( tid_print, PrintData       ,
      0 ) );<br>
          assert_status( rtems_task_start( tid_read , ReadStream      ,
      0 ) );<br>
          assert_status( rtems_task_delete( RTEMS_SELF ) );<br>
      }</small><br>
    <br>
    <big><i>Modified console.c code changes</i><i>:</i></big><br>
    <small>...<br>
        volatile int sending;<br>
        char *buf;<br>
      <b>  int irq_open;</b><br>
      #endif<br>
      ...<br>
      #if CONSOLE_USE_INTERRUPTS<br>
        apbuarts[uarts].irq = apb->irq;<br>
      <b>  apbuarts[uarts].irq_open = 0;</b><br>
      #endif<br>
      ....<br>
        /* Register Interrupt handler */<br>
      <b>  if (!uart->irq_open) {</b><br>
          sc = rtems_interrupt_handler_install(uart->irq, "console",<br>
                           RTEMS_INTERRUPT_SHARED, console_isr,<br>
                           uart);<br>
          if (sc != RTEMS_SUCCESSFUL)<br>
            return sc;<br>
      <b>  }</b><b><br>
      </b><b>  uart->irq_open++;</b><br>
      <br>
        uart->sending = 0;<br>
      ....<br>
      <br>
        /* uninstall ISR */<br>
      <b>  uart->irq_open--;</b><b><br>
      </b><b>  if (!uart->irq_open) {</b><br>
          rtems_interrupt_handler_remove(uart->irq, console_isr,
      uart);<br>
      <b>  }</b><br>
      #endif</small><br>
    <br>
    <br>
  </body>
</html>