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

4.104.114.84.95
Last change on this file since bfded728 was bfded728, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/00 at 14:16:00

Fixed warnings.

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[514cf30]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
[6f9c75c3]14 *
15 *  $Id$
[514cf30]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
[bfded728]44int fileno( FILE *stream); /* beyond ANSI */
45
[514cf30]46/*
47 * Test raw (ICANON=0) input
48 */
49static void
50testRawInput (int vmin, int vtime)
51{
52        int i;
53        struct termios old, new;
54        rtems_interval ticksPerSecond, then, now;
55        unsigned int msec;
56        unsigned long count;
57        int nread;
58        unsigned char cbuf[100];
59
60        printf ("*** Raw input  VMIN=%d  VTIME=%d ***\n", vmin, vtime);
61        rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
62        i = tcgetattr (fileno (stdin), &old);
63        if (i < 0) {
64                printf ("tcgetattr failed: %s\n", strerror (errno));
65                return;
66        }
67        new = old;
68        new.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
69        new.c_cc[VMIN] = vmin;
70        new.c_cc[VTIME] = vtime;
71        i = tcsetattr (fileno (stdin), TCSANOW, &new);
72        if (i < 0) {
73                printf ("tcsetattr failed: %s\n", strerror (errno));
74                return;
75        }
76        do {
77                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
78                count = 0;
79                for (;;) {
80                        nread = read (fileno (stdin), cbuf, sizeof cbuf);
81                        if (nread < 0) {
82                                printf ("Read error: %s\n", strerror (errno));
83                                goto out;
84                        }
85                        count++;
86                        if (nread != 0)
87                                break;
88                }
89                rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
90                msec = (now - then) * 1000 / ticksPerSecond;
91                printf ("Count:%-10lu  Interval:%3u.%3.3d  Char:",
92                                        count, msec / 1000, msec % 1000);
93                for (i = 0 ; i < nread ; i++)
94                        printf (" %2.2x", cbuf[i]);
95                printf ("\n");
96        } while (cbuf[0] != 'q');
97    out:
98        i = tcsetattr (fileno (stdin), TCSANOW, &old);
99        if (i < 0)
100                printf ("tcsetattr failed: %s\n", strerror (errno));
101        printf ("*** End of Raw input  VMIN=%d  VTIME=%d ***\n", vmin, vtime);
102}
103
104/*
105 * RTEMS Startup Task
106 */
107rtems_task
108Init (rtems_task_argument ignored)
109{
110        int i, j;
111
112        printf( "\n\n*** HELLO WORLD TEST ***\n" );
113        printf( "Hello World\n" );
114        printf( "*** END OF HELLO WORLD TEST ***\n" );
115
116        printf( "\n\ntype 'q' to exit raw input tests\n\n" );
117
118        for (;;) {
119                /*
120                 * Test  blocking, line-oriented input
121                 */
122                do {
123                        printf (">>> ");
124                        fflush (stdout);
125                        i = scanf (" %d", &j);
126                        printf ("Return: %d Value: %d\n", i, j);
127                } while (i != 0);
128
129                /*
130                 * Consume what scanf rejected
131                 */
132                while ((i = getchar ()) != '\n')
133                        if (i == EOF)
134                                break;
135
136                /*
137                 * Test character-oriented input
138                 */
139                testRawInput (0, 0);
140                testRawInput (0, 20);
141                testRawInput (5, 0);
142                testRawInput (5, 20);
143        }
144        exit (1);
145}
Note: See TracBrowser for help on using the repository browser.