source: rtems/testsuites/libtests/termios01/termios_testdriver.c @ 78da8ac3

4.115
Last change on this file since 78da8ac3 was ea9a626, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/10/09 at 14:26:32

Reflect changes to rtems_termios_callbacks->write.

  • Property mode set to 100644
File size: 4.7 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 <termios.h>
18#include <rtems/termiostypes.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
33ssize_t termios_test_driver_write_support (int minor, const char *buf, size_t len)
34{
35  size_t 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  int                    baud_requested;
58  int                    number;
59  const char            *parity = "NONE";
60  const char            *char_size = "5";
61  const char            *stop = "NONE";
62
63  baud_requested = t->c_cflag & CBAUD;
64
65  number = rtems_termios_baud_to_number( baud_requested );
66
67  /*
68   *  Parity
69   */
70  if (t->c_cflag & PARENB) {
71    parity = "EVEN";
72    if (!(t->c_cflag & PARODD))
73      parity = "ODD";
74  }
75
76  /*
77   *  Character Size
78   */
79  if (t->c_cflag & CSIZE) {
80    switch (t->c_cflag & CSIZE) {
81      case CS5:  char_size = "5"; break;
82      case CS6:  char_size = "6"; break;
83      case CS7:  char_size = "7"; break;
84      case CS8:  char_size = "8"; break;
85    }
86  }
87
88  /*
89   *  Stop Bits
90   */
91  if (t->c_cflag & CSTOPB)
92    stop = "2";
93  else
94    stop = "1";
95
96  printf(
97    "set_attributes - B%d %s-%s-%s\n",
98    number,
99    char_size,
100    parity,
101    stop
102  );
103  return 0;
104}
105
106/*
107 *  Test Device Driver Entry Points
108 */
109rtems_device_driver termios_test_driver_initialize(
110  rtems_device_major_number  major,
111  rtems_device_minor_number  minor,
112  void                      *arg
113)
114{
115  rtems_status_code sc;
116
117  rtems_termios_initialize();
118
119  /*
120   *  Register Device Names
121   */
122  puts(
123    "Termios_test_driver - rtems_io_register "
124      TERMIOS_TEST_DRIVER_DEVICE_NAME " - OK"
125  );
126  sc = rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
127  directive_failed( sc, "rtems_io_register_name" );
128
129  return RTEMS_SUCCESSFUL;
130}
131
132rtems_device_driver termios_test_driver_open(
133  rtems_device_major_number major,
134  rtems_device_minor_number minor,
135  void                    * arg
136)
137{
138  rtems_status_code sc;
139  int               rc;
140  rtems_libio_open_close_args_t *args = arg;
141  static const rtems_termios_callbacks Callbacks = {
142    NULL,                                    /* firstOpen */
143    NULL,                                    /* lastClose */
144    termios_test_driver_inbyte_nonblocking,  /* pollRead */
145    termios_test_driver_write_support,       /* write */
146    termios_test_driver_set_attributes,      /* setAttributes */
147    NULL,                                    /* stopRemoteTx */
148    NULL,                                    /* startRemoteTx */
149    0                                        /* outputUsesInterrupts */
150  };
151
152  if ( minor > 2 ) {
153    puts( "ERROR - Termios_testdriver - only 1 minor supported" );
154    rtems_test_exit(0);
155  }
156
157  sc = rtems_termios_open (major, minor, arg, &Callbacks);
158  directive_failed( sc, "rtems_termios_open" );
159
160  puts( "Termios_test_driver - rtems_set_initial_baud - bad baud - OK" );
161  rc = rtems_termios_set_initial_baud( args->iop->data1, 5000 );
162  if ( rc != -1 ) {
163    printf( "ERROR - return %d\n", rc );
164    rtems_test_exit(0);
165  }
166
167  puts( "Termios_test_driver - rtems_set_initial_baud - 38400 - OK" );
168  rc = rtems_termios_set_initial_baud( args->iop->data1, 38400 );
169  if ( rc ) {
170    printf( "ERROR - return %d\n", rc );
171    rtems_test_exit(0);
172  }
173
174  return RTEMS_SUCCESSFUL;
175}
176
177rtems_device_driver termios_test_driver_close(
178  rtems_device_major_number major,
179  rtems_device_minor_number minor,
180  void                    * arg
181)
182{
183  return rtems_termios_close (arg);
184}
185
186rtems_device_driver termios_test_driver_read(
187  rtems_device_major_number major,
188  rtems_device_minor_number minor,
189  void                    * arg
190)
191{
192  return rtems_termios_read (arg);
193}
194
195rtems_device_driver termios_test_driver_write(
196  rtems_device_major_number major,
197  rtems_device_minor_number minor,
198  void                    * arg
199)
200{
201  return rtems_termios_write (arg);
202}
203
204rtems_device_driver termios_test_driver_control(
205  rtems_device_major_number major,
206  rtems_device_minor_number minor,
207  void                    * arg
208)
209{
210  return rtems_termios_ioctl (arg);
211}
Note: See TracBrowser for help on using the repository browser.