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
Mon Aug 19 10:23:23 UTC 2013


Dear Chris,


Thanks for your kind reply. The comments are very useful for me.


As per your advice, I have used following calls for Console Port (Port 1) :


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


Now the issue is related to read/write from/to serial port 2. First Please
find some facts :


1. In rtems-4.10.2\c\src\lib\libbsp\m68k\mvme162\console.c ,
rtems_console_initialization function registers tty00 and tty01 as given
below :

status = rtems_io_register_name("/dev/tty00", major,
(rtems_device_minor_number) 0);


status = rtems_io_register_name("/dev/tty01", major,
(rtems_device_minor_number) 1 );


2. In rtems-4.10.2\c\src\lib\libbsp\m68k\mvme162\console.c , there is no
call for :

rtems_termios_initialize, rtems_termios_open and rtems_termios_close


3. The file rtems-4.10.2\c\src\lib\libbsp\m68k\mvme162\console.c says "We
only have stdin/stdout".


4. Whenever a char is received an interrupt invokes and adds char in a
buffer.


Most probably due to above facts, There is error in Opening tty00 (serial
port 2) and consequently failure of read / write on serial port 2 :


I have used following in my application :


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

fd0 = open(device0, O_RDWR);
fd1 = open(device0, O_RDWR);


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


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



Please note that I have initialized both channels of Z85230 of SCC of
MVME162-522A by adding following calls in  console_initialize(...)

SCC_Initialize_channels();


I have kept the source code for SCC_Initialize_channels() in other files
and have integrated with console.c If you need source code added, I may
provide source files.


Now Kindly advise me whether I have to modify my console.c to use
rtems_termios calls for initialization, opening, setting parameters and
closing tty00 and tty01.


Meantime I shall go through and try following assuggested by you :

1. 
http://www.freebsd.org/cgi/man.cgi?query=termios&apropos=0&sektion=0&manpath=FreeBSD+9.1-RELEASE&arch=default&format=html

2. "termios examples".


http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html


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


> AJAI KUMAR MEDHAVI wrote:
>>
>>
>> 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));
>
> You could use ...
>
>    nbytes = read(STDIN_FILENO, buf, sizeof(buf));
>
> You are accessing stdin.
>
>>     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);
>
> and ..
>
>    len = write(STDOUT_FILENO, respmsg, 4);
>
> This is writing to stdout, the same device printf uses by default.
>
>>
>>
>> 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)
>>
>
> These are opened for you during initialization.
>
>>
>> but following read/write functions for Serial port 2 (tty00 / tty01) are
>> not working :
>>
>> read(1, buf, sizeof(buf));
>> write(0, respmsg, 4);
>>
>
> You need to use the 'fd' returned by the 'open'. You should also call
> close with the fd when you are finished.
>
>>
>> Please advise me on following points :
>>
>> 1. Whether first parameter in read/write functions corresponds to minor
>> no
>> of console driver.
>>
>
> I suggest you read the man page for open, read and write. FreeBSD
> provide a suitable resource online. The open man page is ...
>
> http://www.freebsd.org/cgi/man.cgi?query=open&apropos=0&sektion=0&manpath=FreeBSD+9.1-RELEASE&arch=default&format=html
>
>>
>> 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.
>>
>
> I also suggest you read about 'termios' ...
>
> http://www.freebsd.org/cgi/man.cgi?query=termios&apropos=0&sektion=0&manpath=FreeBSD+9.1-RELEASE&arch=default&format=html
>
> This effects what happens to the data arriving over the serial port. For
> example the serial port may have default to requiring hardware hardware
> handshaking and the signals have not been asserted by the remote device.
> You also need to set the correct baudrate matching the remote device.
>
>>
>> 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);
>>
>
> I suggest you use the standard functions such as open, read and write
> and not the ones used to implement the standard interfaces.
>
>>
>> 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)
>>
>
> I am sorry but I do not know the answer to this question. They should be
> the same if the BSP has not changed.
>
>>
>> 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).
>>
>
> May I suggest you google "termios examples". This looks like an
> interesting one to try ...
>
> http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html
>
>> 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.
>>
>
> The open call will happen when you use the 'open' call with the correct
> path to the tty01.
>
> Chris
>


-- 




More information about the users mailing list