source: rtems/testsuites/libtests/termios/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 18.9 KB
RevLine 
[514cf30]1/*
2 * RTEMS configuration/initialization
[8f71a36]3 *
[514cf30]4 * This program may be distributed and used for any purpose.
5 * I ask only that you:
[df49c60]6 *  1. Leave this author information intact.
7 *  2. Document any changes you make.
[514cf30]8 *
9 * W. Eric Norum
10 * Saskatchewan Accelerator Laboratory
11 * University of Saskatchewan
12 * Saskatoon, Saskatchewan, CANADA
13 * eric@skatter.usask.ca
[8f71a36]14 *
[df49c60]15 * Additions:
16 * Charles-Antoine Gauthier
17 * Software Engineering Group
18 * Institute for Information Technology
19 * National Research Council of Canada
20 * charles.gauthier@nrc.ca
[514cf30]21 */
22
[7d3f9c6]23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
[514cf30]27#include <bsp.h>
28
[11b9b5d]29#include <rtems/shell.h>
[93531e9b]30#include <rtems/termiostypes.h>
[514cf30]31
32#include <stdio.h>
33#include <unistd.h>
34#include <termios.h>
35#include <errno.h>
36#include <string.h>
37
[016a926]38#include <tmacros.h>
39
[f8b2eb03]40const char rtems_test_name[] = "TERMIOS";
41
[4c86e3d]42/* forward declarations to avoid warnings */
43rtems_task Init(rtems_task_argument argument);
44void print_32bits(unsigned long bits, unsigned char size, char * names[]);
45void print_c_iflag(struct termios * tp);
46void print_c_oflag(struct termios * tp);
47void print_c_lflag(struct termios * tp);
48void print_c_cflag(struct termios * tp);
49void print_c_cc(struct termios * tp);
[1c6926c1]50void print_baud(const char* name, speed_t spd);
[4c86e3d]51void print_termios(struct termios *tp);
52unsigned long get_baud_rate(void);
53unsigned long get_parity(void);
54unsigned long get_stop_bits(void);
55unsigned long get_data_bits(void);
56void change_line_settings(struct termios *tp);
57void canonical_input(struct termios *tp);
58void do_raw_input(int vmin, int vtime);
59void usage(void);
60
[df49c60]61#if !defined(fileno)
[bfded728]62int fileno( FILE *stream); /* beyond ANSI */
[df49c60]63#endif
64
65/* Some of the termios dumping code depends on bit positions! */
66
67void print_32bits( unsigned long bits, unsigned char size, char * names[] )
68{
69  unsigned char i;
70
71  for( i = 0; i < size; i++ ) {
72    if( (bits >> i) & 0x1 )
73      printf( "%s ", names[i] );
74  }
75}
76
77
78void print_c_iflag( struct termios * tp )
79{
80  char * c_iflag_bits [] = {
81    "IGNBRK",   /* 0000001 */
82    "BRKINT",   /* 0000002 */
83    "IGNPAR",   /* 0000004 */
84    "PARMRK",   /* 0000010 */
85    "INPCK",    /* 0000020 */
86    "ISTRIP",   /* 0000040 */
87    "INLCR",    /* 0000100 */
88    "IGNCR",    /* 0000200 */
89    "ICRNL",    /* 0000400 */
90    "IUCLC",    /* 0001000 */
91    "IXON",     /* 0002000 */
92    "IXANY",    /* 0004000 */
93    "IXOFF",    /* 0010000 */
94    "IMAXBEL",  /* 0020000 */
95    "unknown",  /* 0040000 */
96    "unknown",  /* 0100000 */
97    "unknown",  /* 0200000 */
98    "unknown",  /* 0400000 */
99    "unknown",  /* 1000000 */
100    "unknown",  /* 2000000 */
101    "unknown"   /* 4000000 */
102  };
103
104  printf( "c_iflag = 0x%08x\n\t", tp->c_iflag );
105  print_32bits( tp->c_iflag, sizeof( c_iflag_bits )/sizeof( char * ), c_iflag_bits );
106  printf( "\n" );
107}
108
109
110void print_c_oflag( struct termios * tp )
111{
112  printf( "c_oflag = 0x%08x\n\t", tp->c_oflag );
113
114  if( tp->c_oflag & OPOST )
115    printf( "OPOST " );
[8f71a36]116
[df49c60]117  if( tp->c_oflag & OLCUC )
118    printf( "OLCUC " );
[8f71a36]119
[df49c60]120  if( tp->c_oflag & ONLCR )
121    printf( "ONLCR " );
[8f71a36]122
[1c6926c1]123  if( tp->c_oflag & ONOEOT )
124    printf( "ONOEOT " );
125
[df49c60]126  if( tp->c_oflag & OCRNL )
127    printf( "OCRNL " );
[8f71a36]128
[df49c60]129  if( tp->c_oflag & ONOCR )
130    printf( "ONOCR " );
[8f71a36]131
[df49c60]132  if( tp->c_oflag & ONLRET )
133    printf( "ONLRET " );
[8f71a36]134
[df49c60]135  printf( "\n" );
136}
137
138
139void print_c_lflag( struct termios * tp )
140{
141  char * c_lflag_bits [] = {
[1c6926c1]142    "ECHOKE",      /* 0x00000001 */
143    "ECHOE",       /* 0x00000002 */
144    "ECHOK",       /* 0x00000004 */
145    "ECHO",        /* 0x00000008 */
146    "ECHONL",      /* 0x00000010 */
147    "ECHOPRT",     /* 0x00000020 */
148    "ECHOCTL",     /* 0x00000040 */
149    "ISIG",        /* 0x00000080 */
150    "ICANON",      /* 0x00000100 */
151    "ALTWERASE",   /* 0x00000200 */
152    "IEXTEN",      /* 0x00000400 */
153    "EXTPROC",     /* 0x00000800 */
154    "XCASE",       /* 0x00001000 */
155    "unknown",     /* 0x00002000 */
156    "unknown",     /* 0x00004000 */
157    "unknown",     /* 0x00008000 */
158    "unknown",     /* 0x00010000 */
159    "unknown",     /* 0x00020000 */
160    "unknown",     /* 0x00040000 */
161    "unknown",     /* 0x00080000 */
162    "unknown",     /* 0x00100000 */
163    "unknown",     /* 0x00200000 */
164    "TOSTOP",      /* 0x00400000 */
165    "FLUSHO",      /* 0x00800000 */
166    "unknown",     /* 0x01000000 */
167    "NOKERNINFO",  /* 0x02000000 */
168    "unknown",     /* 0x04000000 */
169    "unknown",     /* 0x08000000 */
170    "unknown",     /* 0x10000000 */
171    "PENDIN",      /* 0x20000000 */
172    "unknown",     /* 0x40000000 */
173    "NOFLSH",      /* 0x80000000 */
[df49c60]174  };
[8f71a36]175
[df49c60]176  printf( "c_lflag = 0x%08x\n\t", tp->c_lflag );
177  print_32bits( tp->c_lflag, sizeof( c_lflag_bits )/sizeof( char * ), c_lflag_bits );
178  printf( "\n" );
179}
180
181
182void print_c_cflag( struct termios * tp )
183{
184  printf( "c_cflag = 0x%08x\n", tp->c_cflag );
[c0ffdee]185
[df49c60]186  switch( tp->c_cflag & CSIZE ) {
187    case CS5:
188      printf( "\tCSIZE =\tCS5\n" );
189      break;
[8f71a36]190
[df49c60]191    case CS6:
192      printf( "\tCSIZE =\tCS6\n" );
193      break;
[8f71a36]194
[df49c60]195    case CS7:
196      printf( "\tCSIZE =\tCS7\n" );
197      break;
[8f71a36]198
[df49c60]199    case CS8:
200      printf( "\tCSIZE =\tCS8\n" );
201      break;
202  }
203
[1c6926c1]204  if( tp->c_cflag & CIGNORE )
205    printf( "\tCIGNORE set: iqnore c_cflags enabled\n" );
206  else
207    printf( "\tCIGNORE clear: iqnore c_cflags disabled\n" );
208
[df49c60]209  if( tp->c_cflag & CSTOPB )
210    printf( "\tCSTOPB set: send 2 stop bits\n" );
211  else
212    printf( "\tCSTOPB clear: send 1 stop bit\n" );
[8f71a36]213
[df49c60]214  if( tp->c_cflag & PARENB )
215    printf( "\tPARENB set: parity enabled\n" );
216  else
217    printf( "\tPARENB clear: parity disabled\n" );
[8f71a36]218
[df49c60]219  if( tp->c_cflag & PARODD )
220    printf( "\tPARODD set: parity odd\n" );
221  else
222    printf( "\tPARODD clear: parity even\n" );
[8f71a36]223
[df49c60]224  if( tp->c_cflag & CREAD )
225    printf( "\tCREAD set: receiver enabled\n" );
226  else
227    printf( "\tCREAD clear: treceiver disabled\n" );
[8f71a36]228
[df49c60]229  if( tp->c_cflag & HUPCL )
230    printf( "\tHUPCL set: enabled\n" );
231  else
232    printf( "\tHUPCL clear: disabled\n" );
[8f71a36]233
[df49c60]234  if( tp->c_cflag & CLOCAL )
235    printf( "\tCLOCAL set: ignore modem lines\n" );
236  else
237    printf( "\tCLOCAL clear: don't ignore modem lines\n" );
[8f71a36]238
[1c6926c1]239  if( tp->c_cflag & CCTS_OFLOW )
240    printf( "\tCCTS_OFLOW: hardware CTS output flow control enabled\n" );
[df49c60]241  else
[1c6926c1]242    printf( "\tCCTS_OFLOW: hardware CTS output flow control disabled\n" );
243
244  if( tp->c_cflag & CRTS_IFLOW )
245    printf( "\tCRTS_IFLOW: hardware RTS input flow control enabled\n" );
246  else
247    printf( "\tCRTS_IFLOW: hardware RTS input flow control disabled\n" );
[8f71a36]248
[df49c60]249  if( tp->c_cflag & CRTSCTS )
250    printf( "\tCRTSCTS: harware flow control enabled?\n" );
251  else
252    printf( "\tCRTSCTS: hardware flow control disabled?\n" );
[1c6926c1]253
254  if( tp->c_cflag & CDSR_OFLOW )
255    printf( "\tCDSR_OFLOW: hardware DSR output flow control enabled\n" );
256  else
257    printf( "\tCDSR_OFLOW: hardware DSR output flow control disabled\n" );
258
259  if( tp->c_cflag & CDTR_IFLOW )
260    printf( "\tCDTR_IFLOW: hardware DTR input flow control enabled\n" );
261  else
262    printf( "\tCDTR_IFLOW: hardware DTR input flow control disabled\n" );
263
264  if( tp->c_cflag & CCAR_OFLOW )
265    printf( "\tCCAR_OFLOW: hardware CD output flow control enabled\n" );
266  else
267    printf( "\tCCAR_OFLOW: hardware CD output flow control disabled\n" );
[df49c60]268}
269
270
271void print_c_cc( struct termios * tp )
272{
[dda9a682]273  size_t i;
274  char * cc_index_names [ /* NCCS */ ] = {
[1c6926c1]275    "[VEOF]    ",   /* 0 */
276    "[VEOL]    ",   /* 1 */
277    "[VEOL2]   ",   /* 2 */
278    "[VERASE]  ",   /* 3 */
279    "[VWERASE] ",   /* 4 */
280    "[VKILL]   ",   /* 5 */
281    "[VREPRINT]",   /* 6 */
282    "[VERASE2] ",   /* 7 */
283    "[VINTR]   ",   /* 8 */
284    "[VQUIT]   ",   /* 9 */
[df49c60]285    "[VSUSP]   ",   /* 10 */
[1c6926c1]286    "[VDSUSP]  ",   /* 11 */
287    "[VSTART]  ",   /* 12 */
288    "[VSTOP]   ",   /* 13 */
289    "[VLNEXT]  ",   /* 14 */
290    "[VDISCARD]",   /* 15 */
291    "[VMIN]    ",   /* 16 */
292    "[VTIME]   ",   /* 17 */
293    "[VSTATUS] ",   /* 18 */
294    "unknown   ",   /* 19 */
[df49c60]295  };
296
[dda9a682]297  for( i = 0; i < sizeof(cc_index_names)/sizeof(char*) ; i++ ) {
[df49c60]298    printf( "c_cc%s = 0x%08x\n", cc_index_names[i], tp->c_cc[i] );
299  }
300}
301
302
[1c6926c1]303void print_baud( const char* name, speed_t spd )
304{
305  switch( spd ) {
306  case B0:
307    printf( "%s = B0\n", name );
308    break;
309
310  case B50:
311    printf( "%s = B50\n", name );
312    break;
313
314  case B75:
315    printf( "%s = B75\n", name );
316    break;
317
318  case B110:
319    printf( "%s = B110\n", name );
320    break;
321
322  case B134:
323    printf( "%s = B134\n", name );
324    break;
325
326  case B150:
327    printf( "%s = B150\n", name );
328    break;
329
330  case B200:
331    printf( "%s = B200\n", name );
332    break;
333
334  case B300:
335    printf( "%s = B300\n", name );
336    break;
337
338  case B600:
339    printf( "%s = B600\n", name );
340    break;
341
342  case B1200:
343    printf( "%s = B1200\n", name );
344    break;
345
346  case B1800:
347    printf( "%s = B1800\n", name );
348    break;
349
350  case B2400:
351    printf( "%s = B2400\n", name );
352    break;
353
354  case B4800:
355    printf( "%s = B4800\n", name );
356    break;
357
358  case B9600:
359    printf( "%s = B9600\n", name );
360    break;
361
362  case B19200:
363    printf( "%s = B19200\n", name );
364    break;
365
366  case B38400:
367    printf( "%s = B38400\n", name );
368    break;
369
370  case B7200:
371    printf( "%s = B7200\n", name );
372    break;
373
374  case B14400:
375    printf( "%s = B14400\n", name );
376    break;
377
378  case B28800:
379    printf( "%s = B28800\n", name );
380    break;
381
382  case B57600:
383    printf( "%s = B57600\n", name );
384    break;
385
386  case B76800:
387    printf( "%s = B76800\n", name );
388    break;
389
390  case B115200:
391    printf( "%s = B115200\n", name );
392    break;
393
394  case B230400:
395    printf( "%s = B230400\n", name );
396    break;
397
398  case B460800:
399    printf( "%s = B460800\n", name );
400    break;
401
402  case B921600:
403    printf( "%s = B921600\n", name );
404    break;
405
406  default:
407    printf( "%s = unknown (0x%08x)\n", name, (unsigned int)spd );
408    break;
409  }
410}
411
412
[df49c60]413void print_termios( struct termios *tp )
414{
415  printf( "\nLooking at the current termios settings:\n\n" );
416  print_c_iflag( tp );
417  print_c_oflag( tp );
418  print_c_cflag( tp );
419  print_c_lflag( tp );
420  print_c_cc( tp );
[1c6926c1]421  print_baud( "c_ispeed", tp->c_ispeed );
422  print_baud( "c_ospeed", tp->c_ospeed );
[df49c60]423  printf( "\n" );
424}
425
426
[4c86e3d]427unsigned long get_baud_rate(void)
[df49c60]428{
429  unsigned long baud_rate;
[8f71a36]430
[80b991e9]431  while( 1 ) {
[df49c60]432    printf( "Enter the numerical value for the new baud rate.\n" );
433    printf( "Choices are: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800\n" );
[1c6926c1]434    printf( "2400, 4800, 9600, 19200, 38400, 7200, 14400, 28800, 57600, 76800\n" );
435    printf( "115200, 230400, 460800, 921600\n" );
[df49c60]436    printf( "\nYour choice: " );
437    scanf( "%lu", &baud_rate );
438    printf( "\n" );
439    switch( baud_rate ) {
440      case 50:     return B50;
441      case 75:     return B75;
442      case 110:    return B110;
443      case 134:    return B134;
444      case 150:    return B150;
445      case 200:    return B200;
446      case 300:    return B300;
447      case 600:    return B600;
448      case 1200:   return B1200;
449      case 1800:   return B1800;
450      case 2400:   return B2400;
451      case 4800:   return B4800;
452      case 9600:   return B9600;
453      case 19200:  return B19200;
454      case 38400:  return B38400;
[1c6926c1]455      case 7200:   return B7200;
456      case 14400:  return B14400;
457      case 28800:  return B28800;
[df49c60]458      case 57600:  return B57600;
[1c6926c1]459      case 76800:  return B76800;
[df49c60]460      case 115200: return B115200;
461      case 230400: return B230400;
462      case 460800: return B460800;
[1c6926c1]463      case 921600: return B921600;
[df49c60]464
465      default:
466        printf( "%lu is not a valid choice. Try again.\n\n", baud_rate );
467        break;
468    }
469  }
470}
471
472
[cbc5c46]473unsigned long get_parity(void)
[df49c60]474{
475  int parity;
[8f71a36]476
[80b991e9]477  while( 1 ) {
[df49c60]478    printf( "Enter the numerical value for the new parity\n" );
479    printf( "Choices are: 0 for no parity, 1 for even parity, 2 for odd parity\n" );
480    printf( "\nYour choice: " );
481    scanf( "%d", &parity );
482    printf( "\n" );
483    switch( parity ) {
484      case 0:
485        return 0;
486
487      case 1:
488        return PARENB;
489
490      case 2:
491        return PARENB | PARODD;
492
493      default:
494        printf( "%d is not a valid choice. Try again.\n\n", parity );
495        break;
496    }
497  }
498}
499
500
[cbc5c46]501unsigned long get_stop_bits(void)
[df49c60]502{
503  int stop_bits;
504
[80b991e9]505  while( 1 ) {
[df49c60]506    printf( "Enter the numerical value for the new number of stop bits\n" );
507    printf( "Choices are: 1 or 2\n" );
508    printf( "\nYour choice: " );
509    scanf( "%d", &stop_bits );
510    printf( "\n" );
511    switch( stop_bits ) {
512      case 1:
513        return 0;
[8f71a36]514
[df49c60]515      case 2:
516        return CSTOPB;
517
518      default:
519        printf( "%d is not a valid choice. Try again.\n\n", stop_bits );
520        break;
521    }
522  }
523}
524
525
[cbc5c46]526unsigned long get_data_bits(void)
[df49c60]527{
528  int data_bits;
529
[80b991e9]530  while( 1 ) {
[df49c60]531    printf( "Enter the numerical value for the new number of data bits\n" );
532    printf( "Choices are: 5, 6, 7 or 8\n" );
533    printf( "\nYour choice: " );
534    scanf( "%d", &data_bits );
535    printf( "\n" );
536    switch( data_bits ) {
537      case 5:
538        return CS5;
[8f71a36]539
[df49c60]540      case 6:
541        return CS6;
[8f71a36]542
[df49c60]543      case 7:
544        return CS7;
[8f71a36]545
[df49c60]546      case 8:
547        return CS8;
548
549      default:
550        printf( "%d is not a valid choice. Try again.\n\n", data_bits );
551        break;
552    }
553  }
554}
555
556
557void change_line_settings( struct termios *tp )
558{
559  unsigned long baud_rate, parity, stop_bits, data_bits, sleep_time;
[8f71a36]560
[df49c60]561  printf( "\nSetting line characteristics\n\n" );
[8f71a36]562
[df49c60]563  baud_rate = get_baud_rate();
564  parity = get_parity();
565  stop_bits = get_stop_bits();
566  data_bits = get_data_bits();
567
568  printf( "NOTE: You will not see output until you switch your terminal settings!\n" );
569  printf( "WARNING: If you do not switch your terminal settings, your terminal may hang.\n" );
570  printf( "Enter the number of seconds the test will wait for you to switch your terminal\n" );
571  printf( "settings before it continues\n" );
572  printf( "Sleep time (in seconds): " );
573  scanf( "%lu", &sleep_time );
574  printf( "\n" );
575  printf( "Setting line to new termios settings in %lu seconds.\n", sleep_time );
576
577  sleep( sleep_time );
[8f71a36]578
[1c6926c1]579  tp->c_cflag = CLOCAL | CREAD | parity | stop_bits | data_bits;
580  tp->c_ispeed = baud_rate;
581  tp->c_ospeed = baud_rate;
[df49c60]582  if( tcsetattr( fileno( stdin ), TCSADRAIN, tp ) < 0 ) {
583    perror( "change_line_settings(): tcsetattr() failed" );
[016a926]584    rtems_test_exit( 1 );
[df49c60]585  }
586  printf( "Line settings set.\n" );
587}
588
589
590void canonical_input( struct termios *tp )
591{
[80b991e9]592  char c;
593  bool first_time = true;
[8f71a36]594
[df49c60]595  printf( "\nTesting canonical input\n\n" );
596
597  printf( "Setting line to canonical input mode.\n" );
[8f71a36]598  tp->c_lflag = ISIG | ICANON | ECHO | ECHONL | ECHOK | ECHOE | ECHOPRT | ECHOCTL | IEXTEN;
[df49c60]599  tp->c_iflag = BRKINT | ICRNL | IXON | IMAXBEL;
600  if( tcsetattr( fileno( stdin ), TCSADRAIN, tp ) < 0 ) {
601    perror( "canonical_input(): tcsetattr() failed" );
[016a926]602    rtems_test_exit( 1 );
[df49c60]603  }
[8f71a36]604
[df49c60]605  while ( ( c = getchar () ) != '\n');
606  printf( "Testing getchar(). Type some text followed by carriage return\n" );
607  printf( "Each character you entered will be echoed back to you\n\n" );
608  while ( ( c = getchar () ) != '\n') {
609    if( first_time ) {
610      printf( "\nYou typed:\n");
[80b991e9]611      first_time = false;
[df49c60]612    }
613    printf( "%c", c );
614  }
615  printf( "\n\nCanonical input test done.\n" );
616}
[bfded728]617
[8ef3818]618
[514cf30]619/*
620 * Test raw (ICANON=0) input
621 */
[df49c60]622void do_raw_input( int vmin, int vtime )
623{
624  int i;
625  struct termios old, new;
626  rtems_interval ticksPerSecond, then, now;
627  unsigned int msec;
628  unsigned long count;
629  int nread;
630  unsigned char cbuf[100];
631
632  printf( "Raw input test with VMIN=%d  VTIME=%d\n", vmin, vtime );
[8f71a36]633
[1875546]634  ticksPerSecond = rtems_clock_get_ticks_per_second();
[df49c60]635  if ( tcgetattr( fileno ( stdin ), &old ) < 0 ) {
636    perror( "do_raw_input(): tcgetattr() failed" );
637    return;
638  }
[8f71a36]639
[df49c60]640  new = old;
641  new.c_lflag &= ~( ICANON | ECHO | ECHONL | ECHOK | ECHOE | ECHOPRT | ECHOCTL );
642  new.c_cc[VMIN] = vmin;
643  new.c_cc[VTIME] = vtime;
644  if( tcsetattr( fileno( stdin ), TCSADRAIN, &new ) < 0 ) {
645    perror ("do_raw_input(): tcsetattr() failed" );
646    return;
647  }
[8f71a36]648
[df49c60]649  do {
[1875546]650    then = rtems_clock_get_ticks_since_boot();
[df49c60]651    count = 0;
652    for(;;) {
653      nread = read( fileno( stdin ), cbuf, sizeof cbuf );
654      if( nread < 0 ) {
655        perror( "do_raw_input(): read() failed" );
656        goto out;
657      }
658      count++;
659      if( nread != 0 )
660        break;
661    }
[1875546]662    now = rtems_clock_get_ticks_since_boot();
[df49c60]663    msec = (now - then) * 1000 / ticksPerSecond;
664    printf( "Count:%-10lu  Interval:%3u.%3.3d  Char:",
665          count, msec / 1000, msec % 1000 );
[8f71a36]666
[df49c60]667    for( i = 0 ; i < nread ; i++ )
668      printf (" 0x%2.2x", cbuf[i]);
669    printf ("\n");
[8f71a36]670
[df49c60]671  } while( cbuf[0] != 'q' );
[8f71a36]672
[df49c60]673out:
674  if( tcsetattr( fileno( stdin ), TCSADRAIN, &old) < 0 )
675    perror("do_raw_input(): tcsetattr() failed: %s\n" );
[8f71a36]676
[f8b2eb03]677  TEST_BEGIN();
[df49c60]678}
679
680
[42e4230]681static void raw_input( struct termios *tp )
[df49c60]682{
683  printf( "\nTesting raw input input\n\n" );
684  printf( "Hit 'q' to terminate the test\n" );
685
686  do_raw_input( 0, 0 );
687  do_raw_input( 0, 20 );
688  do_raw_input( 5, 0 );
689  do_raw_input( 5, 20 );
[8f71a36]690
[df49c60]691  printf( "\nRaw input test done.\n" );
692}
693
694
695void usage( void )
696{
697  printf( "\nYou have the following choices:\n" );
698  printf( "  1 - Reset the struct termios\n" );
699  printf( "  2 - Look at the current termios setting\n" );
700  printf( "  3 - Change the line characteristics\n" );
701  printf( "  4 - Test canonical input\n" );
702  printf( "  5 - Test raw input\n" );
703  printf( "  9 - Exit\n" );
704  printf( "Enter your choice (1 to 5 or 9, followed by a carriage return): " );
[514cf30]705}
706
[11b9b5d]707static void notification( int fd, int seconds_remaining, void *arg )
708{
709  printf(
710    "Press any key to check the termios input capabilities (%is remaining)\n",
711    seconds_remaining
712  );
713}
[df49c60]714
[514cf30]715/*
716 * RTEMS Startup Task
717 */
718rtems_task
719Init (rtems_task_argument ignored)
720{
[11b9b5d]721  rtems_status_code status;
[c0ffdee]722  char c ;
[df49c60]723  struct termios orig_termios, test_termios;
[8f71a36]724
[f8b2eb03]725  TEST_BEGIN();
[11b9b5d]726
727  status = rtems_shell_wait_for_input(
728    STDIN_FILENO,
729    20,
730    notification,
731    NULL
732  );
733  if (status == RTEMS_SUCCESSFUL) {
734    if( tcgetattr( fileno( stdin ), &orig_termios ) < 0 ) {
735      perror( "tcgetattr() failed" );
736      rtems_test_exit( 0 );
737    }
[df49c60]738
[11b9b5d]739    test_termios = orig_termios;
[df49c60]740
[11b9b5d]741    usage();
742    for(;;) {
743      switch( c = getchar() ) {
744        case '1':
745          printf( "\nResetting the line to the original termios setting\n\n" );
746          test_termios = orig_termios;
747          if( tcsetattr( fileno( stdin ), TCSADRAIN, &test_termios ) < 0 ) {
748            perror( "tcsetattr() failed" );
749            rtems_test_exit( 1 );
750          }
751          usage();
752          break;
753
754        case '2':
755          print_termios( &test_termios );
756          usage();
757          break;
758
759        case '3':
760          change_line_settings( &test_termios );
761          usage();
762          break;
763
764        case '4':
765          canonical_input( &test_termios );
766          usage();
767          break;
768
769        case '5':
770          raw_input( &test_termios );
771          usage();
772          break;
773
774        case '9':
[016a926]775          rtems_test_exit( 1 );
[df49c60]776
[11b9b5d]777        case '\n':
778          break;
[df49c60]779
[11b9b5d]780        default:
781          printf( "\n%c is not a valid choice. Try again\n\n", c );
782          usage();
783          break;
784      }
[df49c60]785    }
[11b9b5d]786  } else {
[f8b2eb03]787    TEST_END();
[11b9b5d]788
789    rtems_test_exit( 0 );
[df49c60]790  }
[514cf30]791}
[4c86e3d]792
793/* application configuration */
794#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
[c4b8b147]795#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
[4c86e3d]796
797#define CONFIGURE_MAXIMUM_TASKS       1
798
[f8b2eb03]799#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
800
[4c86e3d]801#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
802
803#define CONFIGURE_MICROSECONDS_PER_TICK 1000
804
805#define CONFIGURE_INIT
806
807#include <rtems/confdefs.h>
808/* end of configuration */
809
Note: See TracBrowser for help on using the repository browser.