source: rtems/c/src/lib/libbsp/powerpc/dmv177/console/console.c @ 9c559acc

4.104.114.84.95
Last change on this file since 9c559acc was c932d85, checked in by Joel Sherrill <joel.sherrill@…>, on 05/30/98 at 10:09:14

New files -- from rtems-LM-980406 which was based on an RTEMS from 12/97.
This was called the dmv170 BSP in that source tree but since the DMV171
is now obsolete, we have transitioned to the DMV177 and have no intention
of checking compatibility with any other models.

  • Property mode set to 100644
File size: 9.8 KB
Line 
1/*
2 *  console.c
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  Currently only polled mode is supported.
7 *
8 *  COPYRIGHT (c) 1989-1998.
9 *  On-Line Applications Research Corporation (OAR).
10 *  Copyright assigned to U.S. Government, 1994.
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id: console.c
17 */
18
19#include <stdlib.h>
20#include <motorola/mc68681.h>
21#include <bsp.h>
22#include <rtems/libio.h>
23#include <assert.h>
24
25#define COM1                      0
26#define COM2                      1
27#define NUM_PORTS                 2
28#define USE_FOR_CONSOLE           COM1
29
30/*
31 *  Define RDB_BREAK_IN if you need to be able to break in to the
32 *  program with a ctrl-c during remote target debugging. If so,
33 *  UART B will not be accessible from rtems during remote debugging
34 *  if interrupt driven console is used. Does not affect UART A, polled
35 *  mode or when the program runs without remote debugging.
36 */
37#define RDB_BREAK_IN
38
39/* Proto-types for Duart.C */
40void console_initialize_interrupts( void );
41char console_inbyte_polled( int port );
42void console_outbyte_polled(int  port, char ch);
43rtems_isr console_isr (rtems_vector_number vector);
44volatile void init_mc88681();
45
46/*  PAGE
47 *
48 *  console_initialize
49 *
50 *  This routine initializes the console IO driver.
51 *
52 *  Input parameters:
53 *    major - console device major number
54 *    minor - console device minor number
55 *    arg   - pointer to optional device driver arguments
56 *
57 *  Output parameters:  NONE
58 *
59 *  Return values:
60 *    rtems_device_driver status code
61 */
62 
63rtems_device_driver console_initialize(
64  rtems_device_major_number  major,
65  rtems_device_minor_number  minor,
66  void                      *arg
67)
68{
69  rtems_status_code status;
70  int               console;
71
72  /*
73   * initialize the termio interface.
74   */
75  rtems_termios_initialize();
76
77  /*
78   *  Register Device Names
79   */
80  console = USE_FOR_CONSOLE;
81  status = rtems_io_register_name( "/dev/console", major, console );
82  if (status != RTEMS_SUCCESSFUL)
83    rtems_fatal_error_occurred(status);
84
85  /*
86   *  Initialize Hardware
87   */
88
89  init_mc88681 ();
90
91#if CONSOLE_USE_INTERRUPTS
92  console_initialize_interrupts();
93#endif
94 
95  return RTEMS_SUCCESSFUL;
96}
97
98/* PAGE
99 *
100 *  console_write_support
101 *
102 *  This routine is Console Termios output entry point.
103 *
104 *  Input parameters:
105 *    minor - console device minor number
106 *    buf   - buffer of data to be written
107 *    len   - length of data to be written
108 *
109 *  Output parameters:  NONE
110 *
111 *  Return values:
112 *    int     number of bytes written
113 */
114
115int console_write_support(
116  int         minor,
117  const char *buf,
118  int         len)
119{
120  int                       nwrite = 0;
121  int                       port = minor;
122
123  /*
124   * verify port Number
125   */
126  assert ( port < NUM_PORTS );
127
128  /*
129   * poll each byte in the string out of the port.
130   */
131  while (nwrite < len) {
132#if defined(CONSOLE_USE_INTERRUPTS)
133#else
134    console_outbyte_polled(port, *buf++);
135#endif
136   nwrite++;
137  }
138
139  /*
140   * return the number of bytes written.
141   */
142  return nwrite;
143}
144
145
146/*  PAGE
147 *
148 *  DEBUG_puts
149 *
150 *  This should be safe in the event of an error.  It attempts to insure
151 *  that no TX empty interrupts occur while it is doing polled IO.  Then
152 *  it restores the state of that external interrupt.
153 *
154 *  Input parameters:
155 *    string  - pointer to debug output string
156 *
157 *  Output parameters:  NONE
158 *
159 *  Return values:      NONE
160 */
161
162void DEBUG_puts(
163  char *string
164)
165{
166  char *s;
167  rtems_unsigned32    isrlevel;
168
169  rtems_interrupt_disable( isrlevel );
170  for ( s = string ; *s ; s++ )
171    console_outbyte_polled( 0, *s );
172
173  console_outbyte_polled( 0, '\r' );
174  console_outbyte_polled( 0, '\n' );
175  rtems_interrupt_enable( isrlevel );
176}
177
178
179/* PAGE
180 *
181 *  console_open
182 *
183 *  This routine is the console device driver open entry point.
184 *
185 *  Input parameters:
186 *    major - console device major number
187 *    minor - console device minor number
188 *    arg   - pointer to optional device driver arguments
189 *
190 *  Output parameters:  NONE
191 *
192 *  Return values:
193 *    rtems_device_driver status code
194 */
195 
196rtems_device_driver console_open(
197  rtems_device_major_number major,
198  rtems_device_minor_number minor,
199  void                    * arg
200)
201{
202  rtems_status_code sc;
203  int               port = minor;
204#if defined(CONSOLE_USE_INTERRUPTS)
205  rtems_libio_open_close_args_t *args = arg;
206#endif
207
208  /*
209   * Verify the minor number is valid.
210   */
211  if (minor < 0)
212    return RTEMS_INVALID_NUMBER;
213
214  if ( port > NUM_PORTS )
215     return RTEMS_INVALID_NUMBER;
216
217  /*
218   *  open the port as a termios console driver.
219   */
220#if defined(CONSOLE_USE_INTERRUPTS)
221   sc = rtems_termios_open (major, minor, arg,
222                            NULL, NULL, NULL,
223                            console_write_support, 0);
224#else
225   sc = rtems_termios_open (major, minor, arg, NULL, NULL,
226                            console_inbyte_nonblocking,
227                            console_write_support,
228                            0);
229#endif
230
231  return sc;
232}
233 
234 
235
236/* PAGE
237 *
238 *  console_reserve_resources
239 *
240 *  This routine reserves resources for each port which may be
241 *  used as a console.
242 *
243 *  Input parameters:
244 *    configuration  - rtems configuration table.
245 *
246 *  Output parameters: NONE
247 *
248 *  Return values: NONE
249 */
250
251void console_reserve_resources(
252  rtems_configuration_table *configuration
253)
254{
255  rtems_termios_reserve_resources( configuration, NUM_PORTS );
256}
257
258/* PAGE
259 *
260 *  console_close
261 *
262 *  This routine is the console device driver close entry point.
263 *
264 *  Input parameters:
265 *    major - console device major number
266 *    minor - console device minor number
267 *    arg   - pointer to optional device driver arguments
268 *
269 *  Output parameters:  NONE
270 *
271 *  Return values:
272 *    rtems_device_driver status code
273 */
274 
275rtems_device_driver console_close(
276  rtems_device_major_number major,
277  rtems_device_minor_number minor,
278  void                    * arg
279)
280{
281  return rtems_termios_close (arg);
282}
283 
284/* PAGE
285 *
286 *  console_read
287 *
288 *  This routine is the console device driver read entry point.
289 *
290 *  Input parameters:
291 *    major - console device major number
292 *    minor - console device minor number
293 *    arg   - pointer to optional device driver arguments
294 *
295 *  Output parameters:  NONE
296 *
297 *  Return values:
298 *    rtems_device_driver status code
299 *
300 */
301 rtems_device_driver console_read(
302  rtems_device_major_number major,
303  rtems_device_minor_number minor,
304  void                    * arg
305)
306{
307  return rtems_termios_read (arg);
308}
309 
310/* PAGE
311 *
312 *  console_write
313 *
314 *  This routine is the console device driver write entry point.
315 *
316 *  Input parameters:
317 *    major - console device major number
318 *    minor - console device minor number
319 *    arg   - pointer to optional device driver arguments
320 *
321 *  Output parameters:  NONE
322 *
323 *  Return values:
324 *    rtems_device_driver status code
325 *
326 */
327rtems_device_driver console_write(
328  rtems_device_major_number major,
329  rtems_device_minor_number minor,
330  void                    * arg
331)
332{
333  return rtems_termios_write (arg);
334}
335 
336/* PAGE
337 *
338 *  console_control
339 *
340 *  This routine is console device driver control entry point
341 *
342 *  Input parameters:
343 *    major - console device major number
344 *    minor - console device minor number
345 *    arg   - pointer to optional device driver arguments
346 *
347 *  Output parameters:  NONE
348 *
349 *  Return values:
350 *    rtems_device_driver status code
351 *
352 */
353rtems_device_driver console_control(
354  rtems_device_major_number major,
355  rtems_device_minor_number minor,
356  void                    * arg
357)
358{
359  return rtems_termios_ioctl (arg);
360}
361
362
363/*
364 *  Interrupt driven console IO
365 */
366
367#if CONSOLE_USE_INTERRUPTS
368
369/*
370 *  Buffers between task and ISRs
371 */
372
373#include <ringbuf.h>
374extern Ring_buffer_t TX_Buffer[2];
375extern Ring_buffer_t RX_Buffer[2];
376
377/*
378 *  console_inbyte_interrupts
379 *
380 *  This routine reads a character from the UART.
381 *
382 *  Input parameters: NONE
383 *
384 *  Output parameters:  NONE
385 *
386 *  Return values:
387 *    character read from UART
388 */
389 
390char console_inbyte_interrupts( int port )
391{
392  char ch;
393
394  while ( Ring_buffer_Is_empty( &RX_Buffer[ port ] ) );
395 
396  Ring_buffer_Remove_character( &RX_Buffer[ port ], ch );
397  return ch;
398}
399 
400/*
401 *  console_outbyte_interrupts
402 *
403 *  This routine transmits a character out.
404 *
405 *  Input parameters:
406 *    port - port to transmit character to
407 *    ch  - character to be transmitted
408 *
409 *  Output parameters:  NONE
410 *
411 *  Return values:      NONE
412 */
413 
414void console_outbyte_interrupts(
415  int  port,
416  char ch
417)
418{
419  /*
420   *  If this is the first character then we need to prime the pump
421   */
422
423  if ( Is_TX_active[ port ] == FALSE ) {
424    Is_TX_active[ port ] = TRUE;
425    console_outbyte_polled( port, ch );
426    return;
427  }
428
429  while ( Ring_buffer_Is_full( &TX_Buffer[ port ] ) );
430 
431  Ring_buffer_Add_character( &TX_Buffer[ port ], ch );
432}
433
434/*
435 *  console_exit
436 *
437 *  This routine allows the console to exit by masking its associated interrupt
438 *  vectors.
439 *
440 *  Input parameters:  NONE
441 *
442 *  Output parameters: NONE
443 *
444 *  Return values:     NONE
445 */
446
447void console_exit()
448{
449  volatile unsigned char *_addr;
450  int port;
451
452  /*
453   *  Although the interrupts for the UART are unmasked, the PIL is set to
454   *  disable all external interrupts.  So we might as well do this first.
455   */
456
457  /* ??? Mask All UART Interrupts           */
458
459  for (port = MC68681_PORT_A; port <= MC68681_PORT_B; port++) {
460    while (!Ring_buffer_Is_empty (&TX_Buffer[port])) {
461      Ring_buffer_Remove_character (&TX_Buffer[port],ch);
462      console_outbyte_polled (port,ch);
463    }
464  }
465
466  /*
467   *  Now wait for all the data to actually get out ... the send register
468   *  should be empty.
469   */
470   _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_A);
471   while (!(*_addr & MC68681_TX_EMPTY));
472
473  _addr = (unsigned char *) (DUART_ADDR + MC68681_STATUS_REG_B);
474   while (!(*_addr & MC68681_TX_EMPTY));
475}
476#endif /* CONSOLE_USE_INTERRUPTS */
477
478
479
Note: See TracBrowser for help on using the repository browser.