How to use Console Driver of RTEMS on MVME162

AJAI KUMAR MEDHAVI akmedhavi at rrcat.gov.in
Thu Aug 8 08:32:40 UTC 2013


HI

For using Console Driver, on MVME162-522 CPU Board, 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_terminios_initialize  / open rtems_terminios_open.





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



> Just use printf and regular C stdio.
>
> --joel
>
> On 8/2/2013 2:45 AM, AJAI KUMAR MEDHAVI wrote:
>> Hi
>>
>>
>> I am working on RTEMS 4.10.2 on MVME162-522A VME CPU Board. I wish to
>> use
>> RTEMS consloe driver (..\libbsp\m68k\mvme162\console) functions to read
>> /write on both channels of CPU board.
>>
>>
>> Here I have  following queries regarding console driver :
>>
>>
>> 1. How to wish to directly use rtems_io_read and rtems_io_write, for
>> writing/reading on channels,  by providng console/tty00/tty01 major and
>> minor number and pointer to arg.
>>
>>
>> here How should I know Console Major number. Because RTEMS itself
>> registers console driver if we include
>> "=define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER" in the application.
>>
>>
>> To find out Console Major/Minor number pair , I have used following call
>> in my application :
>>
>> /*----Get Console Device Major / Minor
>> Number---------------------------*/
>> 	status = rtems_io_lookup_name( "/dev/console",
>> &Console_low_level_device_info );
>> 	if(status != RTEMS_SUCCESSFUL)
>> 		rtems_fatal_error_occurred(status);
>>
>> 	Console_device_major = Console_low_level_device_info.major;
>> 	Console_device_minor = Console_low_level_device_info.minor;
>>
>> I have defined Console_device_major, Console_device_minor as global
>> variables.
>>
>>
>> printf("\n\nConsole Device Major No. : %d", (int)Console_device_major);
>> 	printf("\nConsole Device Minor No. : %d", (int)Console_device_minor);
>>
>>
>> but on printing Console Major/ Minor number is coming sometimes 0 / 0
>> and
>> sometimes  different values other than 0 / 0 when I compile my
>> application
>> without making any changes in console.c and above system call in my
>> application.
>>
>> When It major/monor comes 0 / 0 I am able to write on channel 0 bu using
>> console Major no. (zero) and minor number (Zero).
>>
>>
>> I am not able to understand why I am getting different values of Major /
>> Minor Values.
>>
>>
>> 2. Second, in console_initialize of
>> (..\libbsp\m68k\mvme162\console\console.c)
>>
>> I have found following code :
>>
>>
>> status = rtems_io_register_name(
>> 		"/dev/console",
>> 		major,
>> 		(rtems_device_minor_number) 1
>> 	);
>>
>> 	if (status != RTEMS_SUCCESSFUL)
>> 		rtems_fatal_error_occurred(status);
>>
>> 	status = rtems_io_register_name(
>> 		"/dev/tty00",
>> 		major,
>> 		(rtems_device_minor_number) 0
>> 	);
>>
>> 	if (status != RTEMS_SUCCESSFUL)
>> 		rtems_fatal_error_occurred(status);
>>
>> 	status = rtems_io_register_name(
>> 		"/dev/tty01",
>> 		major,
>> 		(rtems_device_minor_number) 1
>> 	);
>>
>>
>> It means Console Minor number must be (One), then I am getting console
>> minor number as zero, when comming correctly, and I am able to write on
>> console channel by proving console Major: 0 and Console Minor :0 in
>> rtems_io_write
>>
>>
>> Here I am confused whether console channel is channel-0 or Channel-1 of
>> Channels provided by Z85230 SCC Chip on MVME162 CPU Board. At present my
>> PC COM1 is connected to Console Port/Serial Port1 of CPU board.
>>
>>
>> Kindly let me know what are  exact channel number of
>> Console/tty00/tty01.
>> Please note that Z85230 SCC chip on MVME162 defines two channels CH-B
>> (channel 0 ) and CH-A (channel-1)
>>
>>
>> In brief , please let me know following :
>>
>> 1. how to find Console/tty00/tty01  Major/Minor number pair for using
>>     in rtems_io_read and rtems_io_write
>>
>>
>> 2. exact channel number of Console/tty00/tty01. Please note that Z85230
>> SCC chip on MVME162 defines two channels CH-B (channel 0 ) and CH-A
>> (channel-1)
>> Whther minor number 1 corresponds to Channel 1 of SCC and minor number 0
>> corresponds to channel number 0 of SCC.
>>
>>
>> 3. Why Console Major/ Minor number is coming  as 0/0 while "/dev/console
>> has been named as minor 1 in status =
>> rtems_io_register_name("/dev/console",
>> major, 	(rtems_device_minor_number) 1 )
>>
>>
>> Also not always as 0/0, it is coming with different - different values
>> like -1 / 444768 and 25768/25678 and so many values ....
>>
>>
>> 4. when I set "Console_Is_Initialized" to 1 in console_initialize(...)
>> then I get no printf on console as per following function in console.c
>>
>>
>> void _BSP_output_char(char c)
>> {
>>    if(Console_Is_Initialized)
>>      putchar(c);
>>    else
>>      _162Bug_output_char(c);
>>
>>    if ('\n' == c)
>>      _BSP_output_char('\r');
>> }
>>
>> What is exactly happening when I set Console_Is_Initialized to 1.
>>
>>
>>
>>
>> Kindly reply me at the earliest.
>>
>>
>> Thanks in advance
>>
>>
>>
>> Best regards
>>
>>
>>
>> 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
>>
>>
>>
>>
>>
>
>
> --
> 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