source: rtems/c/src/tests/libtests/termios/init.c @ 514cf30

4.104.114.84.95
Last change on this file since 514cf30 was 514cf30, checked in by Joel Sherrill <joel.sherrill@…>, on 10/23/97 at 15:12:46

Added new test for termios style consoles from Eric Norum.

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