Serial device access with qemu!

Joel Sherrill joel.sherrill at OARcorp.com
Tue Nov 23 14:21:45 UTC 2010


On 11/23/2010 02:50 AM, Jeferson Luiz Rodrigues Souza wrote:
> Hi everyone,
>
> I am trying to access a serial port in RTEMS 4.9.4 using a pc586 bsp. 
> However, when I execute the application using qemu the code cannot 
> open the device, and the perror() function presents the following 
> message: "No such file or directory". It seems that RTEMS did not 
> initialize a properly driver to handle serial device. Is it right?
>
> The qemu command line is:
>
> sudo qemu -serial "/dev/ttyS0" -fda floppy.img -boot a
>
> I made a search in this list and I found references about serial port 
> access but nothing to help in my case. Could anyone help me or point 
> me some documentation about serial port access in RTEMS?
>
> The code used in the test is presented below. I do not have some 
> experience with RTEMS and I do not know the source of this problem.
>
The /dev/ttyS0 above is the host serial port.  The -serial says
attach attach the serial port COM1 on the target simulator
PC to the specified device.  So you are attaching the virtual
COM1 to the real serial port on the host /dev/ttyS0. Is that
what you intend to do?

FWIW COM1 --> /dev/ttyS1
COM2 --> /dev/ttyS2

on the RTEMS target.

--joel
> Thanks,
> jefecomp.
>
>
> #include <signal.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <pthread.h>
> #include <uart.h>
> #include <termios.h>
> #include<sched.h>
> #include <bsp.h>
> #include <fcntl.h>
> #include <sys/types.h>
> #include <sys/stat.h>
>
> #define CONFIGURE_INIT
> #include <rtems.h>
>
>
> void *POSIX_Init();
>
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_APPLICATIONS_NEEDS_RTC_DRIVER
> #define CONFIGURE_MICROSECONDS_PER_TICK 1000
>
> #define CONFIGURE_MAXIMUM_POSIX_THREADS 10
> #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
> #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
> #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 10
> #define CONFIGURE_MAXIMUM_POSIX_TIMERS 10
> #define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 40
> #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 10
> #define CONFIGURE_POSIX_INIT_THREAD_TABLE
> #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
> #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 3
> #include<rtems/confdefs.h>
>
> void *POSIX_Init()
> {
>     printf("Serial Port Test!!!\n");
>
>     char buffer[255];
>     int bytesRead;
>     int serial_fp = open("/dev/ttyS0",O_RDONLY);
>
>     printf("SERIAL_FP = %i\n",serial_fp);
>
>     if(serial_fp < 0)
>     {
>         printf("FAILURE TO OPEN SERIAL PORT\n");
>         perror(serial_fp);
>         exit(-1);
>     }
>
>     //write(serial_fp,buffer,strlen(buffer)+1);
>     bytesRead = read(serial_fp, buffer, 255);
>
>
>     if(bytesRead < 0)
>     {
>         printf("Problems in the read of Serial Port");
>         close(serial_fp);
>         exit(1);
>     }
>     else
>         buffer[bytesRead] = 0;
>
>
>     printf(buffer);
>
>     close(serial_fp);
>     exit(0);
> }


-- 
Joel Sherrill, Ph.D.             Director of Research&  Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985





More information about the users mailing list