source: rtems/testsuites/libtests/termios04/termios_testdriver_intr.c @ 028aa06

4.115
Last change on this file since 028aa06 was 028aa06, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/10 at 14:35:54

2010-07-01 Joel Sherrill <joel.sherrill@…>

  • termios04/termios_testdriver_intr.c: Task driven IO now works.
  • Property mode set to 100644
File size: 5.5 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.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 <rtems/dumpbuf.h>
20#include "termios_testdriver_intr.h"
21
22rtems_id Rx_Timer;
23rtems_id Tx_Timer;
24
25#define TX_MAX 1024
26uint8_t                   Tx_Buffer[TX_MAX];
27int                       Tx_Index = 0;
28struct rtems_termios_tty *Ttyp;
29
30void termios_test_driver_wait_for_tx_to_complete(void)
31{
32  rtems_task_wake_after( 2 * rtems_clock_get_ticks_per_second() );
33}
34
35void termios_test_driver_dump_tx(const char *c)
36{
37  termios_test_driver_wait_for_tx_to_complete();
38
39  printf( "%s %d characters\n", c, Tx_Index );
40  rtems_print_buffer( Tx_Buffer, Tx_Index );
41  Tx_Index = 0;
42}
43 
44const uint8_t *Rx_Buffer;
45int            Rx_Index = 0;
46int            Rx_Length = 0;
47bool           Rx_FirstTime = true;
48bool           Rx_EnqueueNow = false;
49
50#if defined(TASK_DRIVEN)
51  int termios_test_driver_inbyte_nonblocking( int port )
52  {
53    if ( Rx_FirstTime == true ) {
54      Rx_FirstTime = false;
55      return -1;
56    }
57    if ( Rx_Index >= Rx_Length )
58      return -1;
59    return Rx_Buffer[ Rx_Index++ ];
60  }
61#endif
62
63rtems_timer_service_routine Rx_ISR(
64  rtems_id  ignored_id,
65  void     *ignored_address
66)
67{
68  uint8_t ch;
69
70  if ( Rx_Index >= Rx_Length )
71    return;
72
73  ch = Rx_Buffer[ Rx_Index++ ];
74  rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1);
75  #if defined(TASK_DRIVEN)
76    rtems_termios_rxirq_occured(Ttyp);
77  #endif
78
79  (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL );
80}
81
82rtems_timer_service_routine Tx_ISR(
83  rtems_id  ignored_id,
84  void     *ignored_address
85)
86{
87  rtems_termios_dequeue_characters (Ttyp, 1);
88
89  (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL );
90}
91
92void termios_test_driver_set_rx_enqueue_now(
93  bool value
94)
95{
96  Rx_EnqueueNow = value;
97}
98
99void termios_test_driver_set_rx(
100  const void *p,
101  size_t      len
102)
103{
104  Rx_Buffer = p;
105  Rx_Length = len;
106  Rx_Index  = 0;
107
108  if ( Rx_EnqueueNow == false) {
109    (void) rtems_timer_fire_after( Rx_Timer, 10, Rx_ISR, NULL );
110    return;
111  }
112
113  do {
114    uint8_t ch;
115    ch = Rx_Buffer[ Rx_Index++ ];
116    rtems_termios_enqueue_raw_characters (Ttyp, (char *)&ch, 1);
117  } while (Rx_Index < Rx_Length );
118}
119
120ssize_t termios_test_driver_write_helper(
121  int         port,
122  const char *buf,
123  size_t      len
124)
125{
126  Tx_Buffer[Tx_Index++] = buf[0];
127  (void) rtems_timer_fire_after( Tx_Timer, 10, Tx_ISR, NULL );
128  return 1;
129}
130
131/*
132 *  Set Attributes Handler
133 */
134int termios_test_driver_set_attributes(
135  int                   minor,
136  const struct termios *t
137)
138{
139  return 0;
140}
141
142/*
143 *  Test Device Driver Entry Points
144 */
145rtems_device_driver termios_test_driver_initialize(
146  rtems_device_major_number  major,
147  rtems_device_minor_number  minor,
148  void                      *arg
149)
150{
151  rtems_status_code status;
152
153  rtems_termios_initialize();
154
155  /*
156   *  Register Device Names
157   */
158  (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 );
159
160  status = rtems_timer_create(rtems_build_name('T', 'M', 'R', 'X'), &Rx_Timer);
161  if ( status )
162    rtems_fatal_error_occurred(1);;
163
164  status = rtems_timer_create(rtems_build_name('T', 'M', 'T', 'X'), &Tx_Timer);
165  if ( status )
166    rtems_fatal_error_occurred(1);;
167
168  return RTEMS_SUCCESSFUL;
169}
170
171rtems_device_driver termios_test_driver_open(
172  rtems_device_major_number major,
173  rtems_device_minor_number minor,
174  void                    * arg
175)
176{
177  rtems_status_code sc;
178  rtems_libio_open_close_args_t *args = arg;
179  static const rtems_termios_callbacks Callbacks = {
180    NULL,                                    /* firstOpen */
181    NULL,                                    /* lastClose */
182    #if defined(TASK_DRIVEN)
183      termios_test_driver_inbyte_nonblocking,/* pollRead */
184    #else
185      NULL,                                  /* pollRead */
186    #endif
187    termios_test_driver_write_helper,        /* write */
188    termios_test_driver_set_attributes,      /* setAttributes */
189    NULL,                                    /* stopRemoteTx */
190    NULL,                                    /* startRemoteTx */
191    #if defined(TASK_DRIVEN)
192      TERMIOS_TASK_DRIVEN                    /* outputUsesInterrupts */
193    #else
194      0                                      /* outputUsesInterrupts */
195    #endif
196  };
197
198  if ( minor > 2 ) {
199    puts( "ERROR - Termios_testdriver - only 1 minor supported" );
200    rtems_test_exit(0);
201  }
202
203  sc = rtems_termios_open (major, minor, arg, &Callbacks);
204
205  Ttyp = args->iop->data1;   /* Keep cookie returned by termios_open */
206
207  return RTEMS_SUCCESSFUL;
208}
209
210rtems_device_driver termios_test_driver_close(
211  rtems_device_major_number major,
212  rtems_device_minor_number minor,
213  void                    * arg
214)
215{
216  return rtems_termios_close (arg);
217}
218
219rtems_device_driver termios_test_driver_read(
220  rtems_device_major_number major,
221  rtems_device_minor_number minor,
222  void                    * arg
223)
224{
225  return rtems_termios_read (arg);
226}
227
228rtems_device_driver termios_test_driver_write(
229  rtems_device_major_number major,
230  rtems_device_minor_number minor,
231  void                    * arg
232)
233{
234  return rtems_termios_write (arg);
235}
236
237rtems_device_driver termios_test_driver_control(
238  rtems_device_major_number major,
239  rtems_device_minor_number minor,
240  void                    * arg
241)
242{
243  return rtems_termios_ioctl (arg);
244}
Note: See TracBrowser for help on using the repository browser.