Raw use of APBUART with Termios pseudo driver in LEON3

Alberto Parnaso pafbat00 at yahoo.es
Tue Apr 1 06:36:36 UTC 2014


Hello all. I have been trying to setup a LEON3 system with RTEMS 4.10 with two (2) APBUARTs in it. My intention is to use one as system console and the other one for serial transmission/reception with Interrupt driven interface. After some reading I realise that APBUART RAW Driver is deprecated and that only way is the Console/Termios driver. 

So far I am capable of writing and reading from both APBUARTs either using IP Core Registers directly, or playing with which port is the system console. I had use the rtems_hello_multiple.c example to either choose APBUART0 or APBUART1 as system console, and both options work fine. However a can't configure the other APBUART as an interrupt driven raw UART. I copied some c code from someone that said that this configuration will Termios UART act as raw,
and it does, but my code only reads one by one byte and I am sure is in polled mode because it is only capable to "not lose" the same number of characters as the HW FIFO has.

I am looking for someones code which uses APBUART with Termios and Interrupt driven interface. Here is a snippet of my
code using APBUART0 as system console and trying to use erroneously APBUART1 as raw interrupt driven serial interface:
< ... >
   #include <drvmgr/ambapp_bus.h>
   /* APBUART0 */
   struct drvmgr_key grlib_drv_res_apbuart0[] =
   {
   {"mode", KEY_TYPE_INT, {(unsigned int)1}},
   {"syscon", KEY_TYPE_INT, {(unsigned int)1}},
   KEY_EMPTY
   };
   /* APBUART1 */
   struct drvmgr_key grlib_drv_res_apbuart1[] =
   {
  {"mode", KEY_TYPE_INT, {(unsigned int)1}},
  {"syscon", KEY_TYPE_INT, {(unsigned int)0}},
  KEY_EMPTY
   };
   /* LEON3 System with driver configuration for 2 APBUARTs, the
    * the rest of the AMBA device drivers use their defaults.
    */
   struct drvmgr_drv_res grlib_drv_resources[] =
   {
   /* DRIVER_ID, DEVICE_INSTANCE, CONFIGURATION_ARRAY
*/
   {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
   {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
   RES_EMPTY
   };

   int debug_uart_index = 1; /* second UART -- APBUART[1] */


<...>


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>



rtems_task Init (rtems_task_argument ignored)
{
 <...>
   /* Opening Communication devices (/dev/console_b) */
   dev_fd = open("/dev/console_b", O_RDWR);
if (dev_fd != 0)
{
printf("Failed to open /dev/console_b.\nCause open failed, ERRNO: %d = %s\n",errno,strerror(errno));
}

   /* Get current configuration */
   tcgetattr(dev_fd, &newTerm);

   newTerm.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ECHOPRT|ECHOCTL|ECHOKE|IEXTEN|ISIG);

   /* Local mode and receiver enabled */
   newTerm.c_cflag |= (CLOCAL | CREAD);

   /* 8 bits, enable receiver */
   newTerm.c_cflag |= CS8;

   /* Raw output */
   newTerm.c_oflag &= ~OPOST;

   /* Ignore breaks. */
   newTerm.c_iflag =  IGNBRK;
   newTerm.c_iflag &= ~INLCR; /*input modes*/

   /* Set UART Speed at 230400 bps */
  cfsetospeed (&newTerm, B230400);
  cfsetispeed (&newTerm, B230400);

   /* Update driver's settings */
   ret = tcsetattr(dev_fd, TCSANOW, &newTerm);
   tcflush(dev_fd, TCIOFLUSH);

  // While loop to test if interrupt is enabled in console b,
   // and also to test the length
of the RX buffer
   while (1)
   {
   printf("Send as many bytes by console b as needed\n");
   scanf ("%d", &ret);

   ret = read (dev_fd, buf, 10);
   printf("\nBytes read: %d. 0x%02X 0x%02X 0x%02X ...\n", ret, buf[0], buf[1], buf[2]);
   memset (buf, 0, 1000);

   }

printf ("Finish prueba_uart_raw Application!\n");

exit( 0 );
<...>

My problem is that "read" function always returns '1' (when bytes
have been received of course) instead of the number of bytes received. It is also not Interrupt driven.

May anyone give me some clue of what am I doing wrong?
Thank you!

pafbat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20140401/97185526/attachment.html>


More information about the users mailing list