Waiting for response --- Read() and Write C functions are working only for Console Port, not for another serial port on MVME162

AJAI KUMAR MEDHAVI akmedhavi at rrcat.gov.in
Wed Aug 14 07:42:43 UTC 2013


HI


I have tried Read(..) and Write(...) C functions to read/write from
Console Port / Serial port1 and Serial port 2 on MVME162-522A CPU Board
ruuning RTEMS 4.10.2 . But it is only working for console port(serial port
1) and not for Serial Port2.


I have used following read() and write() functions to read/write from
Console Port ( Serial Port 1 on CPU Board) :


FOR READING FROM CONSOLE PORT  :

   char buf[5];

   memset(buf, 0, sizeof(buf));
   nbytes = read(0, buf, sizeof(buf));
   printf("string read = %s\n", buf);


TO WRITE ON CONSOLE PORT :

   int len;
   char *respmsg;  (Global variable)
   rtems_libio_rw_args_t *rw_args_test; (Global Variable)

   respmsg[0]= 69;
   respmsg[1]= 70;
   respmsg[2]= 71;
   respmsg[3]= 72;


   rw_args_test->buffer = respmsg;
   rw_args_test->count = 4;

   len = write(1, respmsg, 4);


The above read(0, buf, sizeof(buf)) and  write(1, respmsg, 4) functions
are working fine for Console Port (Serial port 1) without using

open("/dev/console", O_RDWR)


but following read/write functions for Serial port 2 (tty00 / tty01) are
not working :

read(1, buf, sizeof(buf));
write(0, respmsg, 4);


Please advise me on following points :

1. Whether first parameter in read/write functions corresponds to minor no
of console driver.


2. Whether I have to open ports using system call Open(...,...) like

     fd = open("/dev/console", O_RDWR)

   Please note that I have also tried by following :

   static const char                 device0[] = "/dev/tty00";
   static const char                 device1[] = "/dev/tty01";

   fd0 = open(device0, O_RDWR);
        rtems_test_assert(fd0 >= 0);

   fd1 = open(device0, O_RDWR);
   rtems_test_assert(fd1 >= 0);


   nbytes = read(fd0, buf, sizeof(buf));
   len = write(fd0, respmsg, 4);


    nbytes = read(fd1, buf, sizeof(buf));
    len = write(fd1, respmsg, 4);

    But this method is not working for both Serial port 1 (Console) and
    Serial port 2.


3. When console Major/Minor number comes as 0/0 then following calls are
   working fine :


rtems_io_write(Console_device_major_number,(rtems_device_minor_number)0,
(void  *)rw_args_test);

rtems_io_write(Console_device_major_number,(rtems_device_minor_number)1,
(void  *)rw_args_test);


but on using write functions :
  write(1, respmsg, 4);
  write(0, respmsg, 4);

only write(1, respmsg, 4) is working on console port.


4. One more stange thing I wish to share :

   In testsuites\hello\init.c, By putting follwoing I have made hello.ralf
downloadable file

status = rtems_io_lookup_name("/dev/console",
&Console_low_level_device_info);
        if(status == RTEMS_SUCCESSFUL)
        {
                printf("\nrtems_io_lookup_name : successful");
                Console_device_major_number =
Console_low_level_device_info.major;
                Console_device_minor_number =
Console_low_level_device_info.minor;
                printf("\n\nConsole Device Major No. : %d",
(int)Console_device_major_number);
                printf("\n\nConsole Device Minor No. : %d",
(int)Console_device_major_number);
        }

On running hello.ralf on CPU board, when I get console major/minor number
0/0 then rtems_io_read/ rtems_io_write and write(1,respmsg, len) calls
work fine.

But on next day, when I run same hello.ralf on CPU board, I get Console
Major/Minor no. different (like -1/-1 or any other values) and
rtems_io_read/ rtems_io_write gets failed but write(1,respmsg, len)
however write(0,respmsg, len) is stil not working.

Any idea how same hello.ralf downloadable file is giving different
major/minor number on next day. (is there any bug in rtems_io_lookup_name)




Kindly provide an example for using  console driver for read/write on both
channels (Please note that Minor number for Console, tty00, tty01 are
1,0,1 in Console driver for MVME162).

You also look  rtems-4.10.2\c\src\lib\libbsp\m68k\mvme162\console.c for
your reference.


Here in console.c,  tty00/ttyo1 have not been initialized /open with
rtems_termios_initialize  / open rtems_termios_open. also tty00/tty01
read/write functions are not using rtems_termios_read and
rtems_termios_write. Whether it may be the reason for problem on reading /
writing on serial port2.



Hoping earliest replies.


Thanks in advance




AJAI KUMAR MEDHAVI
SCIENTIFIC OFFICER
RAJA RAMMANNA CENTRE FOR ADVANCED TECHNOLGY
DEPARTMENT OF ATOMIC ENERGY, GOV. OF INDIA,
PO : CAT, INDORE-452013, INDIA
PH. 91-731-2488052
Email : akmedhavi at rrcat.gov.in , akmedhavi at rediffmail.com




-- 





More information about the users mailing list