source: rtems/testsuites/libtests/termios/init.c @ 6f9c75c3

4.104.114.84.95
Last change on this file since 6f9c75c3 was 6f9c75c3, checked in by Joel Sherrill <joel.sherrill@…>, on 01/16/98 at 16:56:48

Ralf Corsepius reported a number of missing CVS Id's:

RTEMS is under CVS control and has been since rtems 3.1.16 which was
around May 1995. So I just to add the $Id$. If you notice other files
with missing $Id$'s let me know. I try to keep w\up with it.

Now that you have asked -- I'll attach a list of files lacking an RCS-Id to
this mail. This list has been generated by a little sh-script I'll also
enclose.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * RTEMS configuration/initialization
3 *
4 * This program may be distributed and used for any purpose.
5 * I ask only that you:
6 *      1. Leave this author information intact.
7 *      2. Document any changes you make.
8 *
9 * W. Eric Norum
10 * Saskatchewan Accelerator Laboratory
11 * University of Saskatchewan
12 * Saskatoon, Saskatchewan, CANADA
13 * eric@skatter.usask.ca
14 *
15 *  $Id$
16 */
17
18#include <bsp.h>
19
20#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
21#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
22
23#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
24
25#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
26
27#define CONFIGURE_MAXIMUM_SEMAPHORES            20
28#define CONFIGURE_MAXIMUM_TIMERS                5
29#define CONFIGURE_MAXIMUM_PERIODS               1
30
31#define CONFIGURE_MICROSECONDS_PER_TICK         1000
32
33#define CONFIGURE_INIT
34rtems_task Init (rtems_task_argument argument);
35
36#include <confdefs.h>
37
38#include <stdio.h>
39#include <unistd.h>
40#include <termios.h>
41#include <errno.h>
42#include <string.h>
43
44/*
45 * Test raw (ICANON=0) input
46 */
47static void
48testRawInput (int vmin, int vtime)
49{
50        int i;
51        struct termios old, new;
52        rtems_interval ticksPerSecond, then, now;
53        unsigned int msec;
54        unsigned long count;
55        int nread;
56        unsigned char cbuf[100];
57
58        printf ("*** Raw input  VMIN=%d  VTIME=%d ***\n", vmin, vtime);
59        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
60        i = tcgetattr (fileno (stdin), &old);
61        if (i < 0) {
62                printf ("tcgetattr failed: %s\n", strerror (errno));
63                return;
64        }
65        new = old;
66        new.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
67        new.c_cc[VMIN] = vmin;
68        new.c_cc[VTIME] = vtime;
69        i = tcsetattr (fileno (stdin), TCSANOW, &new);
70        if (i < 0) {
71                printf ("tcsetattr failed: %s\n", strerror (errno));
72                return;
73        }
74        do {
75                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
76                count = 0;
77                for (;;) {
78                        nread = read (fileno (stdin), cbuf, sizeof cbuf);
79                        if (nread < 0) {
80                                printf ("Read error: %s\n", strerror (errno));
81                                goto out;
82                        }
83                        count++;
84                        if (nread != 0)
85                                break;
86                }
87                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
88                msec = (now - then) * 1000 / ticksPerSecond;
89                printf ("Count:%-10lu  Interval:%3u.%3.3d  Char:",
90                                        count, msec / 1000, msec % 1000);
91                for (i = 0 ; i < nread ; i++)
92                        printf (" %2.2x", cbuf[i]);
93                printf ("\n");
94        } while (cbuf[0] != 'q');
95    out:
96        i = tcsetattr (fileno (stdin), TCSANOW, &old);
97        if (i < 0)
98                printf ("tcsetattr failed: %s\n", strerror (errno));
99        printf ("*** End of Raw input  VMIN=%d  VTIME=%d ***\n", vmin, vtime);
100}
101
102/*
103 * RTEMS Startup Task
104 */
105rtems_task
106Init (rtems_task_argument ignored)
107{
108        int i, j;
109
110        printf( "\n\n*** HELLO WORLD TEST ***\n" );
111        printf( "Hello World\n" );
112        printf( "*** END OF HELLO WORLD TEST ***\n" );
113
114        printf( "\n\ntype 'q' to exit raw input tests\n\n" );
115
116        for (;;) {
117                /*
118                 * Test  blocking, line-oriented input
119                 */
120                do {
121                        printf (">>> ");
122                        fflush (stdout);
123                        i = scanf (" %d", &j);
124                        printf ("Return: %d Value: %d\n", i, j);
125                } while (i != 0);
126
127                /*
128                 * Consume what scanf rejected
129                 */
130                while ((i = getchar ()) != '\n')
131                        if (i == EOF)
132                                break;
133
134                /*
135                 * Test character-oriented input
136                 */
137                testRawInput (0, 0);
138                testRawInput (0, 20);
139                testRawInput (5, 0);
140                testRawInput (5, 20);
141        }
142        exit (1);
143}
Note: See TracBrowser for help on using the repository browser.