source: rtems/testsuites/libtests/termios01/termios_testdriver.c @ dda7c828

4.104.115
Last change on this file since dda7c828 was dda7c828, checked in by Joel Sherrill <joel.sherrill@…>, on 10/01/09 at 23:52:36

2009-10-01 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, termios01/termios_testdriver.c: Do not use CONSOLE_USE_INTERRUPTS. That is in use by BSPs and we should not use it.
  • termios02/.cvsignore, termios02/Makefile.am, termios02/init.c, termios02/termios02.doc, termios02/termios02.scn: New files. termios02 is a test for tcdrain().
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 *  This file contains a test fixture termios device driver
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include "tmacros.h"
15#include <rtems/libio.h>
16#include <stdlib.h>
17#include <assert.h>
18#include <termios.h>
19#include "termios_testdriver.h"
20
21int termios_test_driver_inbyte_nonblocking( int port )
22{
23  return -1;
24}
25
26void termios_test_driver_outbyte_polled(
27  int  port,
28  char ch
29)
30{
31}
32
33int termios_test_driver_write_support (int minor, const char *buf, int len)
34{
35  int nwrite = 0;
36
37  while (nwrite < len) {
38#if (TERMIOS_TEST_DRIVER_USE_INTERRUPTS)
39    termios_test_driver_outbyte_interrupt( minor, *buf++ );
40#else
41    termios_test_driver_outbyte_polled( minor, *buf++ );
42#endif
43    nwrite++;
44  }
45  return nwrite;
46}
47
48
49/*
50 *  Set Attributes Handler
51 */
52int termios_test_driver_set_attributes(
53  int                   minor,
54  const struct termios *t
55)
56{
57  uint32_t               ulBaudDivisor;
58  int                    baud_requested;
59  int                    number;
60  rtems_interrupt_level  Irql;
61  const char            *parity = "NONE";
62  const char            *char_size = "5";
63  const char            *stop = "NONE";
64
65  baud_requested = t->c_cflag & CBAUD;
66
67  number = rtems_termios_baud_to_number( baud_requested );
68
69  /*
70   *  Parity
71   */
72  if (t->c_cflag & PARENB) {
73    parity = "EVEN";
74    if (!(t->c_cflag & PARODD))
75      parity = "ODD";
76  }
77
78  /*
79   *  Character Size
80   */
81  if (t->c_cflag & CSIZE) {
82    switch (t->c_cflag & CSIZE) {
83      case CS5:  char_size = "5"; break;
84      case CS6:  char_size = "6"; break;
85      case CS7:  char_size = "7"; break;
86      case CS8:  char_size = "8"; break;
87    }
88  }
89
90  /*
91   *  Stop Bits
92   */
93  if (t->c_cflag & CSTOPB)
94    stop = "2";
95  else
96    stop = "1";
97
98  printf(
99    "set_attributes - B%d %s-%s-%s\n",
100    number,
101    char_size,
102    parity,
103    stop
104  );
105  return 0;
106}
107
108/*
109 *  Test Device Driver Entry Points
110 */
111rtems_device_driver termios_test_driver_initialize(
112  rtems_device_major_number  major,
113  rtems_device_minor_number  minor,
114  void                      *arg
115)
116{
117  rtems_status_code sc;
118
119  rtems_termios_initialize();
120
121  /*
122   *  Register Device Names
123   */
124  puts(
125    "Termios_test_driver - rtems_io_register "
126      TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
127  );
128  sc = rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
129  directive_failed( sc, "rtems_io_register_name" );
130
131  return RTEMS_SUCCESSFUL;
132}
133
134rtems_device_driver termios_test_driver_open(
135  rtems_device_major_number major,
136  rtems_device_minor_number minor,
137  void                    * arg
138)
139{
140  rtems_status_code sc;
141  int               rc;
142  rtems_libio_open_close_args_t *args = arg;
143  static const rtems_termios_callbacks Callbacks = {
144    NULL,                                    /* firstOpen */
145    NULL,                                    /* lastClose */
146    termios_test_driver_inbyte_nonblocking,  /* pollRead */
147    termios_test_driver_write_support,       /* write */
148    termios_test_driver_set_attributes,      /* setAttributes */
149    NULL,                                    /* stopRemoteTx */
150    NULL,                                    /* startRemoteTx */
151    0                                        /* outputUsesInterrupts */
152  };
153
154  if ( minor > 2 ) {
155    puts( "ERROR - Termios_testdriver - only 1 minor supported" );
156    rtems_test_exit(0);
157  }
158
159  sc = rtems_termios_open (major, minor, arg, &Callbacks);
160  directive_failed( sc, "rtems_termios_open" );
161
162  puts( "Termios_test_driver - rtems_set_initial_baud - bad baud - OK" );
163  rc = rtems_termios_set_initial_baud( args->iop->data1, 5000 );
164  if ( rc != -1 ) {
165    printf( "ERROR - return %d\n", rc );
166    rtems_test_exit(0);
167  }
168
169  puts( "Termios_test_driver - rtems_set_initial_baud - 38400 - OK" );
170  rc = rtems_termios_set_initial_baud( args->iop->data1, 38400 );
171  if ( rc ) {
172    printf( "ERROR - return %d\n", rc );
173    rtems_test_exit(0);
174  }
175
176  return RTEMS_SUCCESSFUL;
177}
178
179rtems_device_driver termios_test_driver_close(
180  rtems_device_major_number major,
181  rtems_device_minor_number minor,
182  void                    * arg
183)
184{
185  return rtems_termios_close (arg);
186}
187
188rtems_device_driver termios_test_driver_read(
189  rtems_device_major_number major,
190  rtems_device_minor_number minor,
191  void                    * arg
192)
193{
194  return rtems_termios_read (arg);
195}
196
197rtems_device_driver termios_test_driver_write(
198  rtems_device_major_number major,
199  rtems_device_minor_number minor,
200  void                    * arg
201)
202{
203  return rtems_termios_write (arg);
204}
205
206rtems_device_driver termios_test_driver_control(
207  rtems_device_major_number major,
208  rtems_device_minor_number minor,
209  void                    * arg
210)
211{
212  return rtems_termios_ioctl (arg);
213}
Note: See TracBrowser for help on using the repository browser.