source: rtems/c/src/lib/libbsp/m68k/mvme162/console/console.c @ 5072b07

4.104.114.84.95
Last change on this file since 5072b07 was c6fb8e90, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/95 at 15:33:39

updated mvme162 code from Misha (mms@…)

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  This file contains the MVME162 console IO package.
3 *
4 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
5 *  On-Line Applications Research Corporation (OAR).
6 *  All rights assigned to U.S. Government, 1994.
7 *
8 *  This material may be reproduced by or for the U.S. Government pursuant
9 *  to the copyright license under the clause at DFARS 252.227-7013.  This
10 *  notice must appear in all copies of this file and its derivatives.
11 *
12 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
13 *  EISCAT Scientific Association. M.Savitski
14 *
15 *  This material is a part of the MVME162 Board Support Package
16 *  for the RTEMS executive. Its licensing policies are those of the
17 *  RTEMS above.
18 *
19 *  $Id$
20 */
21
22#define M162_INIT
23
24#include <rtems.h>
25#include "console.h"
26#include "bsp.h"
27#include "ringbuf.h"
28
29Ring_buffer_t  Buffer[2];
30
31/*
32 *  Interrupt handler for receiver interrupts
33 */
34
35rtems_isr C_Receive_ISR(rtems_vector_number vector)
36{
37  register int    ipend, port;
38
39  ZWRITE0(1, 0x38);     /* reset highest IUS */
40
41  ipend = ZREAD(1, 3);  /* read int pending from A side */
42
43  if      (ipend == 0x04) port = 0;   /* channel B intr pending */
44  else if (ipend == 0x20) port = 1;   /* channel A intr pending */
45  else return;
46   
47  Ring_buffer_Add_character(&Buffer[port], ZREADD(port));
48 
49  if (ZREAD(port, 1) & 0x70) {    /* check error stat */
50    ZWRITE0(port, 0x30);          /* reset error */
51  }
52}
53
54rtems_device_driver console_initialize(
55  rtems_device_major_number  major,
56  rtems_device_minor_number  minor,
57  void                      *arg,
58  rtems_id                   self,
59  rtems_unsigned32          *status
60)
61{
62  int     i;
63 
64  /*
65   * Initialise receiver interrupts on both ports
66   */
67
68  for (i = 0; i <= 1; i++) {
69    Ring_buffer_Initialize( &Buffer[i] );
70    ZWRITE(i, 2, SCC_VECTOR);
71    ZWRITE(i, 10, 0);
72    ZWRITE(i, 1, 0x10);     /* int on all Rx chars or special condition */
73    ZWRITE(i, 9, 8);        /* master interrupt enable */
74  }
75   
76  set_vector(C_Receive_ISR, SCC_VECTOR, 1); /* install ISR for ports A and B */
77
78  mcchip->vector_base = 0;
79  mcchip->gen_control = 2;        /* MIEN */
80  mcchip->SCC_int_ctl = 0x13;     /* SCC IEN, IPL3 */
81
82  *status = RTEMS_SUCCESSFUL;
83}
84
85/*
86 *   Non-blocking char input
87 */
88
89rtems_boolean char_ready(int port, char *ch)
90{
91  if ( Ring_buffer_Is_empty( &Buffer[port] ) )
92    return FALSE;
93
94  Ring_buffer_Remove_character( &Buffer[port], *ch );
95 
96  return TRUE;
97}
98
99/*
100 *   Block on char input
101 */
102
103char char_wait(int port)
104{
105  unsigned char tmp_char;
106 
107  while ( !char_ready(port, &tmp_char) );
108  return tmp_char;
109}
110
111/* 
112 *   This routine transmits a character out the SCC.  It no longer supports
113 *   XON/XOFF flow control.
114 */
115
116void char_put(int port, char ch)
117{
118  while (1) {
119    if (ZREAD0(port) & TX_BUFFER_EMPTY) break;
120  }
121  ZWRITED(port, ch);
122}
123
124/*
125 *    Map port A (1) to stdin, stdout, and stderr.
126 *    Map everything else to port B (0).
127 */
128
129int __read(int fd, char *buf, int nbytes)
130{
131  int i, port;
132
133  if ( fd <= 2 ) port = 1;
134  else           port = 0;
135
136  for (i = 0; i < nbytes; i++) {
137    *(buf + i) = char_wait(port);
138    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
139      (*(buf + i++)) = '\n';
140      (*(buf + i)) = 0;
141      break;
142    }
143  }
144  return (i);
145}
146
147/*
148 *  Map port A (1) to stdin, stdout, and stderr.
149 *  Map everything else to port B (0).
150 */
151
152int __write(int fd, char *buf, int nbytes)
153{
154  int i, port;
155 
156  if ( fd <= 2 ) port = 1;
157  else           port = 0;
158 
159  for (i = 0; i < nbytes; i++) {
160    if (*(buf + i) == '\n') {
161      char_put (port, '\r');
162    }
163    char_put (port, *(buf + i));
164  }
165  return (nbytes);
166}
Note: See TracBrowser for help on using the repository browser.