source: rtems/testsuites/libtests/termios05/termios_testdriver_taskdriven.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  This file contains a test fixture termios device driver
3 *
4 *  COPYRIGHT (c) 1989-2010.
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.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include "tmacros.h"
17#include <rtems/libio.h>
18#include <stdlib.h>
19#include <termios.h>
20#include <rtems/termiostypes.h>
21#include <rtems/dumpbuf.h>
22#include "termios_testdriver_taskdriven.h"
23
24#define TX_MAX 1024
25uint8_t Tx_Buffer[TX_MAX];
26int     Tx_Index = 0;
27
28void termios_test_driver_dump_tx(const char *c)
29{
30  printf( "%s %d characters\n", c, Tx_Index );
31  rtems_print_buffer( Tx_Buffer, Tx_Index );
32  Tx_Index = 0;
33}
34 
35const uint8_t *Rx_Buffer;
36int            Rx_Index;
37int            Rx_Length;
38bool           Rx_FirstTime = true;
39
40void termios_test_driver_set_rx(
41  const void *p,
42  size_t      len
43)
44{
45  Rx_Buffer = p;
46  Rx_Length = len;
47  Rx_Index  = 0;
48}
49
50int termios_test_driver_inbyte_nonblocking( int port )
51{
52  if ( Rx_FirstTime == true ) {
53    Rx_FirstTime = false;
54    return -1;
55  }
56  if ( Rx_Index >= Rx_Length )
57    return -1;
58  return Rx_Buffer[ Rx_Index++ ];
59}
60
61void termios_test_driver_outbyte_polled(
62  int  port,
63  char ch
64)
65{
66  Tx_Buffer[Tx_Index++] = (uint8_t) ch;
67}
68
69ssize_t termios_test_driver_write_support (int minor, const char *buf, size_t len)
70{
71  size_t nwrite = 0;
72
73  while (nwrite < len) {
74    termios_test_driver_outbyte_polled( minor, *buf++ );
75    nwrite++;
76  }
77  return nwrite;
78}
79
80
81/*
82 *  Set Attributes Handler
83 */
84int termios_test_driver_set_attributes(
85  int                   minor,
86  const struct termios *t
87)
88{
89  return 0;
90}
91
92/*
93 *  Test Device Driver Entry Points
94 */
95rtems_device_driver termios_test_driver_initialize(
96  rtems_device_major_number  major,
97  rtems_device_minor_number  minor,
98  void                      *arg
99)
100{
101  rtems_termios_initialize();
102
103  /*
104   *  Register Device Names
105   */
106  (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
107
108  return RTEMS_SUCCESSFUL;
109}
110
111rtems_device_driver termios_test_driver_open(
112  rtems_device_major_number major,
113  rtems_device_minor_number minor,
114  void                    * arg
115)
116{
117  rtems_status_code sc;
118  static const rtems_termios_callbacks Callbacks = {
119    NULL,                                    /* firstOpen */
120    NULL,                                    /* lastClose */
121    termios_test_driver_inbyte_nonblocking,  /* pollRead */
122    termios_test_driver_write_support,       /* write */
123    termios_test_driver_set_attributes,      /* setAttributes */
124    NULL,                                    /* stopRemoteTx */
125    NULL,                                    /* startRemoteTx */
126    TERMIOS_TASK_DRIVEN                      /* outputUsesInterrupts */
127  };
128
129  if ( minor > 2 ) {
130    puts( "ERROR - Termios_testdriver - only 1 minor supported" );
131    rtems_test_exit(0);
132  }
133
134  sc = rtems_termios_open (major, minor, arg, &Callbacks);
135
136  return RTEMS_SUCCESSFUL;
137}
138
139rtems_device_driver termios_test_driver_close(
140  rtems_device_major_number major,
141  rtems_device_minor_number minor,
142  void                    * arg
143)
144{
145  return rtems_termios_close (arg);
146}
147
148rtems_device_driver termios_test_driver_read(
149  rtems_device_major_number major,
150  rtems_device_minor_number minor,
151  void                    * arg
152)
153{
154  return rtems_termios_read (arg);
155}
156
157rtems_device_driver termios_test_driver_write(
158  rtems_device_major_number major,
159  rtems_device_minor_number minor,
160  void                    * arg
161)
162{
163  return rtems_termios_write (arg);
164}
165
166rtems_device_driver termios_test_driver_control(
167  rtems_device_major_number major,
168  rtems_device_minor_number minor,
169  void                    * arg
170)
171{
172  return rtems_termios_ioctl (arg);
173}
Note: See TracBrowser for help on using the repository browser.