source: rtems/c/src/lib/libbsp/m68k/gen68302/console/console.c @ 9e86dd7d

4.104.114.84.95
Last change on this file since 9e86dd7d was 9e86dd7d, checked in by Joel Sherrill <joel.sherrill@…>, on 06/07/95 at 01:27:28

incorporated mc68302 support

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Initialize the MC68302 SCC2 for console IO board support 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 *  $Id$
13 */
14
15#define GEN68302_INIT
16
17#include <rtems.h>
18#include "console.h"
19#include <bsp.h>
20
21#include "m68302.h"
22
23/*  console_initialize
24 *
25 *  This routine initializes the console IO driver.
26 *
27 *  Input parameters: NONE
28 *
29 *  Output parameters:  NONE
30 *
31 *  Return values:
32 */
33
34rtems_device_driver console_initialize(
35  rtems_device_major_number  major,
36  rtems_device_minor_number  minor,
37  void                      *arg,
38  rtems_id                   self,
39  rtems_unsigned32          *status
40)
41{
42  volatile m302_dualPortRAM_t *p = &m302;
43
44  p->reg.pacnt |= 0x0003;               /* enable RXD2 and TXD2 signals */
45  /*
46   * TODO: Check assembly code.  I think gcc's volatile semantics force
47   * this to not use a CLR.
48   */
49  p->reg.simode = 0;                    /* NMSI mode */
50
51  p->reg.scc[1].scon = 0x00d8;          /* 9600 baud */
52  p->reg.scc[1].scm  = 0x01b1;
53
54  p->scc2.parm.rfcr = 0x50;             /* Rx buffers in supervisor data */
55  p->scc2.parm.tfcr = 0x50;             /* Tx buffers in supervisor data */
56  p->scc2.parm.mrblr = 0x0001;          /* Max Rx buffer length is 1 byte */
57
58  p->scc2.prot.uart.max_idl = 0x0000;   /* 0 = maximum timeout value */
59  p->scc2.prot.uart.brkcr = 0x0001;     /* send 1 break char on STOP TX cmd */
60  p->scc2.prot.uart.parec = 0x0000;     /* reset parity error counter */
61  p->scc2.prot.uart.frmec = 0x0000;     /* reset framing error counter */
62  p->scc2.prot.uart.nosec = 0x0000;     /* reset noise error counter */
63  p->scc2.prot.uart.brkec = 0x0000;     /* reset break condition counter */
64
65  p->scc2.prot.uart.character[0] = 0x0003; /* use <ctrl>c as control char */
66  p->scc2.prot.uart.character[1] = 0x8000; /* set end of cntrl char table */
67
68  p->scc2.bd.rx[0].status = 0xA000;     /* RxBD0 empty, wrap, no intr */
69  p->scc2.bd.rx[0].length = 0x0000;
70  p->scc2.bd.rx[0].buffer =
71      (rtems_unsigned8 *) &m302.scc2.bd.rx[1]; /* RxBD1 is Rx buffer */
72
73  p->reg.scc[1].dsr = 0x7000;           /* set full-length last stop bit */
74
75  p->scc2.bd.tx[0].status = 0x3000;     /* TxBD0 not ready, wrap, intr */
76  p->scc2.bd.tx[0].length = 0x0001;
77  p->scc2.bd.tx[0].buffer =
78      (rtems_unsigned8 *) &m302.scc2.bd.tx[1]; /* TxBD1 is Tx buffer */
79
80  p->reg.scc[1].scce = 0xFF;            /* clear all SCC event flags */
81  p->reg.scc[1].sccm = 0x03;            /* enable only Tx & Rx interrupts */
82  p->reg.scc[1].scm  = 0x01BD;
83
84  *status = RTEMS_SUCCESSFUL;
85}
86
87
88/*  is_character_ready
89 *
90 *  Check to see if a character is available on the MC68302's SCC2.  If so,
91 *  then return a TRUE (along with the character).  Otherwise return FALSE.
92 *
93 *  Input parameters:   pointer to location in which to return character
94 *
95 *  Output parameters:  character (if available)
96 *
97 *  Return values:      TRUE - character available
98 *                      FALSE - no character available
99 */
100
101rtems_boolean is_character_ready(
102  char *ch                              /* -> character  */
103)
104{
105#define RXS (m302.scc2.bd.rx[0].status)
106#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
107
108    for (;;) {
109        if (RXS & RBIT_HDLC_EMPTY_BIT)
110            return FALSE;
111
112        *ch = RXD;
113        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
114        if ( *ch >= ' ' &&  *ch <= '~' )
115            return TRUE;
116    }
117}
118
119
120/*  inbyte
121 *
122 *  Receive a character from the MC68302's SCC2.
123 *
124 *  Input parameters:   NONE
125 *
126 *  Output parameters:  NONE
127 *
128 *  Return values:      character read
129 */
130
131char inbyte( void )
132{
133    char ch;
134
135#define RXS (m302.scc2.bd.rx[0].status)
136#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
137
138    do {
139        while (RXS & RBIT_HDLC_EMPTY_BIT)
140            /* Wait until character received */ ;
141
142        ch = RXD;
143        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
144
145        if (ch == '\r' || ch == '\n')
146            break;
147    } while (ch < ' ' ||  ch > '~');
148
149    return ch;
150}
151
152
153/*  outbyte
154 *
155 *  Transmit a character out on the MC68302's SCC2.
156 *  It may support XON/XOFF flow control.
157 *
158 *  Input parameters:
159 *    ch  - character to be transmitted
160 *
161 *  Output parameters:  NONE
162 */
163
164void outbyte(
165  char ch
166)
167{
168#define TXS (m302.scc2.bd.tx[0].status)
169#define TXD (* ((volatile char *) m302.scc2.bd.tx[0].buffer))
170
171#define RXS (m302.scc2.bd.rx[0].status)
172#define RXD (* ((volatile char *) m302.scc2.bd.rx[0].buffer))
173
174    while (TXS & RBIT_HDLC_READY_BIT)
175        /* Wait until okay to transmit */ ;
176
177    /*
178     * Check for flow control requests and process.
179     */
180    while ( ! (RXS & RBIT_HDLC_EMPTY_BIT)) {
181        if (RXD == XOFF)
182            do {
183                RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
184                while (RXS & RBIT_HDLC_EMPTY_BIT)
185                    /* Wait until character received */ ;
186            } while (RXD != XON);
187        RXS = RBIT_HDLC_EMPTY_BIT | RBIT_HDLC_WRAP_BIT;
188    }
189
190    TXD = ch;
191    TXS = RBIT_HDLC_READY_BIT | RBIT_HDLC_WRAP_BIT;
192    if (ch == '\n')
193        outbyte('\r');
194}
195
196/*
197 * __read  -- read bytes from the serial port. Ignore fd, since
198 *            we only have stdin.
199 */
200
201int __read(
202  int fd,
203  char *buf,
204  int nbytes
205)
206{
207  int i = 0;
208
209  for (i = 0; i < nbytes; i++) {
210    *(buf + i) = inbyte();
211    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
212      (*(buf + i++)) = '\n';
213      (*(buf + i)) = 0;
214      break;
215    }
216  }
217  return (i);
218}
219
220/*
221 * __write -- write bytes to the serial port. Ignore fd, since
222 *            stdout and stderr are the same. Since we have no filesystem,
223 *            open will only return an error.
224 */
225
226int __write(
227  int fd,
228  char *buf,
229  int nbytes
230)
231{
232  int i;
233
234  for (i = 0; i < nbytes; i++) {
235    if (*(buf + i) == '\n') {
236      outbyte ('\r');
237    }
238    outbyte (*(buf + i));
239  }
240  return (nbytes);
241}
Note: See TracBrowser for help on using the repository browser.